Class DocumentTableSchema
- java.lang.Object
-
- software.amazon.awssdk.enhanced.dynamodb.document.DocumentTableSchema
-
- All Implemented Interfaces:
TableSchema<EnhancedDocument>
public final class DocumentTableSchema extends Object implements TableSchema<EnhancedDocument>
Implementation ofTableSchemathat builds a table schema based on DynamoDB Items.In Amazon DynamoDB, an item is a collection of attributes. Each attribute has a name and a value. An attribute value can be a scalar, a set, or a document type
A DocumentTableSchema is used to create a
DynamoDbTablewhich provides read and writes access to DynamoDB table asEnhancedDocument.DocumentTableSchema specifying primaryKey, sortKey and a customAttributeConverter can be created as below
DocumentTableSchema can also be created without specifying primaryKey and sortKey in which cases the
TableMetadataof DocumentTableSchema will error if we try to access attributes from metaData. Also if attributeConverterProviders are not provided thenDefaultAttributeConverterProviderwill be used- See Also:
- Working with items and attributes
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classDocumentTableSchema.Builder
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description List<String>attributeNames()Returns a complete list of attribute names that are mapped by thisTableSchemaAttributeValueattributeValue(EnhancedDocument item, String attributeName)Returns a single attribute value from the modelled object.static DocumentTableSchema.Builderbuilder()booleanisAbstract()A boolean value that represents whether thisTableSchemais abstract which means that it cannot be used to directly create records as it is lacking required structural elements to map to a table, such as a primary key, but can be referred to and embedded by other schemata.Map<String,AttributeValue>itemToMap(EnhancedDocument item, boolean ignoreNulls)Takes a modelled object and converts it into a raw map ofAttributeValuethat the DynamoDb low-level SDK can work with.Map<String,AttributeValue>itemToMap(EnhancedDocument item, Collection<String> attributes)Takes a modelled object and extracts a specific set of attributes which are then returned as a map ofAttributeValuethat the DynamoDb low-level SDK can work with.EnhancedType<EnhancedDocument>itemType()Returns theEnhancedTypethat represents the 'Type' of the Java object this table schema object maps to and from.EnhancedDocumentmapToItem(Map<String,AttributeValue> attributeMap)Takes a raw DynamoDb SDK representation of a record in a table and maps it to a Java object.TableMetadatatableMetadata()Returns the object that describes the structure of the table being modelled by the mapper.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface software.amazon.awssdk.enhanced.dynamodb.TableSchema
converterForAttribute, mapToItem
-
-
-
-
Method Detail
-
builder
public static DocumentTableSchema.Builder builder()
-
mapToItem
public EnhancedDocument mapToItem(Map<String,AttributeValue> attributeMap)
Description copied from interface:TableSchemaTakes a raw DynamoDb SDK representation of a record in a table and maps it to a Java object. A new object is created to fulfil this operation.If attributes are missing from the map, that will not cause an error, however if attributes are found in the map which the mapper does not know how to map, an exception will be thrown.
If all attribute values in the attributeMap are null, null will be returned. Use
TableSchema.mapToItem(Map, boolean)instead if you need to preserve empty object.API Implementors Note:
TableSchema.mapToItem(Map, boolean)must be implemented ifpreserveEmptyObjectbehavior is desired.- Specified by:
mapToItemin interfaceTableSchema<EnhancedDocument>- Parameters:
attributeMap- A map of String toAttributeValuethat contains all the raw attributes to map.- Returns:
- A new instance of a Java object with all the attributes mapped onto it.
- See Also:
TableSchema.mapToItem(Map, boolean)
-
itemToMap
public Map<String,AttributeValue> itemToMap(EnhancedDocument item, boolean ignoreNulls)
Takes a modelled object and converts it into a raw map ofAttributeValuethat the DynamoDb low-level SDK can work with. This flag does not have significance for the Document API, unlike Java objects where the default value of an undefined Object is null.In contrast to mapped classes, where a schema is present, the DocumentSchema is unaware of the entire schema.Therefore, if an attribute is not present, it signifies that it is null, and there is no need to handle it in a separate way.However, if the user explicitly wants to nullify certain attributes, then the user needs to set those attributes as null in the Document that needs to be updated.- Specified by:
itemToMapin interfaceTableSchema<EnhancedDocument>- Parameters:
item- The modelled Java object to convert into a map of attributes.ignoreNulls- If set to true; any null values in the Java object will not be added to the output map. If set to false; null values in the Java object will be added asAttributeValueof type 'nul' to the output map.- Returns:
- A map of String to
AttributeValuerepresenting all the modelled attributes in the model object.
-
itemToMap
public Map<String,AttributeValue> itemToMap(EnhancedDocument item, Collection<String> attributes)
Description copied from interface:TableSchemaTakes a modelled object and extracts a specific set of attributes which are then returned as a map ofAttributeValuethat the DynamoDb low-level SDK can work with. This method is typically used to extract just the key attributes of a modelled item and will not ignore nulls on the modelled object.- Specified by:
itemToMapin interfaceTableSchema<EnhancedDocument>- Parameters:
item- The modelled Java object to extract the map of attributes from.attributes- A collection of attribute names to extract into the output map.- Returns:
- A map of String to
AttributeValuerepresenting the requested modelled attributes in the model object.
-
attributeValue
public AttributeValue attributeValue(EnhancedDocument item, String attributeName)
Description copied from interface:TableSchemaReturns a single attribute value from the modelled object.- Specified by:
attributeValuein interfaceTableSchema<EnhancedDocument>- Parameters:
item- The modelled Java object to extract the attribute from.attributeName- The attribute name describing which attribute to extract.- Returns:
- A single
AttributeValuerepresenting the requested modelled attribute in the model object or null if the attribute has not been set with a value in the modelled object.
-
tableMetadata
public TableMetadata tableMetadata()
Description copied from interface:TableSchemaReturns the object that describes the structure of the table being modelled by the mapper. This includes information such as the table name, index keys and attribute tags.- Specified by:
tableMetadatain interfaceTableSchema<EnhancedDocument>- Returns:
- A
TableMetadataobject that contains structural information about the table being modelled.
-
itemType
public EnhancedType<EnhancedDocument> itemType()
Description copied from interface:TableSchemaReturns theEnhancedTypethat represents the 'Type' of the Java object this table schema object maps to and from.- Specified by:
itemTypein interfaceTableSchema<EnhancedDocument>- Returns:
- The
EnhancedTypeof the modelled item this TableSchema maps to.
-
attributeNames
public List<String> attributeNames()
Description copied from interface:TableSchemaReturns a complete list of attribute names that are mapped by thisTableSchema- Specified by:
attributeNamesin interfaceTableSchema<EnhancedDocument>
-
isAbstract
public boolean isAbstract()
Description copied from interface:TableSchemaA boolean value that represents whether thisTableSchemais abstract which means that it cannot be used to directly create records as it is lacking required structural elements to map to a table, such as a primary key, but can be referred to and embedded by other schemata.- Specified by:
isAbstractin interfaceTableSchema<EnhancedDocument>- Returns:
- true if it is abstract, and therefore cannot be used directly to create records but can be referred to by other schemata, and false if it is concrete and may be used to map records directly.
-
-