Interface QueryCriteria

All Known Implementing Classes:
NumericQueryCriteria, SimpleQueryCriteria, StringQueryCriteria, ValueBetween, ValueContaining, ValueEndsWith, ValueGreaterThan, ValueGreaterThanOrEqualTo, ValueIs, ValueIsOneOf, ValueLessThan, ValueLessThanOrEqualTo, ValueLike, ValueStartsWith

public interface QueryCriteria
Used to provide criteria for database querying. Comes with static utility methods for easily creating these using semantic method chaining. Example:

import static io.john.amiscaray.quak.data.query.QueryCriteria.*;

public class Test {

    public void test() {
        QueryCriteria criteria = valueOfField("name", contains("oh"));
    }

}
  • Method Details

    • getTestPredicate

      jakarta.persistence.criteria.Predicate getTestPredicate(jakarta.persistence.criteria.Root<?> queryRoot, jakarta.persistence.criteria.CriteriaBuilder criteriaBuilder)
      Creates a predicate using the given query root and criteria builder.
      Parameters:
      queryRoot - The query root.
      criteriaBuilder - The criteria builder.
      Returns:
      The predicate representing the criteria to query the database.
    • and

      default QueryCriteria and(QueryCriteria queryCriteria)
      ANDs this query with another one.
      Parameters:
      queryCriteria - The other query.
      Returns:
      The criteria ANDed with the other criteria
    • or

      default QueryCriteria or(QueryCriteria queryCriteria)
      ORs this query with another one.
      Parameters:
      queryCriteria - The other query.
      Returns:
      A new QueryCriteria representing the criteria ORed with the other criteria
    • valueOfField

      static QueryCriteria valueOfField(String fieldName, QueryCriteriaProvider queryCriteriaProvider)
      Creates a query criteria testing that the value of a field matches some condition provided by a query criteria provider.
      Parameters:
      fieldName - The name of the field.
      queryCriteriaProvider - A query criteria provider. This should take the name of the field and test something on it.
      Returns:
      The query about the value of the given field.
    • matchesAllOf

      static QueryCriteriaProvider matchesAllOf(QueryCriteriaProvider... queryCriteriaProviders)
      ANDs the given query criteria providers into a single query criteria provider.
      Parameters:
      queryCriteriaProviders - The query criteria providers.
      Returns:
      The query criteria providers conjoined into a single one.
    • is

      static QueryCriteriaProvider is(Object value)
      Creates a query criteria provider testing that the value of a field equals to the given value.
      Parameters:
      value - The value.
      Returns:
      A query criteria provider.
    • isOneOf

      static QueryCriteriaProvider isOneOf(Object... values)
      Creates a query criteria provider testing that the value of a field equals one of the given values.
      Parameters:
      values - The values.
      Returns:
      A query criteria provider.
    • isBetween

      static QueryCriteriaProvider isBetween(Number min, Number max)
      Creates a query criteria provider testing that the value of a field is between a min and a max (inclusive).
      Parameters:
      min - The min.
      max - The max.
      Returns:
      A query criteria provider.
    • isGreaterThan

      static QueryCriteriaProvider isGreaterThan(Number value)
      Creates a query criteria provider testing that the value of a field is greater than some value.
      Parameters:
      value - The value.
      Returns:
      A query criteria provider.
    • isGreaterThanOrEqualTo

      static QueryCriteriaProvider isGreaterThanOrEqualTo(Number value)
      Creates a query criteria provider testing that the value of a field is greater than or equal to some value.
      Parameters:
      value - The value.
      Returns:
      A query criteria provider.
    • isLessThan

      static QueryCriteriaProvider isLessThan(Number value)
      Creates a query criteria provider testing that the value of a field is less than some value.
      Parameters:
      value - The value.
      Returns:
      A query criteria provider.
    • isLessThanOrEqualTo

      static QueryCriteriaProvider isLessThanOrEqualTo(Number value)
      Creates a query criteria provider testing that the value of a field is less than or equal to some value.
      Parameters:
      value - The value.
      Returns:
      A query criteria provider.
    • contains

      static QueryCriteriaProvider contains(String substring)
      Creates a query criteria provider testing that the value of a field contains a substring.
      Parameters:
      substring - The substring.
      Returns:
      A query criteria provider.
    • endsWith

      static QueryCriteriaProvider endsWith(String suffix)
      Creates a query criteria provider testing that the value of a field ends with a suffix.
      Parameters:
      suffix - The suffix.
      Returns:
      A query criteria provider.
    • startsWith

      static QueryCriteriaProvider startsWith(String prefix)
      Creates a query criteria provider testing that the value of a field starts with a prefix.
      Parameters:
      prefix - The prefix
      Returns:
      A query criteria provider.
    • isLike

      static QueryCriteriaProvider isLike(String regex)
      Creates a query criteria provider testing that the value of a field matches some regex (using SQL syntax).
      Parameters:
      regex - The regex.
      Returns:
      A query criteria provider.