T
- The type of object that this TableSchema
maps to.@ThreadSafe public final class BeanTableSchema<T> extends WrappedTableSchema<T,StaticTableSchema<T>>
TableSchema
that builds a table schema based on properties and annotations of a bean
class. Example:
@DynamoDbBean
public class Customer {
private String accountId;
private int subId; // primitive types are supported
private String name;
private Instant createdDate;
@DynamoDbPartitionKey
public String getAccountId() { return this.accountId; }
public void setAccountId(String accountId) { this.accountId = accountId; }
@DynamoDbSortKey
public int getSubId() { return this.subId; }
public void setSubId(int subId) { this.subId = subId; }
// Defines a GSI (customers_by_name) with a partition key of 'name'
@DynamoDbSecondaryPartitionKey(indexNames = "customers_by_name")
public String getName() { return this.name; }
public void setName(String name) { this.name = name; }
// Defines an LSI (customers_by_date) with a sort key of 'createdDate' and also declares the
// same attribute as a sort key for the GSI named 'customers_by_name'
@DynamoDbSecondarySortKey(indexNames = {"customers_by_date", "customers_by_name"})
public Instant getCreatedDate() { return this.createdDate; }
public void setCreatedDate(Instant createdDate) { this.createdDate = createdDate; }
}
Creating an BeanTableSchema
is a moderately expensive operation, and should be performed sparingly. This is
usually done once at application startup.
If this table schema is not behaving as you expect, enable debug logging for 'software.amazon.awssdk.enhanced.dynamodb.beans'.Modifier and Type | Method and Description |
---|---|
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 . |
attributeNames, attributeValue, converterForAttribute, delegateTableSchema, isAbstract, itemToMap, itemToMap, itemType, mapToItem, mapToItem, tableMetadata
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
builder, builder, fromBean, fromClass, fromImmutableClass
public static <T> BeanTableSchema<T> create(Class<T> beanClass)
BeanTableSchema
from it that can be used with the
DynamoDbEnhancedClient
.
Creating an BeanTableSchema
is a moderately expensive operation, and should be performed sparingly. This is
usually done once at application startup.T
- The bean class type.beanClass
- The bean class to build the table schema from.BeanTableSchema
Copyright © 2022. All rights reserved.