Skip to content

Add annotation-based Collation support [DATAMONGO-1854] #2755

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
spring-projects-issues opened this issue Jan 21, 2018 · 2 comments
Closed
Assignees
Labels
in: repository Repositories abstraction type: enhancement A general enhancement

Comments

@spring-projects-issues
Copy link

Shiv Veeram opened DATAMONGO-1854 and commented

Provide collation support in mongo repository interface


Reference URL: https://jira.mongodb.org/browse/SERVER-1920

Issue Links:

Referenced from: pull request #644

2 votes, 2 watchers

@spring-projects-issues
Copy link
Author

Christoph Strobl commented

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);
  1. 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

@spring-projects-issues
Copy link
Author

Christoph Strobl commented

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: repository Repositories abstraction type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants