Class DynamoSimplifiedClient

java.lang.Object
dev.hogwai.dynamodb.simplified.DynamoSimplifiedClient
All Implemented Interfaces:
DynamoSimplifiedClientInterface, AutoCloseable

public class DynamoSimplifiedClient extends Object implements DynamoSimplifiedClientInterface
Entry point for the DynamoDB Simplified library.

Provides factory methods to create a client and access typed Table instances for DynamoDB table operations. Wraps a DynamoDbEnhancedClient and a DynamoDbClient.

Thread safety: this client is safe to use from multiple threads once created. The table() factory method may be called concurrently. Individual builders returned by Table methods are single-use and not thread-safe.

Usage:

DynamoSimplifiedClient client = DynamoSimplifiedClient.create();
Table<Post> posts = client.table("posts", Post.class);
posts.query().partitionKey("subreddit").executeAll();
See Also:
  • Table
  • DynamoDbEnhancedClient
  • DynamoDbClient
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns a cross-table batch get builder for retrieving items from multiple tables.
    Returns a cross-table batch write builder for putting/deleting items across multiple tables.
    Returns a new DynamoSimplifiedClientBuilder for building a client with a custom DynamoDB client and/or enhanced client extensions.
    void
    Closes the underlying DynamoDB client, releasing any network resources.
    static @NonNull DynamoSimplifiedClient
    Creates a DynamoSimplifiedClient with default AWS credentials and region.
    static @NonNull DynamoSimplifiedClient
    create(@NonNull software.amazon.awssdk.services.dynamodb.DynamoDbClient client)
    Creates a DynamoSimplifiedClient with a custom DynamoDbClient.
    entityQuery(@NonNull String tableName)
    Starts a cross-entity query using the default _type discriminator attribute.
    entityQuery(@NonNull String tableName, @NonNull String discriminatorAttribute)
    Starts a cross-entity query using a custom discriminator attribute.
    <T> @NonNull EntityTable<T>
    entityTable(@NonNull Class<T> entityClass)
    Returns an EntityTable for the given entity class, enabling single-table design with auto-computed composite keys and discriminator filtering.
    @NonNull software.amazon.awssdk.services.dynamodb.model.ExecuteStatementResponse
    executeStatement(@NonNull software.amazon.awssdk.services.dynamodb.model.ExecuteStatementRequest request)
    Executes a PartiQL statement against DynamoDB.
    @NonNull software.amazon.awssdk.services.dynamodb.DynamoDbClient
    Returns the underlying DynamoDbClient for advanced operations.
    @NonNull software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClient
    Returns the underlying DynamoDbEnhancedClient for advanced operations.
    @NonNull List<String>
    Lists all DynamoDB tables available to this client.
    <T> @NonNull Table<T>
    table(@NonNull String tableName, @NonNull Class<T> itemClass)
    Returns a typed Table for the given table name and item class.
    <T> @NonNull Table<T>
    table(@NonNull String tableName, @NonNull Class<T> itemClass, @NonNull Consumer<software.amazon.awssdk.enhanced.dynamodb.mapper.StaticTableSchema.Builder<T>> configurator)
    Returns a typed Table for the given table name and item class, using a StaticTableSchema configured by the provided consumer.
    <T> @NonNull Table<T>
    table(@NonNull String tableName, @NonNull software.amazon.awssdk.enhanced.dynamodb.TableSchema<T> schema)
    Returns a typed Table for the given table name and custom schema.
    Starts building a transactional read operation across one or more tables.
    Starts building a transactional write operation across one or more tables.

    Methods inherited from class Object

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

    • builder

      public static @NonNull DynamoSimplifiedClientBuilder builder()
      Returns a new DynamoSimplifiedClientBuilder for building a client with a custom DynamoDB client and/or enhanced client extensions.
      Returns:
      a new builder instance
    • create

      public static @NonNull DynamoSimplifiedClient create()
      Creates a DynamoSimplifiedClient with default AWS credentials and region.

      Builds both the DynamoDbEnhancedClient and the underlying DynamoDbClient.

      Returns:
      a new DynamoSimplifiedClient instance
    • create

      public static @NonNull DynamoSimplifiedClient create(@NonNull software.amazon.awssdk.services.dynamodb.DynamoDbClient client)
      Creates a DynamoSimplifiedClient with a custom DynamoDbClient.

      Builds the DynamoDbEnhancedClient from the provided client.

      Parameters:
      client - the DynamoDB client to use
      Returns:
      a new DynamoSimplifiedClient instance
    • table

      public <T> @NonNull Table<T> table(@NonNull String tableName, @NonNull Class<T> itemClass)
      Returns a typed Table for the given table name and item class.

      The item class must be a valid DynamoDB bean with appropriate annotations.

      Specified by:
      table in interface DynamoSimplifiedClientInterface
      Type Parameters:
      T - the item type
      Parameters:
      tableName - the name of the DynamoDB table
      itemClass - the class of items stored in the table
      Returns:
      a Table<T> for the specified table
    • table

      public <T> @NonNull Table<T> table(@NonNull String tableName, @NonNull software.amazon.awssdk.enhanced.dynamodb.TableSchema<T> schema)
      Returns a typed Table for the given table name and custom schema.
      Specified by:
      table in interface DynamoSimplifiedClientInterface
      Type Parameters:
      T - the item type
      Parameters:
      tableName - the name of the DynamoDB table
      schema - the table schema defining item mapping
      Returns:
      a Table<T> for the specified table
    • table

      public <T> @NonNull Table<T> table(@NonNull String tableName, @NonNull Class<T> itemClass, @NonNull Consumer<software.amazon.awssdk.enhanced.dynamodb.mapper.StaticTableSchema.Builder<T>> configurator)
      Returns a typed Table for the given table name and item class, using a StaticTableSchema configured by the provided consumer.

      This is useful when you want to define the table schema programmatically rather than using annotations. Example:

      Table<Item> table = client.table("items", Item.class, b -> b
          .newItemSupplier(Item::new)
          .addAttribute(String.class, a -> a.name("pk")
              .getter(Item::getPk)
              .setter(Item::setPk)
              .tags(StaticAttributeTags.primaryPartitionKey()))
          .addAttribute(String.class, a -> a.name("sk")
              .getter(Item::getSk)
              .setter(Item::setSk)
              .tags(StaticAttributeTags.primarySortKey())));
      
      Specified by:
      table in interface DynamoSimplifiedClientInterface
      Type Parameters:
      T - the item type
      Parameters:
      tableName - the name of the DynamoDB table
      itemClass - the class of items stored in the table
      configurator - a consumer to configure the StaticTableSchema.Builder
      Returns:
      a Table<T> for the specified table
    • entityTable

      public <T> @NonNull EntityTable<T> entityTable(@NonNull Class<T> entityClass)
      Returns an EntityTable for the given entity class, enabling single-table design with auto-computed composite keys and discriminator filtering.

      The entity class must be annotated with @Entity. Key components are defined via @KeyComponent and automatically composed into the table's partition/sort keys before every put and update operation. Queries are automatically filtered by the entity's discriminator value.

      Specified by:
      entityTable in interface DynamoSimplifiedClientInterface
      Type Parameters:
      T - the entity type
      Parameters:
      entityClass - the entity class annotated with @Entity
      Returns:
      an EntityTable<T> for single-table design
    • entityQuery

      public @NonNull EntityQueryBuilder entityQuery(@NonNull String tableName)
      Starts a cross-entity query using the default _type discriminator attribute.
      Specified by:
      entityQuery in interface DynamoSimplifiedClientInterface
      Parameters:
      tableName - the DynamoDB table shared by the entity types
      Returns:
      a cross-entity query builder
    • entityQuery

      public @NonNull EntityQueryBuilder entityQuery(@NonNull String tableName, @NonNull String discriminatorAttribute)
      Starts a cross-entity query using a custom discriminator attribute.
      Specified by:
      entityQuery in interface DynamoSimplifiedClientInterface
      Parameters:
      tableName - the DynamoDB table shared by the entity types
      discriminatorAttribute - the attribute containing each entity's discriminator
      Returns:
      a cross-entity query builder
    • transactGet

      public @NonNull TransactGetBuilder transactGet()
      Starts building a transactional read operation across one or more tables.

      All items are read atomically in a single all-or-nothing transaction.

      Specified by:
      transactGet in interface DynamoSimplifiedClientInterface
      Returns:
      a transact get builder
    • transactWrite

      public @NonNull TransactWriteBuilder transactWrite()
      Starts building a transactional write operation across one or more tables.

      All put, update, delete, and condition check actions are applied atomically.

      Specified by:
      transactWrite in interface DynamoSimplifiedClientInterface
      Returns:
      a transact write builder
    • batchGet

      public @NonNull CrossTableBatchGetBuilder batchGet()
      Returns a cross-table batch get builder for retrieving items from multiple tables.
      Specified by:
      batchGet in interface DynamoSimplifiedClientInterface
      Returns:
      a cross-table batch get builder
    • batchWrite

      public @NonNull CrossTableBatchWriteBuilder batchWrite()
      Returns a cross-table batch write builder for putting/deleting items across multiple tables.
      Specified by:
      batchWrite in interface DynamoSimplifiedClientInterface
      Returns:
      a cross-table batch write builder
    • getEnhancedClient

      public @NonNull software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClient getEnhancedClient()
      Returns the underlying DynamoDbEnhancedClient for advanced operations.
      Specified by:
      getEnhancedClient in interface DynamoSimplifiedClientInterface
      Returns:
      the enhanced DynamoDB client
    • getDynamoDbClient

      public @NonNull software.amazon.awssdk.services.dynamodb.DynamoDbClient getDynamoDbClient()
      Returns the underlying DynamoDbClient for advanced operations.
      Specified by:
      getDynamoDbClient in interface DynamoSimplifiedClientInterface
      Returns:
      the DynamoDB client
    • listTables

      public @NonNull List<String> listTables()
      Lists all DynamoDB tables available to this client.

      Returns a list of table names accessible with the configured AWS credentials.

      Specified by:
      listTables in interface DynamoSimplifiedClientInterface
      Returns:
      a list of DynamoDB table names
    • executeStatement

      public @NonNull software.amazon.awssdk.services.dynamodb.model.ExecuteStatementResponse executeStatement(@NonNull software.amazon.awssdk.services.dynamodb.model.ExecuteStatementRequest request)
      Executes a PartiQL statement against DynamoDB.

      This is a passthrough to the underlying low-level DynamoDbClient.executeStatement(ExecuteStatementRequest). No fluent builder is provided because PartiQL is schemaless and the SDK request is already simple.

      Specified by:
      executeStatement in interface DynamoSimplifiedClientInterface
      Parameters:
      request - the PartiQL request to execute
      Returns:
      the response from DynamoDB
    • close

      public void close()
      Closes the underlying DynamoDB client, releasing any network resources.

      After calling this method, the client instance is no longer usable.

      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface DynamoSimplifiedClientInterface