Skip to content

Commit a955a99

Browse files
committed
HSEARCH-5018 Add same properties to the standalone mapper
1 parent 8e7ada6 commit a955a99

File tree

2 files changed

+79
-10
lines changed

2 files changed

+79
-10
lines changed

mapper/pojo-standalone/src/main/java/org/hibernate/search/mapper/pojo/standalone/cfg/StandalonePojoMapperSettings.java

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
package org.hibernate.search.mapper.pojo.standalone.cfg;
88

99
import org.hibernate.search.engine.environment.bean.BeanReference;
10+
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.ProjectionConstructor;
11+
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.SearchEntity;
12+
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.processing.RootMapping;
1013
import org.hibernate.search.mapper.pojo.standalone.mapping.SearchMapping;
1114
import org.hibernate.search.mapper.pojo.standalone.mapping.StandalonePojoMappingConfigurer;
1215
import org.hibernate.search.mapper.pojo.standalone.schema.management.SchemaManagementStrategyName;
@@ -36,6 +39,43 @@ private StandalonePojoMapperSettings() {
3639
*/
3740
public static final String SCHEMA_MANAGEMENT_STRATEGY = PREFIX + Radicals.SCHEMA_MANAGEMENT_STRATEGY;
3841

42+
/**
43+
* Whether Hibernate Search should automatically build Jandex indexes for types registered for annotation processing
44+
* (entities in particular),
45+
* to ensure that all "root mapping" annotations in those JARs (e.g. {@link org.hibernate.search.mapper.pojo.mapping.definition.annotation.ProjectionConstructor})
46+
* are taken into account.
47+
* <p>
48+
* Expects a Boolean value such as {@code true} or {@code false},
49+
* or a string that can be parsed into a Boolean value.
50+
* <p>
51+
* Defaults to {@link Defaults#MAPPING_BUILD_MISSING_DISCOVERED_JANDEX_INDEXES}.
52+
*
53+
* @see org.hibernate.search.mapper.pojo.mapping.definition.annotation.AnnotationMappingConfigurationContext#buildMissingDiscoveredJandexIndexes(boolean)
54+
*/
55+
public static final String MAPPING_BUILD_MISSING_DISCOVERED_JANDEX_INDEXES =
56+
PREFIX + Radicals.MAPPING_BUILD_MISSING_DISCOVERED_JANDEX_INDEXES;
57+
58+
/**
59+
* Whether Hibernate Search should automatically discover annotated types
60+
* present in the Jandex index that are also annotated
61+
* with {@link RootMapping root mapping annotations}.
62+
* <p>
63+
* When enabled, if an annotation meta-annotated with {@link RootMapping}
64+
* is found in the Jandex index,
65+
* and a type annotated with that annotation (e.g. {@link SearchEntity} or {@link ProjectionConstructor}) is found in the Jandex index,
66+
* then that type will automatically be scanned for mapping annotations,
67+
* even if the type wasn't explicitly added.
68+
* <p>
69+
* Expects a Boolean value such as {@code true} or {@code false},
70+
* or a string that can be parsed into a Boolean value.
71+
* <p>
72+
* Defaults to {@link Defaults#MAPPING_DISCOVER_ANNOTATED_TYPES_FROM_ROOT_MAPPING_ANNOTATIONS}.
73+
*
74+
* @see org.hibernate.search.mapper.pojo.mapping.definition.annotation.AnnotationMappingConfigurationContext#discoverAnnotatedTypesFromRootMappingAnnotations(boolean)
75+
*/
76+
public static final String MAPPING_DISCOVER_ANNOTATED_TYPES_FROM_ROOT_MAPPING_ANNOTATIONS =
77+
PREFIX + Radicals.MAPPING_DISCOVER_ANNOTATED_TYPES_FROM_ROOT_MAPPING_ANNOTATIONS;
78+
3979
/**
4080
* A configurer for the Hibernate Search mapping.
4181
* <p>
@@ -95,10 +135,15 @@ private Radicals() {
95135
}
96136

97137
public static final String SCHEMA_MANAGEMENT_STRATEGY = "schema_management.strategy";
98-
public static final String MAPPING_CONFIGURER = "mapping.configurer";
99-
public static final String MULTI_TENANCY_ENABLED = "mapping.multi_tenancy.enabled";
138+
public static final String MAPPING_PREFIX = "mapping.";
139+
public static final String MAPPING_BUILD_MISSING_DISCOVERED_JANDEX_INDEXES =
140+
MAPPING_PREFIX + "build_missing_discovered_jandex_indexes";
141+
public static final String MAPPING_DISCOVER_ANNOTATED_TYPES_FROM_ROOT_MAPPING_ANNOTATIONS =
142+
MAPPING_PREFIX + "discover_annotated_types_from_root_mapping_annotations";
143+
public static final String MAPPING_CONFIGURER = MAPPING_PREFIX + "configurer";
144+
public static final String MULTI_TENANCY_ENABLED = MAPPING_PREFIX + "multi_tenancy.enabled";
100145
public static final String MULTI_TENANCY_TENANT_IDENTIFIER_CONVERTER =
101-
"mapping.multi_tenancy.tenant_identifier_converter";
146+
MAPPING_PREFIX + "multi_tenancy.tenant_identifier_converter";
102147
public static final String INDEXING_PLAN_SYNCHRONIZATION_PREFIX = "indexing.plan.synchronization.";
103148
public static final String INDEXING_PLAN_SYNCHRONIZATION_STRATEGY = INDEXING_PLAN_SYNCHRONIZATION_PREFIX + "strategy";
104149

@@ -114,6 +159,8 @@ private Defaults() {
114159

115160
public static final SchemaManagementStrategyName SCHEMA_MANAGEMENT_STRATEGY =
116161
SchemaManagementStrategyName.CREATE_OR_VALIDATE;
162+
public static final boolean MAPPING_BUILD_MISSING_DISCOVERED_JANDEX_INDEXES = true;
163+
public static final boolean MAPPING_DISCOVER_ANNOTATED_TYPES_FROM_ROOT_MAPPING_ANNOTATIONS = true;
117164
public static final boolean MULTI_TENANCY_ENABLED = false;
118165

119166
public static final BeanReference<IndexingPlanSynchronizationStrategy> INDEXING_PLAN_SYNCHRONIZATION_STRATEGY =

mapper/pojo-standalone/src/main/java/org/hibernate/search/mapper/pojo/standalone/mapping/impl/StandalonePojoMappingInitiator.java

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import java.util.List;
1010

11+
import org.hibernate.search.engine.cfg.ConfigurationPropertySource;
1112
import org.hibernate.search.engine.cfg.spi.ConfigurationProperty;
1213
import org.hibernate.search.engine.cfg.spi.OptionalConfigurationProperty;
1314
import org.hibernate.search.engine.environment.bean.BeanHolder;
@@ -27,6 +28,21 @@
2728
public class StandalonePojoMappingInitiator extends AbstractPojoMappingInitiator<StandalonePojoMappingPartialBuildState>
2829
implements StandalonePojoMappingConfigurationContext {
2930

31+
private static final ConfigurationProperty<Boolean> MAPPING_BUILD_MISSING_DISCOVERED_JANDEX_INDEXES =
32+
ConfigurationProperty
33+
.forKey( StandalonePojoMapperSettings.Radicals.MAPPING_BUILD_MISSING_DISCOVERED_JANDEX_INDEXES )
34+
.asBoolean()
35+
.withDefault( StandalonePojoMapperSettings.Defaults.MAPPING_BUILD_MISSING_DISCOVERED_JANDEX_INDEXES )
36+
.build();
37+
38+
private static final ConfigurationProperty<Boolean> MAPPING_DISCOVER_ANNOTATED_TYPES_FROM_ROOT_MAPPING_ANNOTATIONS =
39+
ConfigurationProperty.forKey(
40+
StandalonePojoMapperSettings.Radicals.MAPPING_DISCOVER_ANNOTATED_TYPES_FROM_ROOT_MAPPING_ANNOTATIONS )
41+
.asBoolean()
42+
.withDefault(
43+
StandalonePojoMapperSettings.Defaults.MAPPING_DISCOVER_ANNOTATED_TYPES_FROM_ROOT_MAPPING_ANNOTATIONS )
44+
.build();
45+
3046
private static final OptionalConfigurationProperty<
3147
List<BeanReference<? extends StandalonePojoMappingConfigurer>>> MAPPING_CONFIGURER =
3248
ConfigurationProperty.forKey( StandalonePojoMapperSettings.Radicals.MAPPING_CONFIGURER )
@@ -42,24 +58,30 @@ public class StandalonePojoMappingInitiator extends AbstractPojoMappingInitiator
4258

4359
public StandalonePojoMappingInitiator(StandalonePojoBootstrapIntrospector introspector) {
4460
super( introspector, StandalonePojoMapperHints.INSTANCE );
45-
// Enable annotated type discovery by default
46-
annotationMapping()
47-
.discoverAnnotatedTypesFromRootMappingAnnotations( true )
48-
.discoverJandexIndexesFromAddedTypes( true )
49-
.discoverAnnotationsFromReferencedTypes( true );
5061
}
5162

5263
@Override
5364
public void configure(MappingBuildContext buildContext,
5465
MappingConfigurationCollector<PojoTypeMetadataContributor> configurationCollector) {
66+
ConfigurationPropertySource propertySource = buildContext.configurationPropertySource();
5567
this.tenancyMode(
56-
MULTI_TENANCY_ENABLED.get( buildContext.configurationPropertySource() )
68+
MULTI_TENANCY_ENABLED.get( propertySource )
5769
? TenancyMode.MULTI_TENANCY
5870
: TenancyMode.SINGLE_TENANCY
5971
);
72+
73+
// Enable annotated type discovery by default
74+
annotationMapping()
75+
.discoverAnnotatedTypesFromRootMappingAnnotations(
76+
MAPPING_DISCOVER_ANNOTATED_TYPES_FROM_ROOT_MAPPING_ANNOTATIONS.get( propertySource ) )
77+
.discoverJandexIndexesFromAddedTypes( true )
78+
.buildMissingDiscoveredJandexIndexes(
79+
MAPPING_BUILD_MISSING_DISCOVERED_JANDEX_INDEXES.get( propertySource ) )
80+
.discoverAnnotationsFromReferencedTypes( true );
81+
6082
// Apply the user-provided mapping configurer if necessary.
6183
// Has to happen before building entityTypeMetadataProvider as configurers can add more entities.
62-
MAPPING_CONFIGURER.getAndMap( buildContext.configurationPropertySource(), buildContext.beanResolver()::resolve )
84+
MAPPING_CONFIGURER.getAndMap( propertySource, buildContext.beanResolver()::resolve )
6385
.ifPresent( holder -> {
6486
try ( BeanHolder<List<StandalonePojoMappingConfigurer>> configurerHolder = holder ) {
6587
for ( StandalonePojoMappingConfigurer configurer : configurerHolder.get() ) {

0 commit comments

Comments
 (0)