Class EntityQuery

java.lang.Object
com.foreach.across.modules.entity.query.EntityQuery
All Implemented Interfaces:
EntityQueryExpression

public class EntityQuery extends Object implements EntityQueryExpression
Abstraction layer for *simple* query construction. An EntityQuery is a simple structure that has the support classes to be constructed from maps, de-serialized to and from JSON and later converted to specific query structures like JPA or QueryDSL.

An EntityQuery is limited in what it supports because it provides a common denominator for different query types.

Author:
Arne Vandamme
See Also:
  • Constructor Details

    • EntityQuery

      public EntityQuery()
    • EntityQuery

      public EntityQuery(@NonNull @NonNull EntityQueryOps operand)
    • EntityQuery

      public EntityQuery(EntityQuery entityQuery)
  • Method Details

    • add

      public final EntityQuery add(EntityQueryExpression expression)
    • setOperand

      public EntityQuery setOperand(@NonNull @NonNull EntityQueryOps operand)
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • hasExpressions

      public boolean hasExpressions()
      Returns:
      true if one or more expressions are present
    • hasSort

      public boolean hasSort()
      Returns:
      true if a sort has been set on this query and it contains orders
    • all

      public static EntityQuery all()
      Returns:
      new EntityQuery instance that will return all entities.
    • all

      public static EntityQuery all(org.springframework.data.domain.Sort sort)
      Returns:
      new EntityQuery instance that will return all entities, sorted accordingly
    • parse

      public static EntityQuery parse(String eql)
      Converts an EQL statement into a (raw) EntityQuery. Not validation or translation of any kind will be done on the elements, this will simply convert the String tokens into an EntityQuery object.

      You should use EntityQueryParser.parse(String) of the relevant entity if you want to parse an EQL into a fully executable EntityQuery. You can use EntityQueryParser.prepare(EntityQuery) to convert the raw query object into an executable one.

      Exceptions will be thrown if parsing fails.

      Parameters:
      eql - to convert
      Returns:
      EntityQuery
    • and

      public static EntityQuery and(EntityQueryExpression... expressions)
      Merges one or more entity queries expressions together using EntityQueryOps.AND. If expressions are sub-queries that define sort values, only the first non-null sort value will be kept.

      This method is null safe: null values will simply be ignored and a query will always be returned.

      Parameters:
      expressions - to merge
      Returns:
      merged query
    • or

      public static EntityQuery or(EntityQueryExpression... expressions)
      Merges one or more entity queries expressions together using EntityQueryOps.OR. If expressions are sub-queries that define sort values, only the first non-null sort value will be kept.

      This method is null safe: null values will simply be ignored and a query will always be returned.

      Parameters:
      expressions - to merge
      Returns:
      merged query
    • create

      public static EntityQuery create(EntityQueryOps operand, EntityQueryExpression... expressions)
    • of

      public static EntityQuery of(String eql)
      Parameters:
      eql - eql statement
      Returns:
      entity query
      See Also:
    • of

      public static EntityQuery of(EntityQuery query)
      Create a duplicate of an existing query. If the value passed in is null, a query instance for all values will be returned. As such, this method can be used to return the default query if you have a null value.
      Parameters:
      query - to duplicate
      Returns:
      query - never null
    • getSort

      public org.springframework.data.domain.Sort getSort()
      Ordering of the results.
    • getOperand

      public EntityQueryOps getOperand()
      Specified by:
      getOperand in interface EntityQueryExpression
    • getExpressions

      @NonNull public @NonNull List<EntityQueryExpression> getExpressions()
    • isTranslated

      public boolean isTranslated()
      Description copied from interface: EntityQueryExpression
      If an expression is marked as translated no additional translation should be performed by an EntityQueryTranslator.
      Specified by:
      isTranslated in interface EntityQueryExpression
      Returns:
      true if this expression is marked as translated.
      See Also:
    • setSort

      public EntityQuery setSort(org.springframework.data.domain.Sort sort)
      Ordering of the results.
      Returns:
      this.
    • setExpressions

      public EntityQuery setExpressions(@NonNull @NonNull List<EntityQueryExpression> expressions)
      Returns:
      this.
    • setTranslated

      public EntityQuery setTranslated(boolean translated)
      Returns:
      this.