Class EntityTableBuilder<T>

java.lang.Object
dev.hogwai.dynamodb.simplified.entity.EntityTableBuilder<T>
Type Parameters:
T - the entity type

public final class EntityTableBuilder<T> extends Object
Builder for creating EntityTable instances for single-table design.

The entity class must be annotated with @Entity and may use @KeyComponent and @KeyPrefix annotations to define the entity schema.

Usage:

EntityTable<User> userTable = new EntityTableBuilder<>(User.class)
        .dynamoDbClient(dynamoDbClient)
        .build();

Alternatively, use DynamoSimplifiedClient.entityTable(Class) for a simpler end-to-end flow.

  • Constructor Summary

    Constructors
    Constructor
    Description
    EntityTableBuilder(@NonNull Class<T> entityClass)
    Creates a new builder for the given entity class.
  • Method Summary

    Modifier and Type
    Method
    Description
    @NonNull EntityTable<T>
    Builds the EntityTable instance.
    static <T> @NonNull EntityTable<T>
    create(@NonNull Class<T> entityClass, @NonNull software.amazon.awssdk.services.dynamodb.DynamoDbClient dynamoDbClient, @NonNull software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClient enhancedClient)
    Creates an EntityTable for the given entity class using the provided DynamoDB clients.
    static <T> @NonNull AsyncEntityTable<T>
    createAsync(@NonNull Class<T> entityClass, @NonNull software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient dynamoDbAsyncClient, @NonNull software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedAsyncClient enhancedAsyncClient)
    Creates an AsyncEntityTable for the given entity class using the provided async DynamoDB clients.
    dynamoDbClient(@NonNull software.amazon.awssdk.services.dynamodb.DynamoDbClient client)
    Sets the low-level DynamoDbClient to use.
    enhancedClient(@NonNull software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClient client)
    Sets the DynamoDbEnhancedClient to use.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • EntityTableBuilder

      public EntityTableBuilder(@NonNull Class<T> entityClass)
      Creates a new builder for the given entity class.
      Parameters:
      entityClass - the entity class annotated with @Entity
  • Method Details

    • dynamoDbClient

      public EntityTableBuilder<T> dynamoDbClient(@NonNull software.amazon.awssdk.services.dynamodb.DynamoDbClient client)
      Sets the low-level DynamoDbClient to use.
      Parameters:
      client - the DynamoDB client
      Returns:
      this builder for chaining
    • enhancedClient

      public EntityTableBuilder<T> enhancedClient(@NonNull software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClient client)
      Sets the DynamoDbEnhancedClient to use.

      If not set, one will be built from the provided dynamoDbClient(DynamoDbClient).

      Parameters:
      client - the enhanced DynamoDB client
      Returns:
      this builder for chaining
    • create

      public static <T> @NonNull EntityTable<T> create(@NonNull Class<T> entityClass, @NonNull software.amazon.awssdk.services.dynamodb.DynamoDbClient dynamoDbClient, @NonNull software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClient enhancedClient)
      Creates an EntityTable for the given entity class using the provided DynamoDB clients.

      This is a convenience method equivalent to:

      new EntityTableBuilder<>(entityClass)
              .dynamoDbClient(dynamoDbClient)
              .enhancedClient(enhancedClient)
              .build();
      
      Type Parameters:
      T - the entity type
      Parameters:
      entityClass - the entity class annotated with @Entity
      dynamoDbClient - the low-level DynamoDB client
      enhancedClient - the enhanced DynamoDB client
      Returns:
      a new EntityTable<T>
    • createAsync

      public static <T> @NonNull AsyncEntityTable<T> createAsync(@NonNull Class<T> entityClass, @NonNull software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient dynamoDbAsyncClient, @NonNull software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedAsyncClient enhancedAsyncClient)
      Creates an AsyncEntityTable for the given entity class using the provided async DynamoDB clients.

      This is a convenience method equivalent to:

      new AsyncEntityTableBuilder<>(entityClass)
              .dynamoDbAsyncClient(dynamoDbAsyncClient)
              .enhancedAsyncClient(enhancedAsyncClient)
              .build();
      
      Type Parameters:
      T - the entity type
      Parameters:
      entityClass - the entity class annotated with @Entity
      dynamoDbAsyncClient - the low-level async DynamoDB client
      enhancedAsyncClient - the enhanced async DynamoDB client
      Returns:
      a new AsyncEntityTable<T>
    • build

      public @NonNull EntityTable<T> build()
      Builds the EntityTable instance.

      Reads the entity schema from annotations, creates the underlying DynamoDB table mapping, and wraps it in an DefaultEntityTable.

      Returns:
      a new EntityTable<T>
      Throws:
      IllegalArgumentException - if the entity class is not annotated with @Entity
      NullPointerException - if no DynamoDbClient is set