Class StructuredQuery
java.lang.Object
com.sap.cloud.sdk.datamodel.odata.client.query.StructuredQuery
- All Implemented Interfaces:
QuerySerializable
StructuredQuery
acts as a builder for OData 2.0 or 4.0 queries. It assists with assembling request parameters
such as $select, $filter, ...
. This API does not differentiate between OData versions. Only leveraging
features e.g. within filters that conform to the selected protocol version is the responsibility of the consumer.-
Method Summary
Modifier and TypeMethodDescriptionstatic StructuredQuery
asNestedQueryOnProperty
(String fieldName, ODataProtocol protocol) Create a nested query on a property.filter
(ValueBoolean... filters) Query modified to limit which entities should be contained in the result set.Compute the encoded string representation of this query.The structured property field name.Compute the string representation of this query.getSkip()
getTop()
boolean
isRoot()
static StructuredQuery
onEntity
(String entityName, ODataProtocol protocol) Create aStructuredQuery
for building up OData 2.0 or 4.0 queries.orderBy
(OrderExpression ordering) Sets theorderBy
operation for this query object, overwriting any existingorderBy
operations.Adds anorderBy
expression to this query object.Sets thesearch
operation for this query object.select
(StructuredQuery... subqueries) Query modifier to limit which complex and navigational properties will be expanded (and thus selected).Query modifier to limit which field values of the entity get fetched and populated.Query modifier to skip a certain amount of results before then adding entities.Query modifier to limit how many entities should be contained in the result set.withCustomParameter
(String key, String value) Adds a custom query parameter in the form of a key=value pair.Requests an inline count by adding the system query option$inlinecount
(OData V2) or$count
(OData V4).
-
Method Details
-
onEntity
@Nonnull public static StructuredQuery onEntity(@Nonnull String entityName, @Nonnull ODataProtocol protocol) Create aStructuredQuery
for building up OData 2.0 or 4.0 queries.- Parameters:
entityName
- The entity collection to be queried.protocol
- TheODataProtocol
version this query should conform to.- Returns:
- A new
StructuredQuery
object.
-
asNestedQueryOnProperty
@Nonnull public static StructuredQuery asNestedQueryOnProperty(@Nonnull String fieldName, @Nonnull ODataProtocol protocol) Create a nested query on a property. This is an OData 4.0 specific feature.- Parameters:
fieldName
- The property that is to be queried.protocol
- TheODataProtocol
version this query should conform to.- Returns:
- A new
StructuredQuery
object.
-
select
Query modifier to limit which field values of the entity get fetched and populated.- Parameters:
fields
- Properties to be selected.- Returns:
- This query object with the added selections.
-
select
Query modifier to limit which complex and navigational properties will be expanded (and thus selected). Such expansions are represented again through structured queries.- Parameters:
subqueries
- Query objects on properties to be expanded. ThegetEntityOrPropertyName()
will be the key for fields that should be expanded.- Returns:
- This query object with the added selections.
-
filter
Query modified to limit which entities should be contained in the result set.- Parameters:
filters
- Filter objects on properties to be filtered.- Returns:
- This query object with the added filters.
-
top
Query modifier to limit how many entities should be contained in the result set.- Parameters:
top
- The number of entities to include in the result set at most.- Returns:
- This query object with the top limit included.
-
skip
Query modifier to skip a certain amount of results before then adding entities.- Parameters:
skip
- The number of entities that shall be skipped before actually filling the result set.- Returns:
- This query object with the skip operation included.
-
orderBy
Adds anorderBy
expression to this query object.If there is no
orderBy
operation present yet, a new one will be created.- Parameters:
field
- The name of the field that should for ordering the result set.order
- TheOrder
.- Returns:
- This query object with the order by operation added.
-
orderBy
Sets theorderBy
operation for this query object, overwriting any existingorderBy
operations.- Parameters:
ordering
- TheOrderExpression
to be used.- Returns:
- This query object with the given
ordering
set.
-
search
Sets thesearch
operation for this query object.- Parameters:
search
- The value to be searched for.- Returns:
- This query object with the
search
operation set.
-
withCustomParameter
Adds a custom query parameter in the form of a key=value pair. This will not override any parameters set viaselect
,filter
etc.- Parameters:
key
- The parameter key. Must not be null or empty.value
- The parameter value.- Returns:
- This query object with the added parameter
- Throws:
IllegalArgumentException
- if the key is null or emptyIllegalStateException
- if this query object is a nested query
-
withInlineCount
Requests an inline count by adding the system query option$inlinecount
(OData V2) or$count
(OData V4).- Returns:
- This query object with the added parameter
-
getEncodedQueryString
Description copied from interface:QuerySerializable
Compute the encoded string representation of this query. All characters except the ones listed inODataUriFactory#SAFE_CHARS_IN_QUERY
are encoded- Specified by:
getEncodedQueryString
in interfaceQuerySerializable
- Returns:
- A string representing the encoded request query.
-
getQueryString
Description copied from interface:QuerySerializable
Compute the string representation of this query.- Specified by:
getQueryString
in interfaceQuerySerializable
- Returns:
- A string representing the request query.
-
getEntityOrPropertyName
The structured property field name. -
isRoot
public boolean isRoot() -
getProtocol
-
getSimpleSelectors
-
getComplexSelectors
-
getFilters
-
getCustomParameters
-
getOrderBy
-
getTop
-
getSkip
-
getSearch
-