47
47
import org .springframework .data .mongodb .core .mapping .MongoPersistentEntity ;
48
48
import org .springframework .data .mongodb .core .mapping .MongoPersistentProperty ;
49
49
import org .springframework .data .mongodb .util .BsonUtils ;
50
+ import org .springframework .data .mongodb .util .DotPath ;
50
51
import org .springframework .data .spel .EvaluationContextProvider ;
51
52
import org .springframework .data .util .TypeInformation ;
52
53
import org .springframework .expression .EvaluationContext ;
@@ -161,16 +162,16 @@ private void potentiallyAddIndexForProperty(MongoPersistentEntity<?> root, Mongo
161
162
* @return List of {@link IndexDefinitionHolder} representing indexes for given type and its referenced property
162
163
* types. Will never be {@code null}.
163
164
*/
164
- private List <IndexDefinitionHolder > resolveIndexForClass (final TypeInformation <?> type , final String dotPath ,
165
- final Path path , final String collection , final CycleGuard guard ) {
165
+ private List <IndexDefinitionHolder > resolveIndexForClass ( TypeInformation <?> type , String dotPath ,
166
+ Path path , String collection , CycleGuard guard ) {
166
167
167
168
return resolveIndexForEntity (mappingContext .getRequiredPersistentEntity (type ), dotPath , path , collection , guard );
168
169
}
169
170
170
- private List <IndexDefinitionHolder > resolveIndexForEntity (MongoPersistentEntity <?> entity , final String dotPath ,
171
- final Path path , final String collection , final CycleGuard guard ) {
171
+ private List <IndexDefinitionHolder > resolveIndexForEntity (MongoPersistentEntity <?> entity , String dotPath ,
172
+ Path path , String collection , CycleGuard guard ) {
172
173
173
- final List <IndexDefinitionHolder > indexInformation = new ArrayList <>();
174
+ List <IndexDefinitionHolder > indexInformation = new ArrayList <>();
174
175
indexInformation .addAll (potentiallyCreateCompoundIndexDefinitions (dotPath , collection , entity ));
175
176
176
177
entity .doWithProperties ((PropertyHandler <MongoPersistentProperty >) property -> this
@@ -184,25 +185,25 @@ private List<IndexDefinitionHolder> resolveIndexForEntity(MongoPersistentEntity<
184
185
private void guardAndPotentiallyAddIndexForProperty (MongoPersistentProperty persistentProperty , String dotPath ,
185
186
Path path , String collection , List <IndexDefinitionHolder > indexes , CycleGuard guard ) {
186
187
187
- String propertyDotPath = dotPath ;
188
+ DotPath propertyDotPath = DotPath . from ( dotPath ) ;
188
189
189
190
if (!persistentProperty .isEmbedded ()) {
190
- propertyDotPath = ( StringUtils . hasText ( dotPath ) ? dotPath + "." : "" ) + persistentProperty .getFieldName ();
191
+ propertyDotPath = propertyDotPath . append ( persistentProperty .getFieldName () );
191
192
}
192
193
193
194
Path propertyPath = path .append (persistentProperty );
194
195
guard .protect (persistentProperty , propertyPath );
195
196
196
197
if (persistentProperty .isEntity ()) {
197
198
try {
198
- indexes .addAll (resolveIndexForEntity (mappingContext .getPersistentEntity (persistentProperty ), propertyDotPath ,
199
+ indexes .addAll (resolveIndexForEntity (mappingContext .getPersistentEntity (persistentProperty ), propertyDotPath . toString () ,
199
200
propertyPath , collection , guard ));
200
201
} catch (CyclicPropertyReferenceException e ) {
201
202
LOGGER .info (e .getMessage ());
202
203
}
203
204
}
204
205
205
- List <IndexDefinitionHolder > indexDefinitions = createIndexDefinitionHolderForProperty (propertyDotPath , collection ,
206
+ List <IndexDefinitionHolder > indexDefinitions = createIndexDefinitionHolderForProperty (propertyDotPath . toString () , collection ,
206
207
persistentProperty );
207
208
208
209
if (!indexDefinitions .isEmpty ()) {
@@ -270,7 +271,7 @@ private Collection<? extends IndexDefinitionHolder> potentiallyCreateTextIndexDe
270
271
}
271
272
272
273
try {
273
- appendTextIndexInformation ("" , Path .empty (), indexDefinitionBuilder , root ,
274
+ appendTextIndexInformation (DotPath . empty () , Path .empty (), indexDefinitionBuilder , root ,
274
275
new TextIndexIncludeOptions (IncludeStrategy .DEFAULT ), new CycleGuard ());
275
276
} catch (CyclicPropertyReferenceException e ) {
276
277
LOGGER .info (e .getMessage ());
@@ -291,9 +292,9 @@ private Collection<? extends IndexDefinitionHolder> potentiallyCreateTextIndexDe
291
292
292
293
}
293
294
294
- private void appendTextIndexInformation (final String dotPath , final Path path ,
295
- final TextIndexDefinitionBuilder indexDefinitionBuilder , final MongoPersistentEntity <?> entity ,
296
- final TextIndexIncludeOptions includeOptions , final CycleGuard guard ) {
295
+ private void appendTextIndexInformation (DotPath dotPath , Path path ,
296
+ TextIndexDefinitionBuilder indexDefinitionBuilder , MongoPersistentEntity <?> entity ,
297
+ TextIndexIncludeOptions includeOptions , CycleGuard guard ) {
297
298
298
299
entity .doWithProperties (new PropertyHandler <MongoPersistentProperty >() {
299
300
@@ -302,16 +303,16 @@ public void doWithPersistentProperty(MongoPersistentProperty persistentProperty)
302
303
303
304
guard .protect (persistentProperty , path );
304
305
305
- if (persistentProperty .isExplicitLanguageProperty () && ! StringUtils . hasText ( dotPath )) {
306
+ if (persistentProperty .isExplicitLanguageProperty () && dotPath . isEmpty ( )) {
306
307
indexDefinitionBuilder .withLanguageOverride (persistentProperty .getFieldName ());
307
308
}
308
309
309
310
TextIndexed indexed = persistentProperty .findAnnotation (TextIndexed .class );
310
311
311
312
if (includeOptions .isForce () || indexed != null || persistentProperty .isEntity ()) {
312
313
313
- String propertyDotPath = ( StringUtils . hasText ( dotPath ) ? dotPath + "." : "" )
314
- + persistentProperty .getFieldName ();
314
+ DotPath propertyDotPath = dotPath
315
+ . append ( persistentProperty .getFieldName () );
315
316
316
317
Path propertyPath = path .append (persistentProperty );
317
318
@@ -324,7 +325,7 @@ public void doWithPersistentProperty(MongoPersistentProperty persistentProperty)
324
325
TextIndexIncludeOptions optionsForNestedType = includeOptions ;
325
326
if (!IncludeStrategy .FORCE .equals (includeOptions .getStrategy ()) && indexed != null ) {
326
327
optionsForNestedType = new TextIndexIncludeOptions (IncludeStrategy .FORCE ,
327
- new TextIndexedFieldSpec (propertyDotPath , weight ));
328
+ new TextIndexedFieldSpec (propertyDotPath . toString () , weight ));
328
329
}
329
330
330
331
try {
@@ -337,7 +338,7 @@ public void doWithPersistentProperty(MongoPersistentProperty persistentProperty)
337
338
entity .getName ()), e );
338
339
}
339
340
} else if (includeOptions .isForce () || indexed != null ) {
340
- indexDefinitionBuilder .onField (propertyDotPath , weight );
341
+ indexDefinitionBuilder .onField (propertyDotPath . toString () , weight );
341
342
}
342
343
}
343
344
@@ -648,15 +649,15 @@ private void resolveAndAddIndexesForAssociation(Association<MongoPersistentPrope
648
649
649
650
MongoPersistentProperty property = association .getInverse ();
650
651
651
- String propertyDotPath = ( StringUtils . hasText (path ) ? path + "." : "" ) + property .getFieldName ();
652
+ DotPath propertyDotPath = DotPath . from (path ). append ( property .getFieldName () );
652
653
653
654
if (property .isAnnotationPresent (GeoSpatialIndexed .class ) || property .isAnnotationPresent (TextIndexed .class )) {
654
655
throw new MappingException (
655
656
String .format ("Cannot create geospatial-/text- index on DBRef in collection '%s' for path '%s'." , collection ,
656
657
propertyDotPath ));
657
658
}
658
659
659
- List <IndexDefinitionHolder > indexDefinitions = createIndexDefinitionHolderForProperty (propertyDotPath , collection ,
660
+ List <IndexDefinitionHolder > indexDefinitions = createIndexDefinitionHolderForProperty (propertyDotPath . toString () , collection ,
660
661
property );
661
662
662
663
if (!indexDefinitions .isEmpty ()) {
0 commit comments