Class MetaTableSchema<T>
- java.lang.Object
-
- software.amazon.awssdk.enhanced.dynamodb.internal.mapper.MetaTableSchema<T>
-
- All Implemented Interfaces:
TableSchema<T>
public class MetaTableSchema<T> extends Object implements TableSchema<T>
An implementation ofTableSchema
that can be instantiated as an uninitialized reference and then lazily initialized later with a concreteTableSchema
at which point it will behave as the real object.This allows an immutable
TableSchema
to be declared and used in a self-referential recursive way within its builder/definition path. Any attempt to use theMetaTableSchema
as a concreteTableSchema
before callinginitialize(TableSchema)
will cause an exception to be thrown.
-
-
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 thisTableSchema
AttributeValue
attributeValue(T item, String attributeName)
Returns a single attribute value from the modelled object.TableSchema<T>
concreteTableSchema()
AttributeConverter<T>
converterForAttribute(Object key)
AttributeConverter
that is applied to the given key.static <T> MetaTableSchema<T>
create(Class<T> itemClass)
void
initialize(TableSchema<T> realTableSchema)
boolean
isAbstract()
A boolean value that represents whether thisTableSchema
is 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.boolean
isInitialized()
Map<String,AttributeValue>
itemToMap(T item, boolean ignoreNulls)
Takes a modelled object and converts it into a raw map ofAttributeValue
that the DynamoDb low-level SDK can work with.Map<String,AttributeValue>
itemToMap(T item, Collection<String> attributes)
Takes a modelled object and extracts a specific set of attributes which are then returned as a map ofAttributeValue
that the DynamoDb low-level SDK can work with.EnhancedType<T>
itemType()
Returns theEnhancedType
that represents the 'Type' of the Java object this table schema object maps to and from.T
mapToItem(Map<String,AttributeValue> attributeMap)
Takes a raw DynamoDb SDK representation of a record in a table and maps it to a Java object.TableMetadata
tableMetadata()
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
mapToItem
-
-
-
-
Method Detail
-
create
public static <T> MetaTableSchema<T> create(Class<T> itemClass)
-
mapToItem
public T mapToItem(Map<String,AttributeValue> attributeMap)
Description copied from interface:TableSchema
Takes 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 ifpreserveEmptyObject
behavior is desired.- Specified by:
mapToItem
in interfaceTableSchema<T>
- Parameters:
attributeMap
- A map of String toAttributeValue
that 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(T item, boolean ignoreNulls)
Description copied from interface:TableSchema
Takes a modelled object and converts it into a raw map ofAttributeValue
that the DynamoDb low-level SDK can work with.- Specified by:
itemToMap
in interfaceTableSchema<T>
- 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 asAttributeValue
of type 'nul' to the output map.- Returns:
- A map of String to
AttributeValue
representing all the modelled attributes in the model object.
-
itemToMap
public Map<String,AttributeValue> itemToMap(T item, Collection<String> attributes)
Description copied from interface:TableSchema
Takes a modelled object and extracts a specific set of attributes which are then returned as a map ofAttributeValue
that 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:
itemToMap
in interfaceTableSchema<T>
- 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
AttributeValue
representing the requested modelled attributes in the model object.
-
attributeValue
public AttributeValue attributeValue(T item, String attributeName)
Description copied from interface:TableSchema
Returns a single attribute value from the modelled object.- Specified by:
attributeValue
in interfaceTableSchema<T>
- Parameters:
item
- The modelled Java object to extract the attribute from.attributeName
- The attribute name describing which attribute to extract.- Returns:
- A single
AttributeValue
representing 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:TableSchema
Returns 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:
tableMetadata
in interfaceTableSchema<T>
- Returns:
- A
TableMetadata
object that contains structural information about the table being modelled.
-
itemType
public EnhancedType<T> itemType()
Description copied from interface:TableSchema
Returns theEnhancedType
that represents the 'Type' of the Java object this table schema object maps to and from.- Specified by:
itemType
in interfaceTableSchema<T>
- Returns:
- The
EnhancedType
of the modelled item this TableSchema maps to.
-
attributeNames
public List<String> attributeNames()
Description copied from interface:TableSchema
Returns a complete list of attribute names that are mapped by thisTableSchema
- Specified by:
attributeNames
in interfaceTableSchema<T>
-
isAbstract
public boolean isAbstract()
Description copied from interface:TableSchema
A boolean value that represents whether thisTableSchema
is 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:
isAbstract
in interfaceTableSchema<T>
- 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.
-
converterForAttribute
public AttributeConverter<T> converterForAttribute(Object key)
Description copied from interface:TableSchema
AttributeConverter
that is applied to the given key.- Specified by:
converterForAttribute
in interfaceTableSchema<T>
- Parameters:
key
- Attribute of the modelled item.- Returns:
- AttributeConverter defined for the given attribute key.
-
initialize
public void initialize(TableSchema<T> realTableSchema)
-
concreteTableSchema
public TableSchema<T> concreteTableSchema()
-
isInitialized
public boolean isInitialized()
-
-