Package com.sap.cds.ql
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.-
Field Summary
Fields inherited from class com.sap.cds.ql.StatementBuilder
hints
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
accept
(CqnVisitor visitor) Traverses the expression tree represented by this token with a givenvisitor
.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.Sets the where condition of the select statement.byParams
(Collection<String> elementRefs) Sets the where condition of the select statement.columns
(Selectable... items) Sets the projection of the select statement.Sets the projection of the select statement.columns
(Function<T, ? extends Selectable>... items) Sets the projection of the select statement.columns
(List<? extends Selectable> items) Sets the projection of the select statement.columns
(Stream<? extends Selectable> items) Sets the projection of the select statement.static Select<StructuredType<?>>
static Select<StructuredType<?>>
Creates a select statement from a given CQN String.distinct()
Specifies that duplicate query results should be eliminated.Sets the exclude list of the select statement.excluding
(Collection<String> qualifiedNames) Sets the exclude list of the select statement.excluding
(Function<T, CqnSelectListValue>... items) Sets the exclude list of the select statement.static Select<StructuredType<?>>
from
(CqnTableFunction tableFunction) Creates a select statement to select entries from a table function.static Select<StructuredType<?>>
Creates a select statement to select entries from the result of a given subquery.static Select<StructuredType<?>>
from
(CqnStructuredTypeRef ref) Creates a select statement to select entries from a specified entity set.static <T extends StructuredType<T>>
Select<T>from
(StructuredType<T> entity) Creates a select statement to select entries from a specified entity set.static Select<StructuredType<?>>
Creates a select statement to select entries from a specified entity set.static Select<StructuredType<?>>
from
(CdsEntity entity, UnaryOperator<StructuredType<?>> path) Creates a select statement to select entries from a specified entity set.static <R extends StructuredType<R>,
T extends StructuredType<T>>
Select<T>Creates a select statement to select entries from a specified entity set.static <T extends StructuredType<T>>
Select<T>Creates a select statement to select entries from a specified entity set.static Select<StructuredType<?>>
Creates a select statement to select entries from a specified entity set.static Select<StructuredType<?>>
from
(String entityName, UnaryOperator<StructuredType<?>> path) Creates a select statement to select entries from a specified entity set.Sets the group by clause of the select statement.Sets the groupBy clause of the select statement.Sets the group by clause of the select statement.Sets the group by clause of the select statement.Sets the group by clause of the select statement.having
(CqnPredicate pred) Sets the having clause of the select statement.having
(Function<T, CqnPredicate> pred) Sets the having clause of the select statement.Specifies that the total number of root entities matching this query shall be returned along with the result.limit
(long top) Sets the limit of the select statement.limit
(long top, long skip) Sets the limit and offset of the select statement.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.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.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.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.Sets the where condition of the select statement.orderBy
(CqnSortSpecification... sortSpecs) Sets the orderBy clause of the select statement.Sets the orderBy clause of the select statement withdisplay names
of select list values.orderBy
(Function<T, CqnSortSpecification>... sortSpecs) Sets the orderBy clause of the select statement.orderBy
(List<CqnSortSpecification> sortSpecs) Sets the orderBy clause of the select statement.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.Adds a search filter to this select statement, requiring that any searchable element of the target entity set matches the given search termAdds a search filter to this select statement, requiring that any given searchable element of the target entity set matches the given search term.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.Adds a search filter to this select statement, requiring that any searchable element of the target entity set matches the given search predicate.toString()
where
(CqnPredicate pred) Sets the where condition of this select statement to a given predicate.where
(Function<T, CqnPredicate> pred) Sets the where condition of this select statement.Methods inherited from class com.sap.cds.ql.StatementBuilder
hint, hints, hints, hints
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface com.sap.cds.ql.cqn.CqnEntitySelector
hasInlineCount, hasLimit, items, orderBy, ref, skip, top
Methods inherited from interface com.sap.cds.ql.cqn.CqnFilterableStatement
where
Methods inherited from interface com.sap.cds.ql.cqn.CqnSelect
asSelect, columns, dispatch, excluding, from, getLock, groupBy, having, isDistinct, isSelect, search, transformations
Methods inherited from interface com.sap.cds.ql.cqn.CqnSource
asJoin, asRef, asSelect, asTableFunction, isJoin, isRef, isSelect, isTableFunction
Methods inherited from interface com.sap.cds.ql.cqn.CqnStatement
asDelete, asInsert, asUpdate, asUpsert, hints, isDelete, isInsert, isUpdate, isUpsert, ref
Methods inherited from interface com.sap.cds.JSONizable
toJson
-
Constructor Details
-
Select
public Select()
-
-
Method Details
-
from
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
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
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 expressionpath
- a path expression navigating from the root entity to the target entity of the select statement- Returns:
- the select statement
-
from
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
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
Creates a select statement to select entries from a table function.- Parameters:
tableFunction
- the table function- 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 reflectionpath
- a path expression navigating from the root entity to the target entity of the select statement- Returns:
- the select statement
- See Also:
-
from
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 entityT
- the type of the target entity- Parameters:
entity
- the static model representation of the entity setpath
- a path expression navigating from the root entity to the target entity of the select statement- Returns:
- the select statement
-
copy
- Parameters:
select
- theCqnSelect
to be copied- Returns:
- the modifiable select statement copy
-
cqn
Creates a select statement from a given CQN String.- Parameters:
cqnSelect
- the CQN representation of the select statement- Returns:
- the select statement
-
distinct
Specifies that duplicate query results should be eliminated.- Returns:
- this select statement
-
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
Sets the projection of the select statement.- Parameters:
items
- theCqnSelectListItem(s)
that shall be selected- Returns:
- this select statement
-
columns
Sets the projection of the select statement.- Parameters:
items
-Function(s)
providing theCqnSelectListItem(s)
that shall be selected- Returns:
- this select statement
-
columns
Sets the projection of the select statement.- Parameters:
items
- theCqnSelectListItem(s)
that shall be selected- Returns:
- this select statement
-
columns
Sets the projection of the select statement.- Parameters:
items
- theCqnSelectListItem(s)
that shall be selected- Returns:
- this select statement
-
columns
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
Sets the exclude list of the select statement.- Parameters:
qualifiedNames
- the items that shall be excluded from the projection- Returns:
- this select statement
-
excluding
Sets the exclude list of the select statement.- Parameters:
items
-Function(s)
providing theCqnSelectListValue(s)
that shall be excluded from the projection- Returns:
- this select statement
-
excluding
Sets the exclude list of the select statement.- Parameters:
qualifiedNames
- the items that shall be excluded from the projection- Returns:
- this select statement
-
where
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 interfaceFilterableStatement<T extends StructuredType<?>,
Select<T extends StructuredType<?>>> - Parameters:
pred
- aFunction
providing the where condition- Returns:
- this select statement
-
where
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 interfaceFilterableStatement<T extends StructuredType<?>,
Select<T extends StructuredType<?>>> - Parameters:
pred
- theCqnPredicate
- Returns:
- this select statement
-
matching
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 aCqnParameter
. The map entries are transformed into equality predicates and joined via and.- Specified by:
matching
in interfaceFilterableStatement<T extends StructuredType<?>,
Select<T extends StructuredType<?>>> - Parameters:
values
- the element name to value map defining the where condition- Returns:
- this select statement
-
byParams
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 aCqnParameter
that has the name of the ref. The predicates are joined via and.- Specified by:
byParams
in interfaceFilterableStatement<T extends StructuredType<?>,
Select<T extends StructuredType<?>>> - Parameters:
elementRefs
- the element references defining the where condition- Returns:
- this select statement
-
byParams
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 aCqnParameter
that has the name of the ref. The predicates are joined via and.- Specified by:
byParams
in interfaceFilterableStatement<T extends StructuredType<?>,
Select<T extends StructuredType<?>>> - Parameters:
elementRefs
- the element references defining the where condition- Returns:
- this select statement
-
byId
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 interfaceFilterableStatement<T extends StructuredType<?>,
Select<T extends StructuredType<?>>> - Parameters:
idValue
- the value of the target entity's key element- Returns:
- this select statement
-
search
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
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
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 predicatesearchableElements
- elements to be searched in. Overwrites default searchable columns.- Returns:
- this select statement
-
search
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 forsearchableElements
- elements to be searched in. Overwrites default searchable columns.- Returns:
- this select statement
-
lock
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 modetimeout
- maximum number of seconds to wait for [timeout] seconds for the lock acquisition. Afterwards the query execution will fail with aCdsLockTimeoutException
.- Returns:
- this select statement
-
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 a lock cannot be acquired, theCdsLockTimeoutException
is thrown upon statement execution.- Parameters:
mode
- the lock mode- Returns:
- this select statement
-
lock
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 execution will fail with theCdsLockTimeoutException
.- Returns:
- this select statement
-
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 a lock cannot be acquired, aCdsLockTimeoutException
is thrown upon statement execution.- Returns:
- this select statement
-
groupBy
Sets the group by clause of the select statement.- Parameters:
dimensions
- the elements the select shall be grouped by- Returns:
- this select statement
-
groupBy
Sets the group by clause of the select statement.- Parameters:
dimensions
-Function(s)
providing theCqnValue(s)
the select shall be grouped by- Returns:
- this select statement
-
groupBy
Sets the group by clause of the select statement.- Parameters:
dimensions
- theCqnValue(s)
the select shall be grouped by- Returns:
- this select statement
-
groupBy
Sets the group by clause of the select statement.- Parameters:
dimensions
- theCqnValue(s)
the select shall be grouped by- Returns:
- this select statement
-
groupBy
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
Sets the having clause of the select statement.- Parameters:
pred
- the having predicate condition- Returns:
- this select statement
-
having
Sets the having clause of the select statement.- Parameters:
pred
-Function(s)
providing the having predicate condition- Returns:
- this select statement
-
orderBy
Sets the orderBy clause of the select statement.- Parameters:
sortSpecs
-Function(s)
providing the sort specification- Returns:
- this select statement
-
orderBy
Sets the orderBy clause of the select statement.- Parameters:
sortSpecs
- the sort specifications- Returns:
- this select statement
-
orderBy
Sets the orderBy clause of the select statement.- Parameters:
sortSpecs
- the sort specifications- Returns:
- this select statement
-
orderBy
Sets the orderBy clause of the select statement withdisplay 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
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
Sets the limit and offset of the select statement.- Parameters:
top
- the maximum number of rows returned by the query or -1 if unlimitedskip
- the number of rows that shall be skipped- Returns:
- this select statement
-
toString
- Overrides:
toString
in classStatementBuilder<Select<T extends StructuredType<?>>>
-
accept
Description copied from interface:CqnToken
Traverses the expression tree represented by this token with a givenvisitor
. The traversal order is depth-first. If this token has child nodes they are traversed first by dispatching the visitor to the children'saccept
methods. Afterwards this token is passed to the visitor'svisit
method specific for this token's type.- Specified by:
accept
in interfaceCqnSelect
- Specified by:
accept
in interfaceCqnToken
- Parameters:
visitor
- theCqnVisitor
-