@Immutable public class DefaultEnhancedDocument extends Object implements EnhancedDocument
EnhancedDocument
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.Modifier and Type | Class and Description |
---|---|
static class |
DefaultEnhancedDocument.DefaultBuilder |
EnhancedDocument.Builder
Constructor and Description |
---|
DefaultEnhancedDocument(DefaultEnhancedDocument.DefaultBuilder builder) |
Modifier and Type | Method and Description |
---|---|
List<AttributeConverterProvider> |
attributeConverterProviders() |
static EnhancedDocument.Builder |
builder()
Creates a default builder for
EnhancedDocument . |
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 specified
EnhancedType ; or null if the
attribute either doesn't exist or the attribute value is null. |
Boolean |
getBoolean(String attributeName)
Gets the
Boolean value for the specified attribute. |
SdkBytes |
getBytes(String attributeName)
Gets the
SdkBytes 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 of
AttributeValue 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 the
SdkNumber 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 a
null 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.
|
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
fromAttributeValueMap, fromJson
public DefaultEnhancedDocument(DefaultEnhancedDocument.DefaultBuilder builder)
public static EnhancedDocument.Builder builder()
EnhancedDocument
EnhancedDocument
.builder
in interface EnhancedDocument
public static <T> AttributeConverter<T> converterForClass(EnhancedType<T> type, ChainConverterProvider chainConverterProvider)
public EnhancedDocument.Builder toBuilder()
EnhancedDocument
toBuilder
in interface EnhancedDocument
EnhancedDocument.Builder
initialized with the values of this EnhancedDocument.public List<AttributeConverterProvider> attributeConverterProviders()
attributeConverterProviders
in interface EnhancedDocument
public boolean isNull(String attributeName)
EnhancedDocument
null
value.isNull
in interface EnhancedDocument
attributeName
- Name of the attribute that needs to be checked.public boolean isPresent(String attributeName)
EnhancedDocument
isPresent
in interface EnhancedDocument
attributeName
- Name of the attribute that needs to be checked.public <T> T get(String attributeName, EnhancedType<T> type)
EnhancedDocument
EnhancedType
; 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
get
in interface EnhancedDocument
T
- The type of the attribute value.attributeName
- Name of the attribute.type
- EnhancedType of the valuepublic String getString(String attributeName)
EnhancedDocument
getString
in interface EnhancedDocument
attributeName
- Name of the attribute.public SdkNumber getNumber(String attributeName)
EnhancedDocument
SdkNumber
value of specified attribute in the document.getNumber
in interface EnhancedDocument
attributeName
- Name of the attribute.public <T> T get(String attributeName, Class<T> clazz)
EnhancedDocument
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.
get
in interface EnhancedDocument
T
- The type of the attribute value.attributeName
- Name of the attribute.clazz
- Class type of value.public SdkBytes getBytes(String attributeName)
EnhancedDocument
SdkBytes
value of specified attribute in the document.getBytes
in interface EnhancedDocument
attributeName
- Name of the attribute.public Set<String> getStringSet(String attributeName)
EnhancedDocument
getStringSet
in interface EnhancedDocument
attributeName
- the name of the attribute.public Set<SdkNumber> getNumberSet(String attributeName)
EnhancedDocument
getNumberSet
in interface EnhancedDocument
attributeName
- Name of the attribute.public Set<SdkBytes> getBytesSet(String attributeName)
EnhancedDocument
getBytesSet
in interface EnhancedDocument
attributeName
- Name of the attribute.public <T> List<T> getList(String attributeName, EnhancedType<T> type)
EnhancedDocument
getList
in interface EnhancedDocument
T
- Type T of List elementsattributeName
- Name of the attribute.type
- EnhancedType
of Type T.public <K,V> Map<K,V> getMap(String attributeName, EnhancedType<K> keyType, EnhancedType<V> valueType)
EnhancedDocument
UUID
keys and Integer
values, use this API
as shown below:
getMap
in interface EnhancedDocument
K
- The type of the Map keys.V
- The type of the Map values.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 in
EnhancedDocument.Builder.attributeConverterProviders(AttributeConverterProvider...)
for the documentpublic String getJson(String attributeName)
EnhancedDocument
getJson
in interface EnhancedDocument
attributeName
- Name of the attribute.public Boolean getBoolean(String attributeName)
EnhancedDocument
Boolean
value for the specified attribute.getBoolean
in interface EnhancedDocument
attributeName
- Name of the attribute.public List<AttributeValue> getListOfUnknownType(String attributeName)
EnhancedDocument
AttributeValue
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, use EnhancedDocument.getList(String, EnhancedType)
instead.getListOfUnknownType
in interface EnhancedDocument
attributeName
- Name of the attribute.AttributeValue
public Map<String,AttributeValue> getMapOfUnknownType(String attributeName)
EnhancedDocument
getMapOfUnknownType
in interface EnhancedDocument
attributeName
- Name of the attribute.AttributeValue
public String toJson()
toJson
in interface EnhancedDocument
public Map<String,AttributeValue> toMap()
EnhancedDocument
toMap
in interface EnhancedDocument
Copyright © 2023. All rights reserved.