Skip to content
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

Implement Criteria API prototype #3

Open
ivan-gammel opened this issue Mar 30, 2022 · 0 comments
Open

Implement Criteria API prototype #3

ivan-gammel opened this issue Mar 30, 2022 · 0 comments

Comments

@ivan-gammel
Copy link
Owner

Simple criteria API can be a reasonable alternative to Spring Data-like finder methods, if it enables at least filtering and ordering of the results.
Possible solution may look like following:

Java model

public record Account(String firstName, LocalDate birthDate) {}

Generated code

public class AccountRepository implements Finder<AccountCriteria, Account> {

    public static class AccountCriteria implements Criteria<AccountCriteria, Account> {}

    public static StringCriteriaBuilder<AccountCriteria> firstName() {}
    public static TemporalCriteriaBuilder<AccountCriteria> birthDate() {}

    // restrict to specific types of conditions
   @Override
    public List<Account> findAll(AccountCriteria criteria) {
         var rs = jdbc.query("SELECT firstName, birthDate FROM Account WHERE " + criteria.toSQLTemplate(), criteria.params())
    }
}

User code

AccountRepository accounts;

@Get("/search-accounts")
public List<Accounts> find(LocalDate givenDate, String searchString) {
      return accounts.findAll(birthDate().before(givenDate)
                                           .and(firstName().containsIgnoreCase(searchString)));
}
@ivan-gammel ivan-gammel added this to the v1_persistence milestone Mar 30, 2022
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

No branches or pull requests

1 participant