Class Select<T extends StructuredType<?>>

Type Parameters:
T - the type of the entity set that is the source of this select statement
All Implemented Interfaces:
JSONizable, CqnEntitySelector, CqnFilterableStatement, CqnSelect, CqnSource, CqnStatement, CqnToken, FilterableStatement<T,Select<T>>, Source<T>, Statement<Select<T>>

public abstract class Select<T extends StructuredType<?>> extends StatementBuilder<Select<T>> implements Source<T>, CqnSelect, FilterableStatement<T,Select<T>>
The Select builder allows to construct CDS QL select statements, which can be executed via the CdsDataStore. Note that some methods in this class mutually exclude each other and cannot be combined. For example, the methods byId, byParams, matching, and where all set the where condition of the enclosing statement, overwriting any previously stored conditions.
  • Constructor Details

    • Select

      public Select()
  • Method Details

    • from

      public static Select<StructuredType<?>> from(String qualifiedName)
      Creates a select statement to select entries from a specified entity set.
      Parameters:
      qualifiedName - the fully qualified name of the CDS entity set
      Returns:
      the select statement
    • from

      public static Select<StructuredType<?>> from(CqnStructuredTypeRef ref)
      Creates a select statement to select entries from a specified entity set.
      Parameters:
      ref - the ref to the entity to select entries from
      Returns:
      the select statement
    • from

      public static <T extends StructuredType<T>> Select<T> from(StructuredType<T> entity)
      Creates a select statement to select entries from a specified entity set.
      Type Parameters:
      T - the type of the entity set
      Parameters:
      entity - the structured type representing the entity set
      Returns:
      the select statement
    • from

      public static Select<StructuredType<?>> from(String entityName, UnaryOperator<StructuredType<?>> path)
      Creates a select statement to select entries from a specified entity set.
      Parameters:
      entityName - the root entity name of the path expression
      path - a path expression navigating from the root entity to the target entity of the select statement
      Returns:
      the select statement
    • from

      public static Select<StructuredType<?>> from(CdsEntity entity)
      Creates a select statement to select entries from a specified entity set.
      Parameters:
      entity - the model representation of the entity set obtained by reflection
      Returns:
      the select statement
      See Also:
    • from

      public static Select<StructuredType<?>> from(CqnSelect subquery)
      Creates a select statement to select entries from the result of a given subquery.
      Parameters:
      subquery - the subquery to select from
      Returns:
      the select statement
    • from

      public static Select<StructuredType<?>> from(CdsEntity entity, UnaryOperator<StructuredType<?>> path)
      Creates a select statement to select entries from a specified entity set.
      Parameters:
      entity - the model representation of the entity set obtained by reflection
      path - a path expression navigating from the root entity to the target entity of the select statement
      Returns:
      the select statement
      See Also:
    • from

      public static <T extends StructuredType<T>> Select<T> from(Class<T> entity)
      Creates a select statement to select entries from a specified entity set.
      Type Parameters:
      T - the type of the entity set
      Parameters:
      entity - the static model representation of the entity set
      Returns:
      the select statement
    • from

      public static <R extends StructuredType<R>, T extends StructuredType<T>> Select<T> from(Class<R> entity, Function<R,T> path)
      Creates a select statement to select entries from a specified entity set.
      Type Parameters:
      R - the type of the root entity
      T - the type of the target entity
      Parameters:
      entity - the static model representation of the entity set
      path - a path expression navigating from the root entity to the target entity of the select statement
      Returns:
      the select statement
    • copy

      public static Select<StructuredType<?>> copy(CqnSelect select)
      Copies the given CqnSelect into a Select builder.
      Parameters:
      select - the CqnSelect to be copied
      Returns:
      the modifiable select statement copy
    • cqn

      public static Select<StructuredType<?>> cqn(String cqnSelect)
      Creates a select statement from a given CQN String.
      Parameters:
      cqnSelect - the CQN representation of the select statement
      Returns:
      the select statement
    • distinct

      public abstract Select<T> distinct()
      Specifies that duplicate query results should be eliminated.
      Returns:
      this select statement
    • inlineCount

      public abstract Select<T> inlineCount()
      Specifies that the total number of root entities matching this query shall be returned along with the result. Upon the calculation of the inline count the limit clause will be ignored. Inline count must not be used in combination with distinct, groupy by or having. The count may not exactly equal the actual number of root entities returned by this query.
      Returns:
      this select statement
    • columns

      @SafeVarargs public final Select<T> columns(Selectable... items)
      Sets the projection of the select statement.
      Parameters:
      items - the CqnSelectListItem(s) that shall be selected
      Returns:
      this select statement
    • columns

      @SafeVarargs public final Select<T> columns(Function<T,? extends Selectable>... items)
      Sets the projection of the select statement.
      Parameters:
      items - Function(s) providing the CqnSelectListItem(s) that shall be selected
      Returns:
      this select statement
    • columns

      public abstract Select<T> columns(List<? extends Selectable> items)
      Sets the projection of the select statement.
      Parameters:
      items - the CqnSelectListItem(s) that shall be selected
      Returns:
      this select statement
    • columns

      public abstract Select<T> columns(Stream<? extends Selectable> items)
      Sets the projection of the select statement.
      Parameters:
      items - the CqnSelectListItem(s) that shall be selected
      Returns:
      this select statement
    • columns

      public abstract Select<T> columns(String... elements)
      Sets the projection of the select statement. Elements are provided as Strings and can be paths that refer to an element of an entity that is reached via an association or composition, e.g. "author.name".
      Parameters:
      elements - the element(s) that shall be selected
      Returns:
      this select statement
    • excluding

      public final Select<T> excluding(String... qualifiedNames)
      Sets the exclude list of the select statement.
      Parameters:
      qualifiedNames - the items that shall be excluded from the projection
      Returns:
      this select statement
    • excluding

      @SafeVarargs public final Select<T> excluding(Function<T,CqnSelectListValue>... items)
      Sets the exclude list of the select statement.
      Parameters:
      items - Function(s) providing the CqnSelectListValue(s) that shall be excluded from the projection
      Returns:
      this select statement
    • excluding

      public abstract Select<T> excluding(Collection<String> qualifiedNames)
      Sets the exclude list of the select statement.
      Parameters:
      qualifiedNames - the items that shall be excluded from the projection
      Returns:
      this select statement
    • where

      public abstract Select<T> where(Function<T,CqnPredicate> pred)
      Sets the where condition of this select statement. The where condition is provided as a function that accepts a model object representing the entity targeted by the select and returning the where condition.
      Specified by:
      where in interface FilterableStatement<T extends StructuredType<?>,Select<T extends StructuredType<?>>>
      Parameters:
      pred - a Function providing the where condition
      Returns:
      this select statement
    • where

      public abstract Select<T> where(CqnPredicate pred)
      Sets the where condition of this select statement to a given predicate. If this statement already has a where condition it is replaced with the given one.
      Specified by:
      where in interface FilterableStatement<T extends StructuredType<?>,Select<T extends StructuredType<?>>>
      Parameters:
      pred - the CqnPredicate
      Returns:
      this select statement
    • matching

      public abstract Select<T> matching(Map<String,?> values)
      Sets the where condition of the select statement. The where condition is computed from a map of element names of the target entity set to their values, or a CqnParameter. The map entries are transformed into equality predicates and joined via and.
      Specified by:
      matching in interface FilterableStatement<T extends StructuredType<?>,Select<T extends StructuredType<?>>>
      Parameters:
      values - the element name to value map defining the where condition
      Returns:
      this select statement
    • byParams

      public Select<T> byParams(String... elementRefs)
      Sets the where condition of the select statement. The where condition is computed from the given vararg of element references of the target entity. For each element reference a predicate is created comparing the element ref with a CqnParameter that has the name of the ref. The predicates are joined via and.
      Specified by:
      byParams in interface FilterableStatement<T extends StructuredType<?>,Select<T extends StructuredType<?>>>
      Parameters:
      elementRefs - the element references defining the where condition
      Returns:
      this select statement
    • byParams

      public abstract Select<T> byParams(Collection<String> elementRefs)
      Sets the where condition of the select statement. The where condition is computed from the given collection of element references of the target entity. For each element ref a predicate is created comparing the ref with a CqnParameter that has the name of the ref. The predicates are joined via and.
      Specified by:
      byParams in interface FilterableStatement<T extends StructuredType<?>,Select<T extends StructuredType<?>>>
      Parameters:
      elementRefs - the element references defining the where condition
      Returns:
      this select statement
    • byId

      public abstract Select<T> byId(Object idValue)
      Sets the where condition of the select statement, requiring that the value of the single key element of the target entity set is equal to the given idValue.
      Specified by:
      byId in interface FilterableStatement<T extends StructuredType<?>,Select<T extends StructuredType<?>>>
      Parameters:
      idValue - the value of the target entity's key element
      Returns:
      this select statement
    • search

      public abstract Select<T> search(String searchTerm)
      Adds a search filter to this select statement, requiring that any searchable element of the target entity set matches the given search term
      Parameters:
      searchTerm - the value to be searched for
      Returns:
      this select statement
    • search

      public abstract Select<T> search(Function<Searchable,Predicate> pred)
      Adds a search filter to this select statement, requiring that any searchable element of the target entity set matches the given search predicate.
      Parameters:
      pred - search predicate
      Returns:
      this select statement
    • search

      public abstract Select<T> search(CqnPredicate pred)
      Adds a search filter to this select statement, requiring that any searchable element of the target entity set matches the given search predicate.
      Parameters:
      pred - search predicate
      Returns:
      this select statement
    • search

      public abstract Select<T> search(Function<Searchable,Predicate> pred, Iterable<String> searchableElements)
      Adds a search filter to this select statement, requiring that any searchable element of the target entity set matches the given search predicate.
      Parameters:
      pred - search predicate
      searchableElements - elements to be searched in. Overwrites default searchable columns.
      Returns:
      this select statement
    • search

      public abstract Select<T> search(String searchTerm, Iterable<String> searchableElements)
      Adds a search filter to this select statement, requiring that any given searchable element of the target entity set matches the given search term.
      Parameters:
      searchTerm - the value to be searched for
      searchableElements - elements to be searched in. Overwrites default searchable columns.
      Returns:
      this select statement
    • lock

      public abstract Select<T> lock(CqnLock.Mode mode, int timeout)
      Creates a write lock on the selected rows so that other queries cannot lock or change the data until current transaction is finished.
      Parameters:
      mode - the lock mode
      timeout - maximum number of seconds to wait for [timeout] seconds for the lock acquisition, afterwards the query will fail with the CdsLockTimeoutException
      Returns:
      this select statement
      Throws:
      CdsLockTimeoutException - if a lock could not be acquired
    • lock

      public abstract Select<T> lock(CqnLock.Mode mode)
      Creates a write lock on the selected rows for a default number of seconds specified by DB so that other queries cannot lock or change the data until current transaction is finished. If lock cannot be acquired, the CdsLockTimeoutException is thrown.
      Parameters:
      mode - the lock mode
      Returns:
      this select statement
      Throws:
      CdsLockTimeoutException - if a lock could not be acquired
    • lock

      public Select<T> lock(int timeout)
      Creates a write lock on the selected rows so that other queries cannot lock or change the data until current transaction is finished.
      Parameters:
      timeout - maximum number of seconds to wait for [timeout] seconds for the lock acquisition, afterwards the query will fail with the CdsLockTimeoutException
      Returns:
      this select statement
      Throws:
      CdsLockTimeoutException - if a lock could not be acquired
    • lock

      public Select<T> lock()
      Creates a write lock on the selected rows for a default number of seconds specified by DB so that other queries cannot lock or change the data until current transaction is finished. If lock cannot be acquired, the CdsLockTimeoutException is thrown.
      Returns:
      this select statement
      Throws:
      CdsLockTimeoutException - if a lock could not be acquired
    • groupBy

      public final Select<T> groupBy(CqnValue... dimensions)
      Sets the group by clause of the select statement.
      Parameters:
      dimensions - the elements the select shall be grouped by
      Returns:
      this select statement
    • groupBy

      @SafeVarargs public final Select<T> groupBy(Function<T,CqnValue>... dimensions)
      Sets the group by clause of the select statement.
      Parameters:
      dimensions - Function(s) providing the CqnValue(s) the select shall be grouped by
      Returns:
      this select statement
    • groupBy

      public abstract Select<T> groupBy(List<? extends CqnValue> dimensions)
      Sets the group by clause of the select statement.
      Parameters:
      dimensions - the CqnValue(s) the select shall be grouped by
      Returns:
      this select statement
    • groupBy

      public abstract Select<T> groupBy(Stream<? extends CqnValue> dimensions)
      Sets the group by clause of the select statement.
      Parameters:
      dimensions - the CqnValue(s) the select shall be grouped by
      Returns:
      this select statement
    • groupBy

      public abstract Select<T> groupBy(String... elements)
      Sets the groupBy clause of the select statement. Elements are provided as Strings and can be paths that refer to an element of an entity that is reached via an association or composition, e.g. "author.name".
      Parameters:
      elements - the element(s) the select shall be grouped by
      Returns:
      this select statement
    • having

      public abstract Select<T> having(CqnPredicate pred)
      Sets the having clause of the select statement.
      Parameters:
      pred - the having predicate condition
      Returns:
      this select statement
    • having

      public abstract Select<T> having(Function<T,CqnPredicate> pred)
      Sets the having clause of the select statement.
      Parameters:
      pred - Function(s) providing the having predicate condition
      Returns:
      this select statement
    • orderBy

      @SafeVarargs public final Select<T> orderBy(Function<T,CqnSortSpecification>... sortSpecs)
      Sets the orderBy clause of the select statement.
      Parameters:
      sortSpecs - Function(s) providing the sort specification
      Returns:
      this select statement
    • orderBy

      public final Select<T> orderBy(CqnSortSpecification... sortSpecs)
      Sets the orderBy clause of the select statement.
      Parameters:
      sortSpecs - the sort specifications
      Returns:
      this select statement
    • orderBy

      public abstract Select<T> orderBy(List<CqnSortSpecification> sortSpecs)
      Sets the orderBy clause of the select statement.
      Parameters:
      sortSpecs - the sort specifications
      Returns:
      this select statement
    • orderBy

      public abstract Select<T> orderBy(String... displayNames)
      Sets the orderBy clause of the select statement with display names of select list values. The display names are provided as the strings and can be:
      • names of an elements
      • aliases of the select list values
      • paths of display names that follow to-one associations
      • paths of display names that sub-elements of the structured elements
      Parameters:
      displayNames - the display names defining the sort order
      Returns:
      this select statement
    • limit

      public Select<T> limit(long top)
      Sets the limit of the select statement.
      Parameters:
      top - the maximum number of rows returned by the query or -1 if unlimited
      Returns:
      this select statement
    • limit

      public abstract Select<T> limit(long top, long skip)
      Sets the limit and offset of the select statement.
      Parameters:
      top - the maximum number of rows returned by the query or -1 if unlimited
      skip - the number of rows that shall be skipped
      Returns:
      this select statement
    • toString

      public String toString()
      Overrides:
      toString in class StatementBuilder<Select<T extends StructuredType<?>>>
    • accept

      public void accept(CqnVisitor visitor)
      Description copied from interface: CqnToken
      Traverses the expression tree represented by this token with a given visitor. The traversal order is depth-first. If this token has child nodes they are traversed first by dispatching the visitor to the children's accept methods. Afterwards this token is passed to the visitor's visit method specific for this token's type.
      Specified by:
      accept in interface CqnSelect
      Specified by:
      accept in interface CqnToken
      Parameters:
      visitor - the CqnVisitor