java.lang.Object
software.amazon.awssdk.enhanced.dynamodb.Key

@ThreadSafe public final class Key extends Object
An object that represents a key that can be used to either identify a specific record or form part of a query conditional. Keys are literal and hence not typed, and can be re-used in commands for different modelled types if the literal values are to be the same.

A key will always have a single partition key value associated with it, and optionally will have a sort key value. The names of the keys themselves are not part of this object.

  • Method Details

    • builder

      public static Key.Builder builder()
      Returns a new builder that can be used to construct an instance of this class.
      Returns:
      A newly initialized Key.Builder object.
    • keyMap

      public Map<String,AttributeValue> keyMap(TableSchema<?> tableSchema, String index)
      Return a map of the key elements that can be passed directly to DynamoDb.
      Parameters:
      tableSchema - A tableschema to determine the key attribute names from.
      index - The name of the index to use when determining the key attribute names.
      Returns:
      A map of attribute names to AttributeValue.
    • partitionKeyValue

      public AttributeValue partitionKeyValue()
      Get the literal value of the partition key stored in this object.
      Returns:
      An AttributeValue representing the literal value of the partition key.
    • sortKeyValue

      public Optional<AttributeValue> sortKeyValue()
      Get the literal value of the sort key stored in this object if available.
      Returns:
      An optional AttributeValue representing the literal value of the sort key, or empty if there is no sort key value in this Key.
    • primaryKeyMap

      public Map<String,AttributeValue> primaryKeyMap(TableSchema<?> tableSchema)
      Return a map of the key elements that form the primary key of a table that can be passed directly to DynamoDb.
      Parameters:
      tableSchema - A tableschema to determine the key attribute names from.
      Returns:
      A map of attribute names to AttributeValue.
    • toBuilder

      public Key.Builder toBuilder()
      Converts an existing key into a builder object that can be used to modify its values and then create a new key.
      Returns:
      A Key.Builder initialized with the values of this key.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object