Class DefaultEnhancedDocument
- java.lang.Object
-
- software.amazon.awssdk.enhanced.dynamodb.internal.document.DefaultEnhancedDocument
-
- All Implemented Interfaces:
EnhancedDocument
@Immutable public class DefaultEnhancedDocument extends Object implements EnhancedDocument
Default implementation ofEnhancedDocument
used by the SDK to create Enhanced Documents. Attributes are initially saved as a String-Object Map when documents are created using the builder. Conversion to an AttributeValueMap is done lazily when values are accessed. When the document is retrieved from DynamoDB, the AttributeValueMap is internally saved as the attribute value map. Custom objects or collections are saved in the enhancedTypeMap to preserve the generic class information. Note that no default ConverterProviders are assigned, so ConverterProviders must be passed in the builder when creating enhanced documents.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
DefaultEnhancedDocument.DefaultBuilder
-
Nested classes/interfaces inherited from interface software.amazon.awssdk.enhanced.dynamodb.document.EnhancedDocument
EnhancedDocument.Builder
-
-
Constructor Summary
Constructors Constructor Description DefaultEnhancedDocument(DefaultEnhancedDocument.DefaultBuilder builder)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description List<AttributeConverterProvider>
attributeConverterProviders()
static EnhancedDocument.Builder
builder()
Creates a default builder forEnhancedDocument
.static <T> AttributeConverter<T>
converterForClass(EnhancedType<T> type, ChainConverterProvider chainConverterProvider)
boolean
equals(Object o)
<T> T
get(String attributeName, Class<T> clazz)
Returns the value of the specified attribute in the current document as a specified class type; or null if the attribute either doesn't exist or the attribute value is null.<T> T
get(String attributeName, EnhancedType<T> type)
Returns the value of the specified attribute in the current document as a specifiedEnhancedType
; or null if the attribute either doesn't exist or the attribute value is null.Boolean
getBoolean(String attributeName)
Gets theBoolean
value for the specified attribute.SdkBytes
getBytes(String attributeName)
Gets theSdkBytes
value of specified attribute in the document.Set<SdkBytes>
getBytesSet(String attributeName)
Gets the Set of String values of the given attribute in the current document.String
getJson(String attributeName)
Gets the JSON document value of the specified attribute.<T> List<T>
getList(String attributeName, EnhancedType<T> type)
Gets the List of values of type T for the given attribute in the current document.List<AttributeValue>
getListOfUnknownType(String attributeName)
Retrieves a list ofAttributeValue
objects for a specified attribute in a document.<K,V>
Map<K,V>getMap(String attributeName, EnhancedType<K> keyType, EnhancedType<V> valueType)
Returns a map of a specific Key-type and Value-type based on the given attribute name, key type, and value type.Map<String,AttributeValue>
getMapOfUnknownType(String attributeName)
Retrieves a Map with String keys and corresponding AttributeValue objects as values for a specified attribute in a document.SdkNumber
getNumber(String attributeName)
Gets theSdkNumber
value of specified attribute in the document.Set<SdkNumber>
getNumberSet(String attributeName)
Gets the Set of String values of the given attribute in the current document.String
getString(String attributeName)
Gets the String value of specified attribute in the document.Set<String>
getStringSet(String attributeName)
Gets the Set of String values of the given attribute in the current document.int
hashCode()
boolean
isNull(String attributeName)
Checks if the document is anull
value.boolean
isPresent(String attributeName)
Checks if the attribute exists in the document.EnhancedDocument.Builder
toBuilder()
Converts an existing EnhancedDocument into a builder object that can be used to modify its values and then create a new EnhancedDocument.String
toJson()
Map<String,AttributeValue>
toMap()
This method converts a document into a key-value map with the keys as String objects and the values as AttributeValue objects.
-
-
-
Constructor Detail
-
DefaultEnhancedDocument
public DefaultEnhancedDocument(DefaultEnhancedDocument.DefaultBuilder builder)
-
-
Method Detail
-
builder
public static EnhancedDocument.Builder builder()
Description copied from interface:EnhancedDocument
Creates a default builder forEnhancedDocument
.
-
converterForClass
public static <T> AttributeConverter<T> converterForClass(EnhancedType<T> type, ChainConverterProvider chainConverterProvider)
-
toBuilder
public EnhancedDocument.Builder toBuilder()
Description copied from interface:EnhancedDocument
Converts an existing EnhancedDocument into a builder object that can be used to modify its values and then create a new EnhancedDocument.- Specified by:
toBuilder
in interfaceEnhancedDocument
- Returns:
- A
EnhancedDocument.Builder
initialized with the values of this EnhancedDocument.
-
attributeConverterProviders
public List<AttributeConverterProvider> attributeConverterProviders()
- Specified by:
attributeConverterProviders
in interfaceEnhancedDocument
- Returns:
- List of AttributeConverterProvider defined for the given Document.
-
isNull
public boolean isNull(String attributeName)
Description copied from interface:EnhancedDocument
Checks if the document is anull
value.- Specified by:
isNull
in interfaceEnhancedDocument
- Parameters:
attributeName
- Name of the attribute that needs to be checked.- Returns:
- true if the specified attribute exists with a null value; false otherwise.
-
isPresent
public boolean isPresent(String attributeName)
Description copied from interface:EnhancedDocument
Checks if the attribute exists in the document.- Specified by:
isPresent
in interfaceEnhancedDocument
- Parameters:
attributeName
- Name of the attribute that needs to be checked.- Returns:
- true if the specified attribute exists with a null/non-null value; false otherwise.
-
get
public <T> T get(String attributeName, EnhancedType<T> type)
Description copied from interface:EnhancedDocument
Returns the value of the specified attribute in the current document as a specifiedEnhancedType
; or null if the attribute either doesn't exist or the attribute value is null.Retrieving String Type for a document Retrieving Custom Type for which Convertor Provider was defined while creating the document Retrieving list of strings in a document Retrieving a Map with List of strings in its values
- Specified by:
get
in interfaceEnhancedDocument
- Type Parameters:
T
- The type of the attribute value.- Parameters:
attributeName
- Name of the attribute.type
- EnhancedType of the value- Returns:
- Attribute value of type T }
-
getString
public String getString(String attributeName)
Description copied from interface:EnhancedDocument
Gets the String value of specified attribute in the document.- Specified by:
getString
in interfaceEnhancedDocument
- Parameters:
attributeName
- Name of the attribute.- Returns:
- value of the specified attribute in the current document as a string; or null if the attribute either doesn't exist or the attribute value is null
-
getNumber
public SdkNumber getNumber(String attributeName)
Description copied from interface:EnhancedDocument
Gets theSdkNumber
value of specified attribute in the document.- Specified by:
getNumber
in interfaceEnhancedDocument
- Parameters:
attributeName
- Name of the attribute.- Returns:
- value of the specified attribute in the current document as a number; or null if the attribute either doesn't exist or the attribute value is null
-
get
public <T> T get(String attributeName, Class<T> clazz)
Description copied from interface:EnhancedDocument
Returns the value of the specified attribute in the current document as a specified class type; or null if the attribute either doesn't exist or the attribute value is null.Retrieving String Type for a document Retrieving Custom Type for which Convertor Provider was defined while creating the document
Note : This API should not be used to retrieve values of List and Map types. Instead, getList and getMap APIs should be used to retrieve attributes of type List and Map, respectively.
- Specified by:
get
in interfaceEnhancedDocument
- Type Parameters:
T
- The type of the attribute value.- Parameters:
attributeName
- Name of the attribute.clazz
- Class type of value.- Returns:
- Attribute value of type T }
-
getBytes
public SdkBytes getBytes(String attributeName)
Description copied from interface:EnhancedDocument
Gets theSdkBytes
value of specified attribute in the document.- Specified by:
getBytes
in interfaceEnhancedDocument
- Parameters:
attributeName
- Name of the attribute.- Returns:
- the value of the specified attribute in the current document as SdkBytes; or null if the attribute either doesn't exist or the attribute value is null.
-
getStringSet
public Set<String> getStringSet(String attributeName)
Description copied from interface:EnhancedDocument
Gets the Set of String values of the given attribute in the current document.- Specified by:
getStringSet
in interfaceEnhancedDocument
- Parameters:
attributeName
- the name of the attribute.- Returns:
- the value of the specified attribute in the current document as a set of strings; or null if the attribute either does not exist or the attribute value is null.
-
getNumberSet
public Set<SdkNumber> getNumberSet(String attributeName)
Description copied from interface:EnhancedDocument
Gets the Set of String values of the given attribute in the current document.- Specified by:
getNumberSet
in interfaceEnhancedDocument
- Parameters:
attributeName
- Name of the attribute.- Returns:
- value of the specified attribute in the current document as a set of SdkNumber; or null if the attribute either doesn't exist or the attribute value is null.
-
getBytesSet
public Set<SdkBytes> getBytesSet(String attributeName)
Description copied from interface:EnhancedDocument
Gets the Set of String values of the given attribute in the current document.- Specified by:
getBytesSet
in interfaceEnhancedDocument
- Parameters:
attributeName
- Name of the attribute.- Returns:
- value of the specified attribute in the current document as a set of SdkBytes; or null if the attribute doesn't exist.
-
getList
public <T> List<T> getList(String attributeName, EnhancedType<T> type)
Description copied from interface:EnhancedDocument
Gets the List of values of type T for the given attribute in the current document.- Specified by:
getList
in interfaceEnhancedDocument
- Type Parameters:
T
- Type T of List elements- Parameters:
attributeName
- Name of the attribute.type
-EnhancedType
of Type T.- Returns:
- value of the specified attribute in the current document as a list of type T, or null if the attribute does not exist.
-
getMap
public <K,V> Map<K,V> getMap(String attributeName, EnhancedType<K> keyType, EnhancedType<V> valueType)
Description copied from interface:EnhancedDocument
Returns a map of a specific Key-type and Value-type based on the given attribute name, key type, and value type. Example usage: When getting an attribute as a map ofUUID
keys andInteger
values, use this API as shown below:- Specified by:
getMap
in interfaceEnhancedDocument
- Type Parameters:
K
- The type of the Map keys.V
- The type of the Map values.- Parameters:
attributeName
- The name of the attribute that needs to be get as Map.keyType
- Enhanced Type of Key attribute, like String, UUID etc that can be represented as String Keys.valueType
- Enhanced Type of Values , which have converters defineds inEnhancedDocument.Builder.attributeConverterProviders(AttributeConverterProvider...)
for the document- Returns:
- Map of type K and V with the given attribute name, key type, and value type.
-
getJson
public String getJson(String attributeName)
Description copied from interface:EnhancedDocument
Gets the JSON document value of the specified attribute.- Specified by:
getJson
in interfaceEnhancedDocument
- Parameters:
attributeName
- Name of the attribute.- Returns:
- value of the specified attribute in the current document as a JSON string; or null if the attribute either doesn't exist or the attribute value is null.
-
getBoolean
public Boolean getBoolean(String attributeName)
Description copied from interface:EnhancedDocument
Gets theBoolean
value for the specified attribute.- Specified by:
getBoolean
in interfaceEnhancedDocument
- Parameters:
attributeName
- Name of the attribute.- Returns:
- value of the specified attribute in the current document as a Boolean representation; or null if the attribute either doesn't exist or the attribute value is null.
-
getListOfUnknownType
public List<AttributeValue> getListOfUnknownType(String attributeName)
Description copied from interface:EnhancedDocument
Retrieves a list ofAttributeValue
objects for a specified attribute in a document. This API should be used when the elements of the list are a combination of different types such as Strings, Maps, and Numbers. If all elements in the list are of a known fixed type, useEnhancedDocument.getList(String, EnhancedType)
instead.- Specified by:
getListOfUnknownType
in interfaceEnhancedDocument
- Parameters:
attributeName
- Name of the attribute.- Returns:
- value of the specified attribute in the current document as a List of
AttributeValue
-
getMapOfUnknownType
public Map<String,AttributeValue> getMapOfUnknownType(String attributeName)
Description copied from interface:EnhancedDocument
Retrieves a Map with String keys and corresponding AttributeValue objects as values for a specified attribute in a document. This API is particularly useful when the values of the map are of different types such as strings, maps, and numbers. However, if all the values in the map for a given attribute key are of a known fixed type, it is recommended to use the method EnhancedDocument#getMap(String, EnhancedType, EnhancedType) instead.- Specified by:
getMapOfUnknownType
in interfaceEnhancedDocument
- Parameters:
attributeName
- Name of the attribute.- Returns:
- value of the specified attribute in the current document as a
AttributeValue
-
toJson
public String toJson()
- Specified by:
toJson
in interfaceEnhancedDocument
- Returns:
- document as a JSON string. Note all binary data will become base-64 encoded in the resultant string.
-
toMap
public Map<String,AttributeValue> toMap()
Description copied from interface:EnhancedDocument
This method converts a document into a key-value map with the keys as String objects and the values as AttributeValue objects. It can be particularly useful for documents with attributes of unknown types, as it allows for further processing or manipulation of the document data in a AttributeValue format.- Specified by:
toMap
in interfaceEnhancedDocument
- Returns:
- Document as a String AttributeValue Key-Value Map
-
-