Class Conditions

java.lang.Object
ch.tocco.nice2.persist.core.api.qb2.Conditions

public final class Conditions extends Object
This is a hub-class that defines some nice-to-have shortcuts but also collects static methods from other places. The idea is to have a single import line to access the query builder "dsl".
  • Method Details

    • equation

      public static Condition equation(Factor left, EquationNode.Operator op, Factor right)
    • equations

      public static Iterable<Condition> equations(Factor left, EquationNode.Operator op, Iterable<? extends Factor> right)
      Creates as many equation conditions as right factors are specified.
    • and

      public static Junction and(Condition... conditions)
    • and

      public static Junction and(Iterable<? extends Condition> conditions)
    • or

      public static Junction or(Condition... conditions)
    • or

      public static Junction or(Iterable<? extends Condition> conditions)
    • not

      public static Junction not(Condition... conditions)
    • not

      public static Junction not(Iterable<? extends Condition> conditions)
    • function

      public static Function function(String identifier)
    • fulltext

      public static Function fulltext(String query)
    • likeall

      public static Function likeall(String query, Iterable<String> pathList)
    • likeall

      public static Function likeall(String query, String... pathList)
    • count

      public static SubQuery count(String path)
      Counts the entities of the relation at the end of path (e.g. relRegistration). The relations before the last one are joined in the main query, so the count is calculated per entity reached by them: on Event_status, count("relEvent.relRegistration").is(3) matches if one event has 3 registrations, not if all events together have 3.
    • sum

      public static SubQuery sum(String path)
      Sums the numeric field at the end of path, which has to contain at least one relation (e.g. relOrder_position.price_order_currency). Like count, a sum over no rows is 0. The relations before the last one are joined in the main query, so the sum is calculated per entity reached by them: on Order_status, sum("relOrder.relOrder_position.price_order_currency").is(100) matches if the positions of one order sum up to 100, not if the positions of all orders together do.
    • avg

      public static SubQuery avg(String path)
      Averages the numeric field at the end of path, which has to contain at least one relation (e.g. relOrder_position.price_order_currency). An average over no rows is null and therefore only matches is(null). The relations before the last one are joined in the main query, so the average is calculated per entity reached by them, not over all entities at the end of the path.
    • min

      public static SubQuery min(String path)
      The minimum of the comparable field at the end of path, which has to contain at least one relation (e.g. relReservation.date_from). The minimum over no rows is null and therefore only matches is(null). The relations before the last one are joined in the main query, so the minimum is calculated per entity reached by them, not over all entities at the end of the path.
    • max

      public static SubQuery max(String path)
      The maximum of the comparable field at the end of path, which has to contain at least one relation (e.g. relReservation.date_from). The maximum over no rows is null and therefore only matches is(null). The relations before the last one are joined in the main query, so the maximum is calculated per entity reached by them, not over all entities at the end of the path.
    • exists

      public static SubQuery exists(String path)
      Creates a new EXISTS subquery to the given path.
    • existsNested

      public static SubQuery existsNested(String path)
      If `path` involves multiple paths (like relFoo.relBar), create nested exists. Otherwise it is the same as SubQuery.exists(String). Example: instead of `exists(relFoo.relBar where …` do `exists(relFoo where exists(relBar where –))` A special SubQuery class is returned, where each condition that is added via `where` calls is appended to the innermost subquery. Calls to `isTrue` apply to all subqueries. All other (reading) operations are applied to the root subquery.
    • subSelect

      public static UncorrelatedSubQuery subSelect(String column, EntityModel model)
      Create an uncorrelated sub select that may select a column from an the provided entity model. E.g.
          EntityModel userModel = context.getEntityManager("User").getModel();
          EntityList foundUsers = queryBuilder.find("User").where(
              field("birthdate").greaterThan(subSelect("birthdate", userModel).where(
                  field("lastname").is("Ott")
              )),
              field("firstname").is("Robin")
          ).build(context).execute());
      
      Parameters:
      column - the column to select
      model - the target entity model
      Returns:
      the UncorrelatedSubQuery instance
    • relationTo

      public static Condition relationTo(String relationPath, PrimaryKey key)
      Creates a condition that checks whether the given relationPath points to the entity specified by key.
    • relationToOne

      public static Condition relationToOne(String relationPath, Iterable<PrimaryKey> keys)
      Creates a condition that checks whether the given relationPath points to at least one of the entities specified by keys.
    • relationToAll

      public static Condition relationToAll(String relationPath, Iterable<PrimaryKey> keys)
      Creates a condition that checks whether the given relationPath points to all entities given by keys.
    • field

      public static FieldDef field(String name)
      Creates a new field defintion that can be used to create conditions starting from a field.
    • fieldExists

      public static FieldDef fieldExists(String name)
      Same as field(String) but uses (nested) exists statements.
    • relation

      public static RelationDef relation(String relationPath)
      Creates a new relation definition that can be used to create conditions starting from a relation.
    • param

      public static Factor param(String paramName)
    • literal

      public static Factor literal(@Nullable Object value)
    • path

      public static Factor path(String pathName)
    • primaryKeyIs

      public static Condition primaryKeyIs(PrimaryKey key)
    • primaryKeyIn

      public static Condition primaryKeyIn(Iterable<PrimaryKey> keys)
    • primaryKeyIsNot

      public static Condition primaryKeyIsNot(PrimaryKey key)
    • commaSeparatedListContains

      public static Condition commaSeparatedListContains(String fieldName, String string, boolean orEmpty)
      Condition that checks whether the provided `string` is contained (exact match!) in a comma separated list to be found in field `fieldName`.
      Parameters:
      fieldName - the name of the field containing the comma separated list on the entity
      string - a string to be found in the list
      orEmpty - set to `true` to also return entities if the field `fieldName` is empty
      Returns:
      a `Condition`
    • isFalse

      public static Condition isFalse()
    • isTrue

      public static Condition isTrue()
    • raw

      public static Condition raw(Node node)