T
- The type of object that this TableSchema
maps to.public final class BeanTableSchema<T> extends Object implements TableSchema<T>
TableSchema
that builds a table schema based on properties and annotations of a bean
class. Example:
@DynamoDbBean
public class CustomerAccount {
private String unencryptedBillingKey;
@DynamoDbPartitionKey
@DynamoDbSecondarySortKey(indexName = "accounts_by_customer")
public String accountId;
@DynamoDbSortKey
@DynamoDbSecondaryPartitionKey(indexName = "accounts_by_customer")
public String customerId;
@DynamoDbAttribute("account_status")
public CustomerAccountStatus status;
@DynamoDbFlatten(dynamoDbBeanClass = Customer.class)
public Customer customer;
public Instant createdOn;
// All public fields must be opted out to not participate in mapping
@DynamoDbIgnore
public String internalKey;
public enum CustomerAccountStatus {
ACTIVE,
CLOSED
}
}
@DynamoDbBean
public class Customer {
public String name;
public List<String> address;
}
}
Modifier and Type | Method and Description |
---|---|
AttributeValue |
attributeValue(T item,
String key)
Returns a single attribute value from the modelled object.
|
static <T> BeanTableSchema<T> |
create(Class<T> beanClass)
Scans a bean class and builds a
BeanTableSchema from it that can be used with the
DynamoDbEnhancedClient . |
Map<String,AttributeValue> |
itemToMap(T item,
boolean ignoreNulls)
Takes a modelled object and converts it into a raw map of
AttributeValue 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 of
AttributeValue that the DynamoDb low-level SDK can work with. |
EnhancedType<T> |
itemType()
Returns the
EnhancedType 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.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
builder, fromBean
public static <T> BeanTableSchema<T> create(Class<T> beanClass)
BeanTableSchema
from it that can be used with the
DynamoDbEnhancedClient
.T
- The bean class type.beanClass
- The bean class to build the table schema from.BeanTableSchema
public T mapToItem(Map<String,AttributeValue> attributeMap)
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.
mapToItem
in interface TableSchema<T>
attributeMap
- A map of String to AttributeValue
that contains all the raw attributes to map.public Map<String,AttributeValue> itemToMap(T item, boolean ignoreNulls)
AttributeValue
that the DynamoDb low-level
SDK can work with.itemToMap
in interface TableSchema<T>
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 as AttributeValue
of
type 'nul' to the output map.AttributeValue
representing all the modelled attributes in the model object.public Map<String,AttributeValue> itemToMap(T item, Collection<String> attributes)
AttributeValue
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.itemToMap
in interface TableSchema<T>
item
- The modelled Java object to extract the map of attributes from.attributes
- A collection of attribute names to extract into the output map.AttributeValue
representing the requested modelled attributes in the model
object.public AttributeValue attributeValue(T item, String key)
attributeValue
in interface TableSchema<T>
item
- The modelled Java object to extract the attribute from.key
- The attribute name describing which attribute to extract.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.public TableMetadata tableMetadata()
tableMetadata
in interface TableSchema<T>
TableMetadata
object that contains structural information about the table being modelled.public EnhancedType<T> itemType()
TableSchema
EnhancedType
that represents the 'Type' of the Java object this table schema object maps to
and from.itemType
in interface TableSchema<T>
EnhancedType
of the modelled item this TableSchema maps to.Copyright © 2020. All rights reserved.