Class Key
- java.lang.Object
-
- software.amazon.awssdk.enhanced.dynamodb.Key
-
@SdkPublicApi @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 partition key values associated with it, and optionally will have sort key values. Supports up to 4 partition keys and 4 sort keys. The names of the keys themselves are not part of this object.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classKey.BuilderBuilder forKey
-
Field Summary
Fields Modifier and Type Field Description static intMAX_KEYS
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Key.Builderbuilder()Returns a new builder that can be used to construct an instance of this class.booleanequals(Object o)inthashCode()Map<String,AttributeValue>keyMap(TableSchema<?> tableSchema, String index)Return a map of the key elements that can be passed directly to DynamoDb.AttributeValuepartitionKeyValue()Get the literal value of the single partition key stored in this object.List<AttributeValue>partitionKeyValues()Get the literal values of all composite partition keys stored in this object.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.Optional<AttributeValue>sortKeyValue()Get the literal value of the single sort key stored in this object if available.List<AttributeValue>sortKeyValues()Get the literal values of all composite sort keys stored in this object.Key.BuildertoBuilder()Converts an existing key into a builder object that can be used to modify its values and then create a new key.
-
-
-
Field Detail
-
MAX_KEYS
public static final int MAX_KEYS
- See Also:
- Constant Field Values
-
-
Method Detail
-
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.Builderobject.
-
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 table schema 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.
-
partitionKeyValues
public List<AttributeValue> partitionKeyValues()
Get the literal values of all composite partition keys stored in this object.- Returns:
- A list of
AttributeValuerepresenting the literal values of the partition keys.
-
sortKeyValues
public List<AttributeValue> sortKeyValues()
Get the literal values of all composite sort keys stored in this object.- Returns:
- A list of
AttributeValuerepresenting the literal values of the sort keys.
-
partitionKeyValue
public AttributeValue partitionKeyValue()
Get the literal value of the single partition key stored in this object.Use
partitionKeyValues()for composite key support- Returns:
- An
AttributeValuerepresenting the literal value of the first partition key.
-
sortKeyValue
public Optional<AttributeValue> sortKeyValue()
Get the literal value of the single sort key stored in this object if available.Use
sortKeyValues()for composite key support- Returns:
- An optional
AttributeValuerepresenting the literal value of the first 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 table schema 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.Builderinitialized with the values of this key.
-
-