Class BeanTableSchema<T>
- java.lang.Object
-
- software.amazon.awssdk.enhanced.dynamodb.mapper.WrappedTableSchema<T,StaticTableSchema<T>>
-
- software.amazon.awssdk.enhanced.dynamodb.mapper.BeanTableSchema<T>
-
- Type Parameters:
T
- The type of object that thisTableSchema
maps to.
- All Implemented Interfaces:
TableSchema<T>
@ThreadSafe public final class BeanTableSchema<T> extends WrappedTableSchema<T,StaticTableSchema<T>>
Implementation ofTableSchema
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; } }
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'.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> BeanTableSchema<T>
create(Class<T> beanClass)
Scans a bean class and builds aBeanTableSchema
from it that can be used with theDynamoDbEnhancedClient
.static <T> BeanTableSchema<T>
create(BeanTableSchemaParams<T> params)
Scans a bean class and builds aBeanTableSchema
from it that can be used with theDynamoDbEnhancedClient
.-
Methods inherited from class software.amazon.awssdk.enhanced.dynamodb.mapper.WrappedTableSchema
attributeNames, attributeValue, converterForAttribute, delegateTableSchema, isAbstract, itemToMap, itemToMap, itemType, mapToItem, mapToItem, tableMetadata
-
-
-
-
Method Detail
-
create
public static <T> BeanTableSchema<T> create(Class<T> beanClass)
Scans a bean class and builds aBeanTableSchema
from it that can be used with theDynamoDbEnhancedClient
.It's recommended to only create a
BeanTableSchema
once for a single bean class, usually at application start up, because it's a moderately expensive operation.If you are running your application in an environment where
beanClass
and the SDK are loaded by different classloaders, you should consider using thecreate(BeanTableSchemaParams)
overload instead, and provided a customMethodHandles.Lookup
object to ensure that the SDK has access to thebeanClass
and its properties at runtime.- Type Parameters:
T
- The bean class type.- Parameters:
beanClass
- The bean class to build the table schema from.- Returns:
- An initialized
BeanTableSchema
-
create
public static <T> BeanTableSchema<T> create(BeanTableSchemaParams<T> params)
Scans a bean class and builds aBeanTableSchema
from it that can be used with theDynamoDbEnhancedClient
.It's recommended to only create a
BeanTableSchema
once for a single bean class, usually at application start up, because it's a moderately expensive operation.Generally, this method should be preferred over
create(Class)
because it allows you to use a customMethodHandles.Lookup
instance, which is necessary when your application runs in an environment where your application code and dependencies like the AWS SDK for Java are loaded by different classloaders.- Type Parameters:
T
- The bean class type.- Parameters:
params
- The parameters object.- Returns:
- An initialized
BeanTableSchema
-
-