Rename ICULocale to CollationLocale. Introduce interface for ComparisonLevel construction and let ICUComparisonLevel types implement that interface. Make value types immutable where possible. Provide static instances for default comparison level instances.
Replace collation conversion IndexConverters with Collation.from(…).toMongoCollation() converter. Introduce missing generic types. Replace Optional.get() with Optional.map(…).orElse(…).
Update reference documentation.
Original pull request: #459.
@ -722,7 +712,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
@@ -722,7 +712,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
@ -885,7 +875,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
@@ -885,7 +875,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
@ -972,7 +962,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
@@ -972,7 +962,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
Assert.hasText(collectionName,"Collection name must not be null or empty!");
@ -1225,18 +1215,19 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
@@ -1225,18 +1215,19 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
@ -1458,7 +1449,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
@@ -1458,7 +1449,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
"Both Query and MapReduceOptions define the collation. Please provide the collation only via one of the two.");
"Both Query and MapReduceOptions define a collation. Please provide the collation only via one of the two.");
});
if(mapReduceOptions.getCollation().isPresent()){
@ -1482,9 +1473,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
@@ -1482,9 +1473,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
@ -2297,7 +2286,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
@@ -2297,7 +2286,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
if(LOGGER.isDebugEnabled()){
LOGGER.debug("findOne using query: {} fields: {} in db.collection: {}",serializeToJsonSafely(query),
@ -2336,11 +2325,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
@@ -2336,11 +2325,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
@ -2399,7 +2384,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
@@ -2399,7 +2384,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
opts.upsert(true);
}
opts.projection(fields);
if(options.returnNew){
if(options.isReturnNew()){
opts.returnDocument(ReturnDocument.AFTER);
}
@ -2506,16 +2491,16 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
@@ -2506,16 +2491,16 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
@ -573,11 +574,10 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
@@ -573,11 +574,10 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
@ -616,8 +616,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
@@ -616,8 +616,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
@ -712,7 +711,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
@@ -712,7 +711,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
@ -1091,34 +1090,35 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
@@ -1091,34 +1090,35 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
@ -1317,7 +1317,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
@@ -1317,7 +1317,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
thrownewMappingException("No id property found for object of type "+objectType);
@ -1907,8 +1907,9 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
@@ -1907,8 +1907,9 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
@ -2011,21 +2012,19 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
@@ -2011,21 +2012,19 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
@ -2129,10 +2128,8 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
@@ -2129,10 +2128,8 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
@ -2154,9 +2151,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
@@ -2154,9 +2151,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
@ -2293,11 +2288,10 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
@@ -2293,11 +2288,10 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
The flags for `$caseSensitive` and `$diacriticSensitive` can be set via the according methods on `TextCriteria`. Please note that these two optional flags have been introduced in MongoDB 3.2 and will not be included in the query unless explicitly set.
[[mongo.collation]]
=== Collations
MongoDB supports since 3.4 collations for collection and index creation and various query operations. Collations define string comparison rules based on the http://userguide.icu-project.org/collation/concepts[ICU collations]. A collation document consists of various properties that are encapsulated in `Collation`:
====
[source,java]
----
Collation collation = Collation.of("fr") <1>
.strength(ComparisonLevel.secondary() <2>
.includeCase())
.numericOrderingEnabled() <3>
.alternate(Alternate.shifted().punct()) <4>
.forwardDiacriticSort() <5>
.normalizationEnabled(); <6>
----
<1> `Collation` requires a locale for creation. This can be either a string representation of the locale, a `Locale` (considering language, country and variant) or a `CollationLocale`. The locale is mandatory for creation.
<2> Collation strength defines comparison levels denoting differences between characters. You can configure various options (case-sensitivity, case-ordering) depending on the selected strength.
<3> Specify whether to compare numeric strings as numbers or as strings.
<4> Specify whether the collation should consider whitespace and punctuation as base characters for purposes of comparison.
<5> Specify whether strings with diacritics sort from back of the string, such as with some French dictionary ordering.
<6> Specify whether to check if text requires normalization and to perform normalization.
====
Collations can be used to create collections and indexes. If you create a collection specifying a collation, the collation is applied to index creation and queries unless you specify a different collation. A collation is valid for a whole operation and cannot be specified on a per-field basis.
@ -2241,6 +2320,8 @@ You can create standard, geospatial and text indexes using the classes `IndexDef
@@ -2241,6 +2320,8 @@ You can create standard, geospatial and text indexes using the classes `IndexDef