Skip to content

Commit 8aabf2f

Browse files
Polishing.
Resolve collation from template expression & update issue references + Javadoc. Original Pull Request: #4131
1 parent ff9d338 commit 8aabf2f

File tree

5 files changed

+25
-17
lines changed

5 files changed

+25
-17
lines changed

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/CompoundIndex.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.lang.annotation.RetentionPolicy;
2323
import java.lang.annotation.Target;
2424

25+
import org.springframework.data.mongodb.core.mapping.Document;
2526
/**
2627
* Mark a class to use compound indexes. <br />
2728
* <p>
@@ -166,17 +167,19 @@
166167
String partialFilter() default "";
167168

168169
/**
169-
* The actual collation definition in JSON format or a {@link org.springframework.expression.spel.standard.SpelExpression
170-
* template expression} resolving to either a JSON String or a {@link org.bson.Document}. The keys of the JSON
171-
* document are configuration options for the collation (language-specific rules for string comparison).
172-
* <br><br>
173-
* TODO write code documentation & example!!!
174-
* <br>
170+
* The actual collation definition in JSON format or a
171+
* {@link org.springframework.expression.spel.standard.SpelExpression template expression} resolving to either a JSON
172+
* String or a {@link org.bson.Document}. The keys of the JSON document are configuration options for the collation
173+
* (language-specific rules for string comparison) to be applied on string properties being part of the index.
174+
* <p>
175+
* <strong>NOTE:</strong> Overrides {@link Document#collation()}.
176+
* <p>
177+
*
175178
*
176179
* @return empty String by default.
177180
* @see <a href=
178-
* "https://www.mongodb.com/docs/manual/reference/collation/">https://www.mongodb.com/docs/manual/reference/collation/</a>
179-
* @since 3.4
181+
* "https://www.mongodb.com/docs/manual/reference/collation/">https://www.mongodb.com/docs/manual/reference/collation/</a>
182+
* @since 4.0
180183
*/
181184
String collation() default "";
182185
}

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/Indexed.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.lang.annotation.RetentionPolicy;
2121
import java.lang.annotation.Target;
2222

23+
import org.springframework.data.mongodb.core.mapping.Document;
2324
/**
2425
* Mark a field to be indexed using MongoDB's indexing feature.
2526
*
@@ -176,12 +177,16 @@
176177
String partialFilter() default "";
177178

178179
/**
179-
* Apply collation configuration for field <br />
180+
* The actual collation definition in JSON format or a
181+
* {@link org.springframework.expression.spel.standard.SpelExpression template expression} resolving to either a JSON
182+
* String or a {@link org.bson.Document}. The keys of the JSON document are configuration options for the collation
183+
* (language-specific rules for string comparison) applied to the indexed based on the field value.
184+
* <p>
185+
* <strong>NOTE:</strong> Overrides {@link Document#collation()}.
180186
*
181187
* @return empty by default.
182-
* @see <a href=
183-
* "https://www.mongodb.com/docs/manual/reference/collation/">https://www.mongodb.com/docs/manual/reference/collation//</a>
184-
* @since 3.1
188+
* @see <a href="https://www.mongodb.com/docs/manual/reference/collation/">https://www.mongodb.com/docs/manual/reference/collation/</a>
189+
* @since 4.0
185190
*/
186191
String collation() default "";
187192
}

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/MongoPersistentEntityIndexResolver.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ protected IndexDefinitionHolder createCompoundIndexDefinition(String dotPath, St
455455
}
456456

457457
if (StringUtils.hasText(index.collation())) {
458-
indexDefinition.collation(Collation.parse(index.collation()));
458+
indexDefinition.collation(evaluateCollation(index.collation(), entity));
459459
}
460460

461461
return new IndexDefinitionHolder(dotPath, indexDefinition, collection);
@@ -578,7 +578,7 @@ protected IndexDefinitionHolder createIndexDefinition(String dotPath, String col
578578
}
579579

580580
if (StringUtils.hasText(index.collation())) {
581-
indexDefinition.collation(Collation.parse(index.collation()));
581+
indexDefinition.collation(evaluateCollation(index.collation(), persistentProperty.getOwner()));
582582
}
583583

584584
return new IndexDefinitionHolder(dotPath, indexDefinition, collection);

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/index/IndexInfoUnitTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public void readsWildcardIndexProjectionCorrectly() {
9393
.contains(new Document("fieldA", 0).append("fieldB.fieldC", 0));
9494
}
9595

96-
@Test // DATAMONGO-2133
96+
@Test // GH-3002
9797
public void collationParsedCorrectly() {
9898
assertThat(getIndexInfo(INDEX_WITH_COLLATION).getCollation())
9999
.contains(Document.parse("{ \"locale\": \"en_US\", \"strength\": 2 }"));

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/index/MongoPersistentEntityIndexResolverUnitTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,7 @@ public void singleIndexWithPartialFilter() {
700700
org.bson.Document.parse("{'value': {'$exists': true}}"));
701701
}
702702

703-
@Test // DATAMONGO-2133
703+
@Test // GH-3002
704704
public void compoundIndexWithCollation() {
705705

706706
List<IndexDefinitionHolder> indexDefinitions = prepareMappingContextAndResolveIndexForType(
@@ -1419,7 +1419,7 @@ public void shouldSkipMapStructuresUnlessAnnotatedWithWildcardIndex() {
14191419
assertThat(indexDefinitions).hasSize(1);
14201420
}
14211421

1422-
@Test // DATAMONGO-2133
1422+
@Test // GH-3002
14231423
public void indexedWithCollation() {
14241424

14251425
List<IndexDefinitionHolder> indexDefinitions = prepareMappingContextAndResolveIndexForType(

0 commit comments

Comments
 (0)