DATACOUCH-574 - Support countBy...() query method calls in repository.

This commit is contained in:
mikereiche
2020-06-23 13:31:02 -07:00
parent cd595995ed
commit c7f41f57ed
8 changed files with 122 additions and 31 deletions

View File

@@ -163,6 +163,16 @@ public class CouchbaseQueryMethod extends QueryMethod {
return StringUtils.hasText(query) ? query : null;
}
/**
* indicates if the method begins with "count"
*
* @return true if the method begins with "count", indicating that .count() should be called instead of one() or
* all().
*/
public boolean isCountQuery() {
return getName().toLowerCase().startsWith("count");
}
@Override
public String toString() {
return super.toString();

View File

@@ -59,15 +59,16 @@ public class N1qlRepositoryQueryExecutor {
Query query;
ExecutableFindByQueryOperation.ExecutableFindByQuery q;
if (queryMethod.hasN1qlAnnotation()) {
query = new StringN1qlQueryCreator(accessor, queryMethod, operations.getConverter(),
operations.getBucketName(), QueryMethodEvaluationContextProvider.DEFAULT,
namedQueries).createQuery();
query = new StringN1qlQueryCreator(accessor, queryMethod, operations.getConverter(), operations.getBucketName(),
QueryMethodEvaluationContextProvider.DEFAULT, namedQueries).createQuery();
} else {
final PartTree tree = new PartTree(queryMethod.getName(), domainClass);
query = new N1qlQueryCreator(tree, accessor, queryMethod, operations.getConverter()).createQuery();
}
q = (ExecutableFindByQueryOperation.ExecutableFindByQuery) operations.findByQuery(domainClass).matching(query);
if (queryMethod.isCollectionQuery()) {
if (queryMethod.isCountQuery()) {
return q.count();
} else if (queryMethod.isCollectionQuery()) {
return q.all();
} else {
return q.oneValue();

View File

@@ -63,15 +63,16 @@ public class ReactiveN1qlRepositoryQueryExecutor {
Query query;
ReactiveFindByQueryOperation.ReactiveFindByQuery q;
if (queryMethod.hasN1qlAnnotation()) {
query = new StringN1qlQueryCreator(accessor, queryMethod, operations.getConverter(),
operations.getBucketName(), QueryMethodEvaluationContextProvider.DEFAULT,
namedQueries).createQuery();
query = new StringN1qlQueryCreator(accessor, queryMethod, operations.getConverter(), operations.getBucketName(),
QueryMethodEvaluationContextProvider.DEFAULT, namedQueries).createQuery();
} else {
final PartTree tree = new PartTree(queryMethod.getName(), domainClass);
query = new N1qlQueryCreator(tree, accessor, queryMethod, operations.getConverter()).createQuery();
}
q = (ReactiveFindByQueryOperation.ReactiveFindByQuery) operations.findByQuery(domainClass).matching(query);
if (queryMethod.isCollectionQuery()) {
if (queryMethod.isCountQuery()) {
return q.count();
} else if (queryMethod.isCollectionQuery()) {
return q.all();
} else {
return q.one();