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 th
      Returns:
      This query object with the added selections.
    • filter

      @Nonnull public StructuredQuery filter(@Nonnull ValueBoolean... filters)
    • top

      @Nonnull public StructuredQuery top(@Nonnull Number top)
    • skip

      @Nonnull public StructuredQuery skip(@Nonnull Number skip)
    • orderBy

      @Nonnull public StructuredQuery orderBy(@Nonnull String field, @Nonnull Order order)
    • orderBy

      @Nonnull public StructuredQuery orderBy(@Nonnull OrderExpression ordering)
    • search

      @Nonnull public StructuredQuery search(@Nonnull String search)
    • 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()