Class ODataEntityKey

java.lang.Object
com.sap.cloud.sdk.datamodel.odata.client.request.AbstractODataParameters
com.sap.cloud.sdk.datamodel.odata.client.request.ODataEntityKey

public class ODataEntityKey extends AbstractODataParameters
Fluent API class to build and hold entity keys. A key is comprised of one or multiple individual key-value pairs.
  • Constructor Details

    • ODataEntityKey

      public ODataEntityKey(@Nonnull ODataProtocol protocol)
      Create a new, empty entity key for the given protocol version.
      Parameters:
      protocol - The ODataProtocol version this key should conform to.
  • Method Details

    • getFieldNames

      @Nonnull public Set<String> getFieldNames()
      Get all field names that are part of this key.
      Returns:
      A set of entity property field names.
    • addKeyProperty

      @Nonnull public <PrimitiveT> ODataEntityKey addKeyProperty(@Nonnull String propertyName, @Nullable PrimitiveT value)
      Add an entity property to this key.
      Type Parameters:
      PrimitiveT - Type of the primitive value.
      Parameters:
      propertyName - Name of the property (derived from the EDMX)
      value - Property value, assumed to be a primitive.
      Returns:
      The modified instance.
      Throws:
      IllegalArgumentException - When a parameter by that idenfitier already exists or primitive type is not supported.
    • addKeyProperties

      @Nonnull public ODataEntityKey addKeyProperties(@Nonnull Map<String,Object> properties)
      Add properties to the OData entity key.
      Parameters:
      properties - The key-value mapping.
      Returns:
      The same instance.
      Throws:
      IllegalArgumentException - When the map contains a primitive type that is not supported.
      See Also:
    • of

      @Nonnull public static ODataEntityKey of(@Nonnull Map<String,Object> key, @Nonnull ODataProtocol protocol)
      Create an instance of ODataEntityKey from a generic key-value composition.
      Parameters:
      key - Key-value pairs of entity properties and their values.
      protocol - The ODataProtocol version this key should conform to.
      Returns:
      A new instance of ODataEntityKey.
      Throws:
      IllegalArgumentException - When the map contains a primitive type that is not supported.
      See Also:
    • toEncodedString

      @Nonnull public String toEncodedString(@Nonnull UriEncodingStrategy strategy)
      Description copied from class: AbstractODataParameters
      Serializes all parameters into an encoded URL path segment. The format is as follows:

      • An empty set of parameters will yield ()
      • A single parameter entry will yield (value)
      • Multiple of parameters will yield (key1=val,key2=val)

      Overrides:
      toEncodedString in class AbstractODataParameters
      Parameters:
      strategy - The URI encoding strategy.
      Returns:
      Encoded URL string representation of the parameters.
    • toString

      @Nonnull public String toString()
      Serializes the entity key into an unencoded OData URL format for entity keys.
      Overrides:
      toString in class AbstractODataParameters
      Returns:
      Encoded URL string representation of entity key.