Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HSEARCH-3523 Split the mapping integration in two phases, to be able …
…to pass the SessionFactory later to the ORM mapper
- Loading branch information
Showing
32 changed files
with
395 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
.../java/org/hibernate/search/engine/common/impl/SearchIntegrationPartialBuildStateImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* Hibernate Search, full-text search for your domain model | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later | ||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
*/ | ||
package org.hibernate.search.engine.common.impl; | ||
|
||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
import java.util.function.Function; | ||
|
||
import org.hibernate.search.engine.backend.index.spi.IndexManagerImplementor; | ||
import org.hibernate.search.engine.backend.spi.BackendImplementor; | ||
import org.hibernate.search.engine.common.spi.SearchIntegrationPartialBuildState; | ||
import org.hibernate.search.engine.common.spi.SearchIntegration; | ||
import org.hibernate.search.engine.environment.bean.spi.BeanResolver; | ||
import org.hibernate.search.engine.mapper.mapping.spi.MappingImplementor; | ||
import org.hibernate.search.engine.mapper.mapping.spi.MappingKey; | ||
import org.hibernate.search.engine.mapper.mapping.spi.MappingPartialBuildState; | ||
import org.hibernate.search.util.common.AssertionFailure; | ||
import org.hibernate.search.util.common.impl.Closer; | ||
|
||
class SearchIntegrationPartialBuildStateImpl implements SearchIntegrationPartialBuildState { | ||
|
||
private final BeanResolver beanResolver; | ||
|
||
private final Map<MappingKey<?, ?>, MappingPartialBuildState> partiallyBuiltMappings; | ||
private final Map<MappingKey<?, ?>, MappingImplementor<?>> fullyBuiltMappings = new LinkedHashMap<>(); | ||
private final Map<String, BackendImplementor<?>> backends; | ||
private final Map<String, IndexManagerImplementor<?>> indexManagers; | ||
|
||
SearchIntegrationPartialBuildStateImpl( | ||
BeanResolver beanResolver, | ||
Map<MappingKey<?, ?>, MappingPartialBuildState> partiallyBuiltMappings, | ||
Map<String, BackendImplementor<?>> backends, | ||
Map<String, IndexManagerImplementor<?>> indexManagers) { | ||
this.beanResolver = beanResolver; | ||
this.partiallyBuiltMappings = partiallyBuiltMappings; | ||
this.backends = backends; | ||
this.indexManagers = indexManagers; | ||
} | ||
|
||
@Override | ||
public void closeOnFailure() { | ||
try ( Closer<RuntimeException> closer = new Closer<>() ) { | ||
closer.pushAll( MappingPartialBuildState::closeOnFailure, partiallyBuiltMappings.values() ); | ||
closer.pushAll( MappingImplementor::close, fullyBuiltMappings.values() ); | ||
closer.pushAll( IndexManagerImplementor::close, indexManagers.values() ); | ||
closer.pushAll( BackendImplementor::close, backends.values() ); | ||
closer.pushAll( BeanResolver::close, beanResolver ); | ||
} | ||
} | ||
|
||
@Override | ||
public <PBM, M> M finalizeMapping(MappingKey<PBM, M> mappingKey, | ||
Function<PBM, MappingImplementor<M>> director) { | ||
// We know this cast will work because of how | ||
@SuppressWarnings("unchecked") | ||
PBM partiallyBuiltMapping = (PBM) partiallyBuiltMappings.get( mappingKey ); | ||
if ( partiallyBuiltMapping == null ) { | ||
throw new AssertionFailure( | ||
"Some partially built mapping could not be found during bootstrap; there is probably a bug in Hibernate Search." | ||
+ " Key: " + mappingKey | ||
); | ||
} | ||
|
||
MappingImplementor<M> mapping = director.apply( partiallyBuiltMapping ); | ||
fullyBuiltMappings.put( mappingKey, mapping ); | ||
partiallyBuiltMappings.remove( mappingKey ); | ||
|
||
return mapping.toAPI(); | ||
} | ||
|
||
@Override | ||
public SearchIntegration finalizeIntegration() { | ||
if ( !partiallyBuiltMappings.isEmpty() ) { | ||
throw new AssertionFailure( | ||
"Some mappings were not fully built; there is probably a bug in Hibernate Search." | ||
+ " Partially built mappings: " + partiallyBuiltMappings | ||
); | ||
} | ||
|
||
return new SearchIntegrationImpl( | ||
beanResolver, | ||
fullyBuiltMappings, | ||
backends, | ||
indexManagers | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
.../main/java/org/hibernate/search/engine/common/spi/SearchIntegrationPartialBuildState.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Hibernate Search, full-text search for your domain model | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later | ||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
*/ | ||
package org.hibernate.search.engine.common.spi; | ||
|
||
import java.util.function.Function; | ||
|
||
import org.hibernate.search.engine.mapper.mapping.spi.MappingImplementor; | ||
import org.hibernate.search.engine.mapper.mapping.spi.MappingKey; | ||
|
||
public interface SearchIntegrationPartialBuildState { | ||
|
||
/** | ||
* Close the resources held by this object (backends, index managers, ...). | ||
* <p> | ||
* To be called in the event of a failure that will prevent {@link #finalizeIntegration()} to be called. | ||
*/ | ||
void closeOnFailure(); | ||
|
||
/** | ||
* Finalize the building of a mapping. | ||
* @param mappingKey The mapping key allowing to retrieve the pre-built mapping. | ||
* @param director The object responsible for turning a pre-built mapping into a fully-built mapping (it may hold some additional context). | ||
* @param <PBM> The type of the partially-built mapping. | ||
* @param <M> The type of the fully-built mapping. | ||
* @return The fully-built mapping. | ||
*/ | ||
<PBM, M> M finalizeMapping(MappingKey<PBM, M> mappingKey, Function<PBM, MappingImplementor<M>> director); | ||
|
||
/** | ||
* Finalize the building of the integration. | ||
* @return The fully-built integration. | ||
*/ | ||
SearchIntegration finalizeIntegration(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.