Class ImmutableTableSchema<T>
- java.lang.Object
-
- software.amazon.awssdk.enhanced.dynamodb.mapper.WrappedTableSchema<T,StaticImmutableTableSchema<T,?>>
-
- software.amazon.awssdk.enhanced.dynamodb.mapper.ImmutableTableSchema<T>
-
- Type Parameters:
T
- The type of object that thisTableSchema
maps to.
- All Implemented Interfaces:
TableSchema<T>
@ThreadSafe public final class ImmutableTableSchema<T> extends WrappedTableSchema<T,StaticImmutableTableSchema<T,?>>
Implementation ofTableSchema
that builds a table schema based on properties and annotations of an immutable class with an associated builder class. Example:@DynamoDbImmutable(builder = Customer.Builder.class) public class Customer { @DynamoDbPartitionKey public String accountId() { ... } @DynamoDbSortKey public int subId() { ... } // Defines a GSI (customers_by_name) with a partition key of 'name' @DynamoDbSecondaryPartitionKey(indexNames = "customers_by_name") public String 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 createdDate() { ... } // Not required to be an inner-class, but builders often are public static final class Builder { public Builder accountId(String accountId) { ... }; public Builder subId(int subId) { ... }; public Builder name(String name) { ... }; public Builder createdDate(Instant createdDate) { ... }; public Customer build() { ... }; } }
ImmutableTableSchema
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> ImmutableTableSchema<T>
create(Class<T> immutableClass)
Scans an immutable class and builds anImmutableTableSchema
from it that can be used with theDynamoDbEnhancedClient
.static <T> ImmutableTableSchema<T>
create(ImmutableTableSchemaParams<T> params)
Scans an immutable class and builds anImmutableTableSchema
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> ImmutableTableSchema<T> create(ImmutableTableSchemaParams<T> params)
Scans an immutable class and builds anImmutableTableSchema
from it that can be used with theDynamoDbEnhancedClient
.Creating an
ImmutableTableSchema
is a moderately expensive operation, and should be performed sparingly. This is usually done once at application startup.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 immutable class type.- Parameters:
params
- The parameters object.- Returns:
- An initialized
ImmutableTableSchema
-
create
public static <T> ImmutableTableSchema<T> create(Class<T> immutableClass)
Scans an immutable class and builds anImmutableTableSchema
from it that can be used with theDynamoDbEnhancedClient
.Creating an
ImmutableTableSchema
is a moderately expensive operation, and should be performed sparingly. This is usually done once at application startup.If you are running your application in an environment where
beanClass
and the SDK are loaded by different classloaders, you should consider using thecreate(ImmutableTableSchemaParams)
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 immutable class type.- Parameters:
immutableClass
- The annotated immutable class to build the table schema from.- Returns:
- An initialized
ImmutableTableSchema
-
-