Search in sources :

Example 11 with ProgrammaticMappingConfigurationContext

use of org.hibernate.search.mapper.pojo.mapping.definition.programmatic.ProgrammaticMappingConfigurationContext in project hibernate-search by hibernate.

the class CleanupIT method startup.

private void startup(Consumer<ProgrammaticMappingConfigurationContext> additionalMappingContributor) {
    this.mapping = setupHelper.start().withConfiguration(builder -> {
        builder.addEntityType(IndexedEntity.class);
        builder.addEntityType(OtherIndexedEntity.class);
        ContainerExtractorConfigurationContext containerExtractorDefinition = builder.containerExtractors();
        containerExtractorDefinition.define(StartupStubContainerExtractor.NAME, StartupStubContainerExtractor.class, /*
									 * Increment static counters upon retrieval of the extractor
									 * and closing of its bean holder,
									 * so that we can check the bean holders are properly closed.
									 */
        ignored -> StartupStubContainerExtractor.create(CONTAINER_VALUE_EXTRACTOR_COUNTER_KEYS));
        containerExtractorDefinition.define(FailingContainerExtractor.NAME, FailingContainerExtractor.class);
        ProgrammaticMappingConfigurationContext mappingDefinition = builder.programmaticMapping();
        TypeMappingStep indexedEntityMapping = mappingDefinition.type(IndexedEntity.class);
        indexedEntityMapping.indexed().index(IndexedEntity.INDEX).routingBinder(StartupStubBridge.binder(ROUTING_BRIDGE_COUNTER_KEYS));
        indexedEntityMapping.binder(StartupStubBridge.binder(TYPE_BRIDGE_COUNTER_KEYS));
        indexedEntityMapping.property("id").documentId().identifierBinder(StartupStubBridge.binder(Integer.class, IDENTIFIER_BRIDGE_COUNTER_KEYS));
        indexedEntityMapping.property("text").genericField().valueBinder(StartupStubBridge.binder(Object.class, VALUE_BRIDGE_COUNTER_KEYS)).extractor(StartupStubContainerExtractor.NAME);
        indexedEntityMapping.property("embedded").associationInverseSide(PojoModelPath.builder().property("embedding").value(StartupStubContainerExtractor.NAME).toValuePath()).binder(StartupStubBridge.binder(PROPERTY_BRIDGE_COUNTER_KEYS)).indexedEmbedded().includePaths("text");
        indexedEntityMapping.property("otherEmbedded").associationInverseSide(PojoModelPath.builder().property("otherEmbedding").value(StartupStubContainerExtractor.NAME).toValuePath());
        additionalMappingContributor.accept(mappingDefinition);
    }).setup();
}
Also used : TypeMappingStep(org.hibernate.search.mapper.pojo.mapping.definition.programmatic.TypeMappingStep) ContainerExtractorConfigurationContext(org.hibernate.search.mapper.pojo.extractor.ContainerExtractorConfigurationContext) ProgrammaticMappingConfigurationContext(org.hibernate.search.mapper.pojo.mapping.definition.programmatic.ProgrammaticMappingConfigurationContext)

Aggregations

ProgrammaticMappingConfigurationContext (org.hibernate.search.mapper.pojo.mapping.definition.programmatic.ProgrammaticMappingConfigurationContext)11 TypeMappingStep (org.hibernate.search.mapper.pojo.mapping.definition.programmatic.TypeMappingStep)8 Before (org.junit.Before)5 Test (org.junit.Test)5 MethodHandles (java.lang.invoke.MethodHandles)4 JavaBeanMappingSetupHelper (org.hibernate.search.integrationtest.mapper.pojo.testsupport.util.rule.JavaBeanMappingSetupHelper)4 SearchMapping (org.hibernate.search.mapper.javabean.mapping.SearchMapping)4 SearchSession (org.hibernate.search.mapper.javabean.session.SearchSession)4 BackendMock (org.hibernate.search.util.impl.integrationtest.common.rule.BackendMock)4 Rule (org.junit.Rule)4 ArrayList (java.util.ArrayList)3 Arrays (java.util.Arrays)3 LinkedHashMap (java.util.LinkedHashMap)3 List (java.util.List)3 Map (java.util.Map)3 PojoModelPath (org.hibernate.search.mapper.pojo.model.path.PojoModelPath)3 SearchException (org.hibernate.search.util.common.SearchException)3 Consumer (java.util.function.Consumer)2 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)2 SessionFactory (org.hibernate.SessionFactory)2