Class StructuredQuery

java.lang.Object
com.sap.cloud.sdk.datamodel.odata.client.query.StructuredQuery
All Implemented Interfaces:
QuerySerializable

public final class StructuredQuery extends Object implements 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 Details

    • onEntity

      @Nonnull public static StructuredQuery onEntity(@Nonnull String entityName, @Nonnull ODataProtocol protocol)
      Create a StructuredQuery for building up OData 2.0 or 4.0 queries.
      Parameters:
      entityName - The entity collection to be queried.
      protocol - The ODataProtocol 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 - The ODataProtocol version this query should conform to.
      Returns:
      A new StructuredQuery object.
    • select

      @Nonnull public StructuredQuery select(@Nonnull String... fields)
      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

      @Nonnull public StructuredQuery select(@Nonnull StructuredQuery... subqueries)
      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. The getEntityOrPropertyName() will be the key for fields that should be expanded.
      Returns:
      This query object with the added selections.
    • filter

      @Nonnull public StructuredQuery filter(@Nonnull ValueBoolean... filters)
      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

      @Nonnull public StructuredQuery top(@Nonnull Number 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

      @Nonnull public StructuredQuery skip(@Nonnull Number 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

      @Nonnull public StructuredQuery orderBy(@Nonnull String field, @Nonnull Order order)
      Adds an orderBy 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 - The Order.
      Returns:
      This query object with the order by operation added.
    • orderBy

      @Nonnull public StructuredQuery orderBy(@Nonnull OrderExpression ordering)
      Sets the orderBy operation for this query object, overwriting any existing orderBy operations.
      Parameters:
      ordering - The OrderExpression to be used.
      Returns:
      This query object with the given ordering set.
    • search

      @Nonnull public StructuredQuery search(@Nonnull String search)
      Sets the search operation for this query object.
      Parameters:
      search - The value to be searched for.
      Returns:
      This query object with the search operation set.
    • withCustomParameter

      @Nonnull public StructuredQuery withCustomParameter(@Nonnull String key, @Nullable String value)
      Adds a custom query parameter in the form of a key=value pair. This will not override any parameters set via select, 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 empty
      IllegalStateException - if this query object is a nested query
    • withInlineCount

      @Nonnull public StructuredQuery 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

      @Nonnull public String getEncodedQueryString()
      Description copied from interface: QuerySerializable
      Compute the encoded string representation of this query. All characters except the ones listed in ODataUriFactory#SAFE_CHARS_IN_QUERY are encoded
      Specified by:
      getEncodedQueryString in interface QuerySerializable
      Returns:
      A string representing the encoded request query.
    • getQueryString

      @Nonnull public String getQueryString()
      Description copied from interface: QuerySerializable
      Compute the string representation of this query.
      Specified by:
      getQueryString in interface QuerySerializable
      Returns:
      A string representing the request query.
    • getEntityOrPropertyName

      @Nonnull public String getEntityOrPropertyName()
      The structured property field name.
    • isRoot

      public boolean isRoot()
    • getProtocol

      public ODataProtocol getProtocol()
    • getSimpleSelectors

      @Nonnull public Collection<String> getSimpleSelectors()
    • getComplexSelectors

      @Nonnull public Collection<StructuredQuery> getComplexSelectors()
    • getFilters

      @Nonnull public Collection<ValueBoolean> getFilters()
    • getCustomParameters

      @Nonnull public Map<String,String> getCustomParameters()
    • getOrderBy

      @Nullable public OrderExpression getOrderBy()
    • getTop

      @Nullable public Number getTop()
    • getSkip

      @Nullable public Number getSkip()
    • getSearch

      @Nullable public String getSearch()