DATACASS-512 - Support exists and count projections.

We now support exists and count projections derived from query methods and on Template API level.

Exists queries fetch rows limiting to a single row to optimize fetching.

Exists queries also support count results, i.e. a single row with a single numeric column is considered a count result. It's evaluated by comparing the number being greater to zero.

boolean exists = template.exists(Query.query(where("firstname").is("Walter")), Person.class);

long count = template.count(Query.query(where("lastname").is("White")), Person.class);

interface PersonRepository extends Repository<Person, String> {

    long countByLastname(String lastname); // derived query

    boolean existsByLastname(String lastname);  // derived query

    @CountQuery("SELECT COUNT(*) from users WHERE lastname = ?0")
    long countQueryByLastname(String lastname); // String-based query

    @ExistsQuery("SELECT * from users WHERE lastname = ?0 LIMIT 1")
    boolean existsQueryByLastname(String lastname);  // String-based query
}

Remove superfluous throws declarations.
This commit is contained in:
Mark Paluch
2018-01-19 10:16:00 +01:00
committed by John Blum
parent 4538b2aa56
commit c0b9479599
36 changed files with 1132 additions and 116 deletions

View File

@@ -3,6 +3,11 @@
This chapter summarizes changes and new features for each release.
[[new-features.2-1-0]]
== What's new in Spring Data for Apache Cassandra 2.1
* New annotations for `@CountQuery` and `@ExistsQuery`.
* Template API extended with `count(…)` and `exists(…)` methods accepting `Query`.
[[new-features.2-0-0]]
== What's new in Spring Data for Apache Cassandra 2.0