Class BeanTableSchema<T>

  • Type Parameters:
    T - The type of object that this TableSchema maps to.
    All Implemented Interfaces:
    TableSchema<T>

    @ThreadSafe
    public final class BeanTableSchema<T>
    extends WrappedTableSchema<T,​StaticTableSchema<T>>
    Implementation of 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'.
    • Method Detail

      • create

        public 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.

        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.

        Type Parameters:
        T - The bean class type.
        Parameters:
        beanClass - The bean class to build the table schema from.
        Returns:
        An initialized BeanTableSchema