[DATAMONGO-1854] Add annotation-based Collation support Created: 21/Jan/18  Updated: 23/May/19  Resolved: 23/Apr/19

Status: Closed
Project: Spring Data MongoDB
Component/s: Repository
Affects Version/s: None
Fix Version/s: 2.2 M4 (Moore)

Type: Improvement Priority: Major
Reporter: Shiv Veeram Assignee: Christoph Strobl
Resolution: Complete Votes: 2
Labels: moore
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
is duplicated by DATAMONGO-2284 Annotation Support for Collations Closed
Relate
is related to DATAMONGO-1518 Add support for Collations Closed
Reference URL: https://jira.mongodb.org/browse/SERVER-1920
Last updater: Mark Paluch
Pull Request URL: https://github.com/spring-projects/spring-data-mongodb/pull/644
Sprint: Lovelace SR1

 Description   

Provide collation support in mongo repository interface.



 Comments   
Comment by Christoph Strobl [ 17/Dec/18 ]

Collation support for Reactive/MongoRepository interfaces could look like this:

1) Via @Query Annotaion

The @Query annotation should be extended to have a collation attribute. The attribute can be a fixed String holding the collation value, the collation JSON representation, a parameter binding flag, of even a JSON allowing parameter binding. Also SpEL might be an option.

@Query(collation = "en_US")
List<Entry> findAllByFixedCollation();

@Query(collation = "{ 'locale' :  'en_US' }")
List<Entry> findAllByFixedJsonCollation();

@Query(collation = "?0")
List<Entry> findAllByDynamicCollation(String collation);

@Query(collation = "{ 'locale' :  ?0 }")
List<Entry> findAllByDynamicJsonCollation(String collation);

@Query(collation = "?#{[0]}")
List<Entry> findAllByDynamicSpElCollation(String collation);

2) Via typed Parameter

...Collation parameter is auto detected via its type (o.s.d.m.core.query.Collation) and applied to the Query.

List<Entry> findAllBy(Collation collation)

A comination of 1) & 2) should lead to an error.

Comment by Christoph Strobl [ 25/Feb/19 ]

Intoducing a new @Collation annotation would allow us to add a CollationResolver that could react on

Collation on domain type

@Document
@Collation("en_US")
public class DomainType {
	
}
  1. Apply the collation value when creating a MongoDB collection via MongoTemplate#createCollection(java.lang.Class)
  2. Apply the collation to indices created for the domain type
  3. Apply the collation to queries issued against the collection
    1. If the Query does not explicitly specify an Collation.
    2. To use the Server default, Query would have to have Collation#SIMPLE set.

Collation on repository

@Collation("en_US")
public interface MyRepo extends Repository<...> {
	
}
  1. Apply the collation to queries issued against the collection
  2. Apply the collation to indexes auto created for finder methods.

Collation on repository finder method

@Collation("en_US")
public interface MyRepo extends Repository<...> {
	
    @Collation("de_AT")
    List<Entry> findAllByFixedCollation();

    @Collation("?0")
    List<Entry> findAllByDynamicCollation(String collation);
}
  1. Override the potential default collation for specific finders.
  2. Apply the collation to indexes auto created for finder methods.
Generated at Wed Oct 16 21:44:49 UTC 2019 using Jira 7.13.8#713008-sha1:1606a5c1e7006e1ab135aac81f7a9566b2dbc3a6.