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 this TableSchema maps to.
All Implemented Interfaces:
TableSchema<T>

@ThreadSafe public final class ImmutableTableSchema<T> extends WrappedTableSchema<T,StaticImmutableTableSchema<T,?>>
Implementation of TableSchema 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() { ... };
     }
 }
 
Creating an 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 Details

    • create

      public static <T> ImmutableTableSchema<T> create(Class<T> immutableClass)
      Scans an immutable class and builds an ImmutableTableSchema from it that can be used with the DynamoDbEnhancedClient. Creating an ImmutableTableSchema is a moderately expensive operation, and should be performed sparingly. This is usually done once at application startup.
      Type Parameters:
      T - The immutable class type.
      Parameters:
      immutableClass - The annotated immutable class to build the table schema from.
      Returns:
      An initialized ImmutableTableSchema