Skip to content

DATAMONGO-1454 - Add support for exists projection in repository query methods. #381

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
wants to merge 2 commits into from

Conversation

mp911de
Copy link
Member

@mp911de mp911de commented Jul 28, 2016

We now support exists projections for query methods in query methods for derived and string queries.

public PersonReposotiry extends Repository<Person, String> {

  boolean existsByFirstname(String firstname);

  @Query(value = "{ 'lastname' : ?0 }", exists = true)
  boolean someExistQuery(String lastname);
}

Related ticket: DATAMONGO-1454
Depends on: spring-projects/spring-data-commons#171

* @since 1.10
* @return
*/
boolean exists() default false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we could derive that from the return type of the query method instead. Queries on MongoDB always return a document which can't be mapped to a boolean naturally. So we could just enable the exists execution for all query methods that return a boolean, can't we?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That works for string-based queries quite well. I added a commit to derive count queries from a long return type.

@mp911de mp911de force-pushed the issue/DATAMONGO-1454 branch 4 times, most recently from c01a004 to 6743f4b Compare October 11, 2016 07:12
@mp911de mp911de force-pushed the issue/DATAMONGO-1454 branch from 6743f4b to 6fa3a86 Compare December 2, 2016 13:20
…y methods.

We now support exists projections for query methods in query methods for derived and string queries.

public PersonReposotiry extends Repository<Person, String> {

  boolean existsByFirstname(String firstname);

  @ExistsQuery(value = "{ 'lastname' : ?0 }")
  boolean someExistQuery(String lastname);

  @query(value = "{ 'lastname' : ?0 }", exists = true)
  boolean anotherExistQuery(String lastname);
}
@mp911de mp911de force-pushed the issue/DATAMONGO-1454 branch from 6fa3a86 to 9d9fbfd Compare December 2, 2016 13:23
odrotbohm pushed a commit that referenced this pull request Dec 2, 2016
…y methods.

We now support exists projections for query methods in query methods for derived and string queries.

public PersonRepository extends Repository<Person, String> {

  boolean existsByFirstname(String firstname);

  @ExistsQuery(value = "{ 'lastname' : ?0 }")
  boolean someExistQuery(String lastname);

  @query(value = "{ 'lastname' : ?0 }", exists = true)
  boolean anotherExistQuery(String lastname);
}

Original pull request: #381.
odrotbohm added a commit that referenced this pull request Dec 2, 2016
Formatting in test case.

Original pull request: #381.
odrotbohm pushed a commit that referenced this pull request Dec 2, 2016
…y methods.

We now support exists projections for query methods in query methods for derived and string queries.

public PersonRepository extends Repository<Person, String> {

  boolean existsByFirstname(String firstname);

  @ExistsQuery(value = "{ 'lastname' : ?0 }")
  boolean someExistQuery(String lastname);

  @query(value = "{ 'lastname' : ?0 }", exists = true)
  boolean anotherExistQuery(String lastname);
}

Original pull request: #381.
odrotbohm added a commit that referenced this pull request Dec 2, 2016
Formatting in test case.

Original pull request: #381.
@odrotbohm odrotbohm closed this Dec 2, 2016
@odrotbohm odrotbohm deleted the issue/DATAMONGO-1454 branch December 2, 2016 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants