4747import org .springframework .data .mongodb .core .mapping .MongoPersistentEntity ;
4848import org .springframework .data .mongodb .core .mapping .MongoPersistentProperty ;
4949import org .springframework .data .mongodb .util .BsonUtils ;
50+ import org .springframework .data .mongodb .util .DotPath ;
5051import org .springframework .data .spel .EvaluationContextProvider ;
5152import org .springframework .data .util .TypeInformation ;
5253import org .springframework .expression .EvaluationContext ;
@@ -161,16 +162,16 @@ private void potentiallyAddIndexForProperty(MongoPersistentEntity<?> root, Mongo
161162 * @return List of {@link IndexDefinitionHolder} representing indexes for given type and its referenced property
162163 * types. Will never be {@code null}.
163164 */
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 ) {
166167
167168 return resolveIndexForEntity (mappingContext .getRequiredPersistentEntity (type ), dotPath , path , collection , guard );
168169 }
169170
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 ) {
172173
173- final List <IndexDefinitionHolder > indexInformation = new ArrayList <>();
174+ List <IndexDefinitionHolder > indexInformation = new ArrayList <>();
174175 indexInformation .addAll (potentiallyCreateCompoundIndexDefinitions (dotPath , collection , entity ));
175176
176177 entity .doWithProperties ((PropertyHandler <MongoPersistentProperty >) property -> this
@@ -184,25 +185,25 @@ private List<IndexDefinitionHolder> resolveIndexForEntity(MongoPersistentEntity<
184185 private void guardAndPotentiallyAddIndexForProperty (MongoPersistentProperty persistentProperty , String dotPath ,
185186 Path path , String collection , List <IndexDefinitionHolder > indexes , CycleGuard guard ) {
186187
187- String propertyDotPath = dotPath ;
188+ DotPath propertyDotPath = DotPath . from ( dotPath ) ;
188189
189190 if (!persistentProperty .isEmbedded ()) {
190- propertyDotPath = ( StringUtils . hasText ( dotPath ) ? dotPath + "." : "" ) + persistentProperty .getFieldName ();
191+ propertyDotPath = propertyDotPath . append ( persistentProperty .getFieldName () );
191192 }
192193
193194 Path propertyPath = path .append (persistentProperty );
194195 guard .protect (persistentProperty , propertyPath );
195196
196197 if (persistentProperty .isEntity ()) {
197198 try {
198- indexes .addAll (resolveIndexForEntity (mappingContext .getPersistentEntity (persistentProperty ), propertyDotPath ,
199+ indexes .addAll (resolveIndexForEntity (mappingContext .getPersistentEntity (persistentProperty ), propertyDotPath . toString () ,
199200 propertyPath , collection , guard ));
200201 } catch (CyclicPropertyReferenceException e ) {
201202 LOGGER .info (e .getMessage ());
202203 }
203204 }
204205
205- List <IndexDefinitionHolder > indexDefinitions = createIndexDefinitionHolderForProperty (propertyDotPath , collection ,
206+ List <IndexDefinitionHolder > indexDefinitions = createIndexDefinitionHolderForProperty (propertyDotPath . toString () , collection ,
206207 persistentProperty );
207208
208209 if (!indexDefinitions .isEmpty ()) {
@@ -270,7 +271,7 @@ private Collection<? extends IndexDefinitionHolder> potentiallyCreateTextIndexDe
270271 }
271272
272273 try {
273- appendTextIndexInformation ("" , Path .empty (), indexDefinitionBuilder , root ,
274+ appendTextIndexInformation (DotPath . empty () , Path .empty (), indexDefinitionBuilder , root ,
274275 new TextIndexIncludeOptions (IncludeStrategy .DEFAULT ), new CycleGuard ());
275276 } catch (CyclicPropertyReferenceException e ) {
276277 LOGGER .info (e .getMessage ());
@@ -291,9 +292,9 @@ private Collection<? extends IndexDefinitionHolder> potentiallyCreateTextIndexDe
291292
292293 }
293294
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 ) {
297298
298299 entity .doWithProperties (new PropertyHandler <MongoPersistentProperty >() {
299300
@@ -302,16 +303,16 @@ public void doWithPersistentProperty(MongoPersistentProperty persistentProperty)
302303
303304 guard .protect (persistentProperty , path );
304305
305- if (persistentProperty .isExplicitLanguageProperty () && ! StringUtils . hasText ( dotPath )) {
306+ if (persistentProperty .isExplicitLanguageProperty () && dotPath . isEmpty ( )) {
306307 indexDefinitionBuilder .withLanguageOverride (persistentProperty .getFieldName ());
307308 }
308309
309310 TextIndexed indexed = persistentProperty .findAnnotation (TextIndexed .class );
310311
311312 if (includeOptions .isForce () || indexed != null || persistentProperty .isEntity ()) {
312313
313- String propertyDotPath = ( StringUtils . hasText ( dotPath ) ? dotPath + "." : "" )
314- + persistentProperty .getFieldName ();
314+ DotPath propertyDotPath = dotPath
315+ . append ( persistentProperty .getFieldName () );
315316
316317 Path propertyPath = path .append (persistentProperty );
317318
@@ -324,7 +325,7 @@ public void doWithPersistentProperty(MongoPersistentProperty persistentProperty)
324325 TextIndexIncludeOptions optionsForNestedType = includeOptions ;
325326 if (!IncludeStrategy .FORCE .equals (includeOptions .getStrategy ()) && indexed != null ) {
326327 optionsForNestedType = new TextIndexIncludeOptions (IncludeStrategy .FORCE ,
327- new TextIndexedFieldSpec (propertyDotPath , weight ));
328+ new TextIndexedFieldSpec (propertyDotPath . toString () , weight ));
328329 }
329330
330331 try {
@@ -337,7 +338,7 @@ public void doWithPersistentProperty(MongoPersistentProperty persistentProperty)
337338 entity .getName ()), e );
338339 }
339340 } else if (includeOptions .isForce () || indexed != null ) {
340- indexDefinitionBuilder .onField (propertyDotPath , weight );
341+ indexDefinitionBuilder .onField (propertyDotPath . toString () , weight );
341342 }
342343 }
343344
@@ -648,15 +649,15 @@ private void resolveAndAddIndexesForAssociation(Association<MongoPersistentPrope
648649
649650 MongoPersistentProperty property = association .getInverse ();
650651
651- String propertyDotPath = ( StringUtils . hasText (path ) ? path + "." : "" ) + property .getFieldName ();
652+ DotPath propertyDotPath = DotPath . from (path ). append ( property .getFieldName () );
652653
653654 if (property .isAnnotationPresent (GeoSpatialIndexed .class ) || property .isAnnotationPresent (TextIndexed .class )) {
654655 throw new MappingException (
655656 String .format ("Cannot create geospatial-/text- index on DBRef in collection '%s' for path '%s'." , collection ,
656657 propertyDotPath ));
657658 }
658659
659- List <IndexDefinitionHolder > indexDefinitions = createIndexDefinitionHolderForProperty (propertyDotPath , collection ,
660+ List <IndexDefinitionHolder > indexDefinitions = createIndexDefinitionHolderForProperty (propertyDotPath . toString () , collection ,
660661 property );
661662
662663 if (!indexDefinitions .isEmpty ()) {
0 commit comments