Package com.sap.cds.ql
Interface CQL
-
public interface CQL
-
-
Method Summary
All Methods Static Methods Deprecated Methods Modifier and Type Method Description static Predicate
and(CqnPredicate p1, CqnPredicate p2)
Creates a conjunction of two given predicatesstatic Predicate
and(Iterable<? extends CqnPredicate> predicates)
Creates a conjunction of given predicatesstatic Value<Number>
average(CqnValue value)
Creates an average function call on the given element or expression.static BooleanFunction
booleanFunc(String name, List<? extends CqnValue> args)
Creates a CDS QL function call that is send to the underlying data store.static Predicate
comparison(CqnValue lhs, CqnComparisonPredicate.Operator op, CqnValue rhs)
Creates a comparison predicate.static Predicate
connect(CqnConnectivePredicate.Operator operator, Iterable<? extends CqnPredicate> predicates)
Creates a logical connection of given predicatesCqnPredicate
.static <T> Literal<T>
constant(T value)
Creates a _constant_ CDS QLLiteral
hinting to the runtime that the value should be treated as constant.static Predicate
containment(CqnContainmentTest.Position position, CqnValue value, CqnValue substring, boolean caseInsensitive)
Creates a predicate that tests whether a string value contains a given substring at a given positionCqnContainmentTest.Position
static Predicate
contains(CqnValue value, CqnValue substring, boolean caseInsensitive)
Creates a predicate that tests whether a string value contains a given substringstatic Predicate
copy(CqnPredicate pred)
Creates a copy of the given predicate.static Predicate
copy(CqnPredicate pred, Modifier modifier)
Creates a modified copy of the given predicate.static <S extends CqnStatement>
Scopy(S statement)
Creates a copy of the given CQN statement.static <S extends CqnStatement>
Scopy(S statement, Modifier modifier)
Creates a modified copy of the given CQN statement.static Value<Long>
count()
Creates a count all function call.static Value<Long>
count(CqnElementRef element)
Creates a count function call on the given element.static Value<Long>
countDistinct(CqnValue value)
Creates an count distinct function call on the given element or expression.static Predicate
endsWith(CqnValue value, CqnValue suffix, boolean caseInsensitive)
Creates a predicate that tests whether a string value ends with a given suffixstatic StructuredType<?>
entity(String qualifiedName)
Creates aStructuredType
representing a CDS entity.static Predicate
exists(CqnSelect subQuery)
Creates an exists predicate that tests if a given subquery returns any rowstatic Value<Number>
expression(CqnValue left, CqnArithmeticExpression.Operator op, CqnValue right)
Creates an arithmetic expression.static <T> FunctionCall<T>
func(String name, CqnValue... args)
Creates a CDS QL function call that is send to the underlying data store.static <T> FunctionCall<T>
func(String name, List<? extends CqnValue> args)
Creates a CDS QL function call that is send to the underlying data store.static <T> ElementRef<T>
get(String path)
Creates anElementRef
representing a path from a CDS entity to an element of this or another entity.static <T> ElementRef<T>
get(List<? extends CqnReference.Segment> segments)
Creates anElementRef
representing a path from a CDS entity to an element of this or another entity.static Predicate
in(CqnValue lhs, CqnValue valueSet)
Creates an in predicate.static Predicate
in(CqnValue lhs, Collection<? extends CqnValue> values)
Creates an in predicate.static CqnToken
list(List<? extends CqnValue> values)
Creates aCqnListValue
composing given valuesstatic <T> Literal<T>
literal(T value)
Deprecated.use constant() for _constant_ and val() for _non-constant_ handlingstatic Predicate
match(StructuredTypeRef ref, Predicate pred, CqnMatchPredicate.Quantifier quantifier)
Creates a match predicate that tests if a given ref matches a given filterstatic Predicate
matching(Map<String,?> elementToValueMap)
Creates a predicate from a map of element names to values or parameters.static <T> Value<T>
max(CqnValue value)
Creates a max function call on the given element or expression.static <T> Value<T>
min(CqnValue value)
Creates a min function call on the given element or expression.static Predicate
not(CqnPredicate predicate)
Negates a givenCqnPredicate
.static Value<Instant>
now()
Creates anElementRef
to be used in queries to represent $now.static Predicate
or(CqnPredicate p1, CqnPredicate p2)
Creates a disjunction of two given predicatesstatic Predicate
or(Iterable<? extends CqnPredicate> predicates)
Creates a disjunction of given predicatesstatic <T> Parameter<T>
param()
static <T> Parameter<T>
param(int index)
Creates an indexedParameter
to be used in CQN statements.static <T> Parameter<T>
param(String name)
Creates a namedParameter
to be used in queries.static Value<?>
plain(String value)
Creates a CQN plain value, which is directly send to the underlying data store.static RefSegment
refSegment(String id)
Creates a segment of a structured type or element reference.static List<RefSegment>
refSegments(List<String> segmentIds)
Creates a list of reference segments.static Predicate
search(String term)
Creates a search predicate.static CqnSortSpecification
sort(CqnValue value, CqnSortSpecification.Order order)
Creates aCqnSortSpecification
that sorts a value by a given orderstatic CqnStar
star()
static Predicate
startsWith(CqnValue value, CqnValue prefix, boolean caseInsensitive)
Creates a predicate that tests whether a string value starts with a given prefixstatic Value<Number>
sum(CqnValue value)
Creates a sum function call on the given element or expression.static StructuredType<?>
to(String path)
Creates aStructuredType
representing a path from a CDS entity to another entity.static StructuredType<?>
to(List<? extends CqnReference.Segment> segments)
Creates aStructuredType
representing a path from a CDS entity to another entity.static Value<String>
toLower(Value<String> val)
Creates a CDS QL expression for converting the given string value to lower case using the rules of the underlying data store.static Value<String>
toLower(String val)
Creates a CDS QL expression for converting the given string value to lower case using the rules of the underlying data store.static Value<String>
toUpper(Value<String> val)
Creates a CDS QL expression for converting the given string value to upper case using the rules of the underlying data store.static Value<String>
toUpper(String val)
Creates a CDS QL expression for converting the given string value to upper case using the rules of the underlying data store.static Value<String>
userId()
Creates anElementRef
on the available $user.id value.static Value<String>
userLocale()
Creates anElementRef
on the available $user.locale value.static <T> Literal<T>
val(T value)
Creates a _non-constant_ CDS QLLiteral
hinting to the runtime that the value should not be treated as constant.static Value<Instant>
validFrom()
Creates anElementRef
on the available $validFrom value.static Value<Instant>
validTo()
Creates anElementRef
on the available $validTo value.static Collector<CqnPredicate,?,CqnPredicate>
withAnd()
Returns aCollector
that connects the input predicates with AND.static Collector<CqnPredicate,?,CqnPredicate>
withOr()
Returns aCollector
that connects the input predicates with OR.
-
-
-
Method Detail
-
copy
static Predicate copy(CqnPredicate pred)
Creates a copy of the given predicate.- Parameters:
pred
- the predicate to be copied- Returns:
- the copy
-
copy
static Predicate copy(CqnPredicate pred, Modifier modifier)
Creates a modified copy of the given predicate.- Parameters:
pred
- the predicate to be copiedmodifier
- the modifier for altering the copy- Returns:
- the modified copy
-
copy
static <S extends CqnStatement> S copy(S statement)
Creates a copy of the given CQN statement.- Type Parameters:
S
- the type of CqnStatement- Parameters:
statement
- the CQN statement to be copied- Returns:
- the copy
-
copy
static <S extends CqnStatement> S copy(S statement, Modifier modifier)
Creates a modified copy of the given CQN statement.- Type Parameters:
S
- the type of CqnStatement- Parameters:
statement
- the CQN statement to be copiedmodifier
- the modifier for altering the copy- Returns:
- the modified copy
-
func
static <T> FunctionCall<T> func(String name, CqnValue... args)
Creates a CDS QL function call that is send to the underlying data store.- Type Parameters:
T
- the return type of the function call- Parameters:
name
- the name of the function to be calledargs
- the arguments of the function- Returns:
- the CDS QL function call
-
func
static <T> FunctionCall<T> func(String name, List<? extends CqnValue> args)
Creates a CDS QL function call that is send to the underlying data store.- Type Parameters:
T
- the return type of the function call- Parameters:
name
- the name of the function to be calledargs
- the arguments of the function- Returns:
- the CDS QL function call
-
booleanFunc
static BooleanFunction booleanFunc(String name, List<? extends CqnValue> args)
Creates a CDS QL function call that is send to the underlying data store.- Parameters:
name
- the name of the function to be calledargs
- the arguments of the function- Returns:
- the CDS QL function call
-
literal
@Deprecated static <T> Literal<T> literal(T value)
Deprecated.use constant() for _constant_ and val() for _non-constant_ handlingCreates a CDS QLLiteral
to be used in queries.- Type Parameters:
T
- the type of the literal- Parameters:
value
- the value of the literal- Returns:
- the literal
-
constant
static <T> Literal<T> constant(T value)
Creates a _constant_ CDS QLLiteral
hinting to the runtime that the value should be treated as constant.- Type Parameters:
T
- the type of the constant- Parameters:
value
- the value of the constant- Returns:
- the literal
-
val
static <T> Literal<T> val(T value)
Creates a _non-constant_ CDS QLLiteral
hinting to the runtime that the value should not be treated as constant.- Type Parameters:
T
- the type of the non-constant value- Parameters:
value
- the value of the non-constant value- Returns:
- the literal
- See Also:
param()
-
not
static Predicate not(CqnPredicate predicate)
Negates a givenCqnPredicate
.- Parameters:
predicate
- theCqnPredicate
to be negated- Returns:
- the negated predicate
-
and
static Predicate and(CqnPredicate p1, CqnPredicate p2)
Creates a conjunction of two given predicates- Parameters:
p1
- 1st operand of the conjunctionp2
- 2nd operand of the conjunction- Returns:
- the conjunction
-
withAnd
static Collector<CqnPredicate,?,CqnPredicate> withAnd()
Returns aCollector
that connects the input predicates with AND. If there are none theCollector
returns TRUE.- Returns:
- the collector
-
or
static Predicate or(CqnPredicate p1, CqnPredicate p2)
Creates a disjunction of two given predicates- Parameters:
p1
- 1st operand of the disjunctionp2
- 2nd operand of the disjunction- Returns:
- the disjunction
-
and
static Predicate and(Iterable<? extends CqnPredicate> predicates)
Creates a conjunction of given predicates- Parameters:
predicates
- the predicates to connect- Returns:
- the conjunction
-
or
static Predicate or(Iterable<? extends CqnPredicate> predicates)
Creates a disjunction of given predicates- Parameters:
predicates
- the predicates to connect- Returns:
- the disjunction
-
withOr
static Collector<CqnPredicate,?,CqnPredicate> withOr()
Returns aCollector
that connects the input predicates with OR. If there are none theCollector
returns FALSE.- Returns:
- the collector
-
connect
static Predicate connect(CqnConnectivePredicate.Operator operator, Iterable<? extends CqnPredicate> predicates)
Creates a logical connection of given predicatesCqnPredicate
.- Parameters:
operator
- operator to connect the predicates withpredicates
- the predicates to connect- Returns:
- the logical connection
-
param
@Deprecated static <T> Parameter<T> param()
Creates a positionalParameter
to be used in queries.- Type Parameters:
T
- the type of the parameter- Returns:
- the parameter
-
param
static <T> Parameter<T> param(int index)
Creates an indexedParameter
to be used in CQN statements. Can be used with positional parameter values.- Type Parameters:
T
- the type of the parameter- Parameters:
index
- the parameter index. If used with positional parameter values, start with 0 for the first parameter- Returns:
- the parameter
-
param
static <T> Parameter<T> param(String name)
Creates a namedParameter
to be used in queries.- Type Parameters:
T
- the type of the parameter- Parameters:
name
- the parameter name- Returns:
- the parameter
-
plain
static Value<?> plain(String value)
Creates a CQN plain value, which is directly send to the underlying data store.- Parameters:
value
- the value content- Returns:
- the plain value
-
count
static Value<Long> count(CqnElementRef element)
Creates a count function call on the given element.- Parameters:
element
- the ref to the element to be counted- Returns:
- the count value
-
min
static <T> Value<T> min(CqnValue value)
Creates a min function call on the given element or expression.- Type Parameters:
T
- the type of the value- Parameters:
value
- the ref to the element to be counted or an expression- Returns:
- the minimum value
-
max
static <T> Value<T> max(CqnValue value)
Creates a max function call on the given element or expression.- Type Parameters:
T
- the type of the value- Parameters:
value
- the ref to the element to be counted or an expression- Returns:
- the maximum value
-
sum
static Value<Number> sum(CqnValue value)
Creates a sum function call on the given element or expression.- Parameters:
value
- the ref to the element to be counted or an expression- Returns:
- the sum value
-
average
static Value<Number> average(CqnValue value)
Creates an average function call on the given element or expression.- Parameters:
value
- the ref to the element to be counted or an expression- Returns:
- the average value
-
countDistinct
static Value<Long> countDistinct(CqnValue value)
Creates an count distinct function call on the given element or expression.- Parameters:
value
- the ref to the element to be counted or an expression- Returns:
- the count of distinct values
-
contains
static Predicate contains(CqnValue value, CqnValue substring, boolean caseInsensitive)
Creates a predicate that tests whether a string value contains a given substring- Parameters:
value
- the string valuesubstring
- the substring to test forcaseInsensitive
- whether the test should be case insensitive- Returns:
- the predicate for the containment test
-
startsWith
static Predicate startsWith(CqnValue value, CqnValue prefix, boolean caseInsensitive)
Creates a predicate that tests whether a string value starts with a given prefix- Parameters:
value
- the string valueprefix
- the prefix to test forcaseInsensitive
- whether the test should be case insensitive- Returns:
- the predicate for the containment test
-
endsWith
static Predicate endsWith(CqnValue value, CqnValue suffix, boolean caseInsensitive)
Creates a predicate that tests whether a string value ends with a given suffix- Parameters:
value
- the string valuesuffix
- the suffix to test forcaseInsensitive
- whether the test should be case insensitive- Returns:
- the predicate for the containment test
-
containment
static Predicate containment(CqnContainmentTest.Position position, CqnValue value, CqnValue substring, boolean caseInsensitive)
Creates a predicate that tests whether a string value contains a given substring at a given positionCqnContainmentTest.Position
- Parameters:
position
- the positionvalue
- the string valuesubstring
- the substring to test forcaseInsensitive
- whether the test should be case insensitive- Returns:
- the predicate for the containment test
-
toLower
static Value<String> toLower(Value<String> val)
Creates a CDS QL expression for converting the given string value to lower case using the rules of the underlying data store.- Parameters:
val
- the String value to be converted- Returns:
- the CDS QL expression for lower case conversion
-
toLower
static Value<String> toLower(String val)
Creates a CDS QL expression for converting the given string value to lower case using the rules of the underlying data store.- Parameters:
val
- the String value to be converted- Returns:
- the CDS QL expression for lower case conversion
-
toUpper
static Value<String> toUpper(Value<String> val)
Creates a CDS QL expression for converting the given string value to upper case using the rules of the underlying data store.- Parameters:
val
- the String value to be converted- Returns:
- the CDS QL expression for upper case conversion
-
toUpper
static Value<String> toUpper(String val)
Creates a CDS QL expression for converting the given string value to upper case using the rules of the underlying data store.- Parameters:
val
- the String value to be converted- Returns:
- the CDS QL expression for upper case conversion
-
entity
static StructuredType<?> entity(String qualifiedName)
Creates aStructuredType
representing a CDS entity.- Parameters:
qualifiedName
- the qualified name of the CDS entity- Returns:
- the
StructuredType
representing the CDS entity
-
to
static StructuredType<?> to(String path)
Creates aStructuredType
representing a path from a CDS entity to another entity.- Parameters:
path
- a String of association element names separated by '.'- Returns:
- the
StructuredType
representing the path to a CDS entity
-
to
static StructuredType<?> to(List<? extends CqnReference.Segment> segments)
Creates aStructuredType
representing a path from a CDS entity to another entity.- Parameters:
segments
- the segments of the path- Returns:
- the
StructuredType
representing the path to a CDS entity
-
get
static <T> ElementRef<T> get(String path)
Creates anElementRef
representing a path from a CDS entity to an element of this or another entity.- Type Parameters:
T
- the type of the element- Parameters:
path
- a String of element names separated by '.', where all except the last segment represent association elements.- Returns:
- the
ElementRef
representing the path to the CDS element
-
get
static <T> ElementRef<T> get(List<? extends CqnReference.Segment> segments)
Creates anElementRef
representing a path from a CDS entity to an element of this or another entity.- Type Parameters:
T
- the type of the element- Parameters:
segments
- the segments of the path- Returns:
- the
ElementRef
representing the path to the CDS element
-
refSegment
static RefSegment refSegment(String id)
Creates a segment of a structured type or element reference.- Parameters:
id
- the id of the segment- Returns:
- the segment
-
refSegments
static List<RefSegment> refSegments(List<String> segmentIds)
Creates a list of reference segments.- Parameters:
segmentIds
- the ids of the segments- Returns:
- the segments
-
expression
static Value<Number> expression(CqnValue left, CqnArithmeticExpression.Operator op, CqnValue right)
Creates an arithmetic expression.- Parameters:
left
- the left-hand side of the expressionop
- the operatorright
- the right-hand side of the expression- Returns:
- the arithmetic expression
-
comparison
static Predicate comparison(CqnValue lhs, CqnComparisonPredicate.Operator op, CqnValue rhs)
Creates a comparison predicate.- Parameters:
lhs
- the left-hand side of the comparisonop
- the comparison operatorrhs
- the right-hand side of the comparison- Returns:
- the comparison predicate
-
in
static Predicate in(CqnValue lhs, Collection<? extends CqnValue> values)
Creates an in predicate.- Parameters:
lhs
- the value to be checked if it's contained in the collectionvalues
- the collection of values- Returns:
- the in predicate
-
in
static Predicate in(CqnValue lhs, CqnValue valueSet)
Creates an in predicate.- Parameters:
lhs
- the value to be checked if it's contained in the collectionvalueSet
- the value describing a collection of values- Returns:
- the in predicate
-
search
static Predicate search(String term)
Creates a search predicate.- Parameters:
term
- the search term- Returns:
- the search predicate
-
exists
static Predicate exists(CqnSelect subQuery)
Creates an exists predicate that tests if a given subquery returns any row- Parameters:
subQuery
- the subquery that performs the existence test- Returns:
- the exists predicate
-
match
static Predicate match(StructuredTypeRef ref, Predicate pred, CqnMatchPredicate.Quantifier quantifier)
Creates a match predicate that tests if a given ref matches a given filter- Parameters:
ref
- the referencepred
- the filterquantifier
- all or any- Returns:
- the match predicate
-
now
static Value<Instant> now()
Creates anElementRef
to be used in queries to represent $now.- Returns:
- the now value
-
validFrom
static Value<Instant> validFrom()
Creates anElementRef
on the available $validFrom value.- Returns:
- the validFrom value
-
validTo
static Value<Instant> validTo()
Creates anElementRef
on the available $validTo value.- Returns:
- the validTo value
-
userLocale
static Value<String> userLocale()
Creates anElementRef
on the available $user.locale value.- Returns:
- the locale string value
-
userId
static Value<String> userId()
Creates anElementRef
on the available $user.id value.- Returns:
- the user.id value
-
star
static CqnStar star()
-
list
static CqnToken list(List<? extends CqnValue> values)
Creates aCqnListValue
composing given values- Parameters:
values
- the components- Returns:
- the list value
-
matching
static Predicate matching(Map<String,?> elementToValueMap)
Creates a predicate from a map of element names to values or parameters. The map entries are transformed into equality predicates and joined via and.- Parameters:
elementToValueMap
- the element name to value map defining the condition- Returns:
- the matching predicate
-
sort
static CqnSortSpecification sort(CqnValue value, CqnSortSpecification.Order order)
Creates aCqnSortSpecification
that sorts a value by a given order- Parameters:
value
- the valueorder
- the order- Returns:
- the sort specification
-
-