jakartaee / jakartaee/data

Count and Exists when using Constraints instead of method name queries

Open
#1,573 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Java
Stars
150
Forks
37
Avg merge
4d 4h
Merged PRs (30d)
34

Description

#857 covered most of what is possible with method name queries to also be possible with constraint queries, but didn't include any alternative for countBy and existsBy.

One way to achieve this would be with `@Count` and `@Exists` annotations for repository methods where the former returns `long` or `int` and the latter returns `boolean`. Or, if a single annotation is preferred, then the return type could control whether it is a count vs. an exists operation. Aligning with the `@Find` annotation, we could even include a value to optionally indicate the entity type to disambiguate when using a multiple entity repository. Or, maybe someone will think of another way to design count/exists queries.

The general idea is that we could have something like,

```java
@Exists
boolean isAvailable(@By(_Product.ID) long productNumber,
@By(_Product.QUANTITY_IN_STOCK) @Is(AtLeast.class) int minAvailable);

@Count
long totalDiscounted(Department department, Restriction filter);
```

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading issue #857 and the existing @Find annotation and repository method query handling. Compare the proposed @Count and @Exists designs, including return-type behavior and entity disambiguation for multiple-entity repositories. Done means an agreed API design with its behavior and required validation or tests specified.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend-api-design
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Active
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.