Class Table<T>

java.lang.Object
dev.hogwai.dynamodb.simplified.Table<T>
Type Parameters:
T - the item type mapped to this table

public class Table<T> extends Object
Typed entry point for DynamoDB operations on a single table.

Obtained via DynamoSimplifiedClient.table(String, Class). Provides fluent builder access (query, scan, put, get, update, delete) and convenience direct methods (putItem, getItem, updateItem, deleteItem).

  • Constructor Summary

    Constructors
    Constructor
    Description
    Table(software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClient enhancedClient, software.amazon.awssdk.enhanced.dynamodb.DynamoDbTable<T> dynamoDbTable, software.amazon.awssdk.services.dynamodb.DynamoDbClient dynamoDbClient)
    Constructs a typed table wrapper.
  • Method Summary

    Modifier and Type
    Method
    Description
    @NonNull BatchGetBuilder<T>
    Starts building a batch get operation to retrieve multiple items by key.
    Starts building a batch write operation to put and delete multiple items.
    void
    Creates the DynamoDB table corresponding to this Table instance.
    void
    create(@NonNull Consumer<software.amazon.awssdk.enhanced.dynamodb.model.CreateTableEnhancedRequest.Builder> configurator)
    Creates the DynamoDB table with options configured by a consumer.
    void
    create(@NonNull software.amazon.awssdk.enhanced.dynamodb.model.CreateTableEnhancedRequest request)
    Creates the DynamoDB table with additional options.
    void
    Deletes the DynamoDB table corresponding to this Table instance permanently.
    @NonNull DeleteBuilder<T>
    delete(@NonNull Object partitionKey)
    Starts building a delete operation by partition key with optional conditions.
    @NonNull DeleteBuilder<T>
    delete(@NonNull Object partitionKey, @NonNull Object sortKey)
    Starts building a delete operation by partition and sort key with optional conditions.
    @Nullable T
    deleteItem(@NonNull Object partitionKey)
    Deletes an item by partition key directly.
    @Nullable T
    deleteItem(@NonNull Object partitionKey, @NonNull Object sortKey)
    Deletes an item by partition and sort key directly.
    @NonNull software.amazon.awssdk.enhanced.dynamodb.model.DescribeTableEnhancedResponse
    Returns information about the DynamoDB table, including its status, schema, throughput settings, and indexes.
    @NonNull software.amazon.awssdk.services.dynamodb.model.TimeToLiveDescription
    Describes the current TTL configuration for this table.
    void
    disableTtl(@NonNull String attributeName)
    Disables TTL on this table for the given attribute name.
    void
    enableTtl(@NonNull String attributeName)
    Enables Time To Live (TTL) on this table with the given attribute name.
    boolean
    Checks whether the DynamoDB table exists.
    @NonNull GetItemBuilder<T>
    get(@NonNull Object partitionKey)
    Starts building a get operation by partition key.
    @NonNull GetItemBuilder<T>
    get(@NonNull Object partitionKey, @NonNull Object sortKey)
    Starts building a get operation by partition and sort key.
    @NonNull software.amazon.awssdk.services.dynamodb.DynamoDbClient
    Returns the underlying low-level DynamoDbClient.
    @NonNull software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClient
    Returns the underlying DynamoDbEnhancedClient for advanced operations.
    @NonNull Optional<T>
    getItem(@NonNull Object partitionKey)
    Fetches an item by partition key directly.
    @NonNull Optional<T>
    getItem(@NonNull Object partitionKey, @NonNull Object sortKey)
    Fetches an item by partition and sort key directly.
    @NonNull software.amazon.awssdk.enhanced.dynamodb.DynamoDbTable<T>
    Returns the underlying DynamoDbTable for advanced operations.
    @NonNull Index<T>
    index(@NonNull String indexName)
    Returns a typed wrapper for the named secondary index (GSI or LSI).
    @NonNull PutBuilder<T>
    put(@NonNull T item)
    Starts building a put operation with optional conditions.
    putAll(@NonNull Collection<T> items)
    Puts all items in a single batch write operation.
    void
    putItem(@NonNull T item)
    Puts an item directly without conditions.
    @NonNull QueryBuilder<T>
    Starts building a query operation.
    @NonNull ScanBuilder<T>
    Starts building a scan operation.
    @NonNull UpdateBuilder<T>
    update(@NonNull T item)
    Starts building an update operation with optional conditions and partial expressions.
    @NonNull UpdateBuilder<T>
    update(@NonNull T item, @NonNull Consumer<UpdateExpression> expressionConsumer)
    Starts building a partial update operation with an expression consumer.
    void
    update(@NonNull Object partitionKey, @Nullable Object sortKey, @NonNull Consumer<UpdateExpression> expressionConsumer)
    Updates an item identified by partition and sort key using a partial update expression.
    @Nullable T
    updateItem(@NonNull T item)
    Updates an item directly without conditions or partial expressions.
    void
    updateTable(@NonNull Consumer<software.amazon.awssdk.services.dynamodb.model.UpdateTableRequest.Builder> requestConsumer)
    Updates the DynamoDB table with the specified configuration.

    Methods inherited from class Object

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

    • Table

      public Table(software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClient enhancedClient, software.amazon.awssdk.enhanced.dynamodb.DynamoDbTable<T> dynamoDbTable, software.amazon.awssdk.services.dynamodb.DynamoDbClient dynamoDbClient)
      Constructs a typed table wrapper.

      Typically obtained via DynamoSimplifiedClient.table(String, Class) rather than constructed directly.

      Parameters:
      enhancedClient - the enhanced DynamoDB client
      dynamoDbTable - the typed enhanced DynamoDB table
      dynamoDbClient - the low-level DynamoDB client (used for fallback operations)
  • Method Details

    • query

      public @NonNull QueryBuilder<T> query()
      Starts building a query operation.

      Use the returned builder to set the partition key, sort key conditions, filters, and other options, then call execute().

      Returns:
      a query builder for chaining
    • scan

      public @NonNull ScanBuilder<T> scan()
      Starts building a scan operation.

      Use the returned builder to set filters and other options, then call execute().

      Returns:
      a scan builder for chaining
    • get

      public @NonNull GetItemBuilder<T> get(@NonNull Object partitionKey)
      Starts building a get operation by partition key.

      Use the returned builder to set projection and consistent read options, then call execute().

      Parameters:
      partitionKey - the partition key value
      Returns:
      a get builder for chaining
    • get

      public @NonNull GetItemBuilder<T> get(@NonNull Object partitionKey, @NonNull Object sortKey)
      Starts building a get operation by partition and sort key.

      Use the returned builder to set projection and consistent read options, then call execute().

      Parameters:
      partitionKey - the partition key value
      sortKey - the sort key value
      Returns:
      a get builder for chaining
    • getItem

      public @NonNull Optional<T> getItem(@NonNull Object partitionKey)
      Fetches an item by partition key directly.
      Parameters:
      partitionKey - the partition key value
      Returns:
      an Optional containing the item, or empty if not found
    • getItem

      public @NonNull Optional<T> getItem(@NonNull Object partitionKey, @NonNull Object sortKey)
      Fetches an item by partition and sort key directly.
      Parameters:
      partitionKey - the partition key value
      sortKey - the sort key value
      Returns:
      an Optional containing the item, or empty if not found
    • put

      public @NonNull PutBuilder<T> put(@NonNull T item)
      Starts building a put operation with optional conditions.

      Use the returned builder to set condition expressions and other options, then call execute().

      Parameters:
      item - the item to put
      Returns:
      a put builder for chaining
    • putItem

      public void putItem(@NonNull T item)
      Puts an item directly without conditions.
      Parameters:
      item - the item to put
    • update

      public @NonNull UpdateBuilder<T> update(@NonNull T item)
      Starts building an update operation with optional conditions and partial expressions.

      Use the returned builder to set condition expressions, update expressions, and other options, then call execute().

      Parameters:
      item - the item with updated values
      Returns:
      an update builder for chaining
    • update

      public @NonNull UpdateBuilder<T> update(@NonNull T item, @NonNull Consumer<UpdateExpression> expressionConsumer)
      Starts building a partial update operation with an expression consumer.

      This is a convenience shorthand for update(item).update(consumer). The returned builder can be further configured before calling execute().

      Parameters:
      item - the item identifying the record to update (key fields only)
      expressionConsumer - a consumer to configure the update expression (SET, REMOVE, ADD, DELETE)
      Returns:
      an update builder for further configuration and execution
    • update

      public void update(@NonNull Object partitionKey, @Nullable Object sortKey, @NonNull Consumer<UpdateExpression> expressionConsumer)
      Updates an item identified by partition and sort key using a partial update expression.

      This avoids creating a dummy item object when the key is already known. Pass null for the sort key when the table has no sort key.

      Parameters:
      partitionKey - the partition key value
      sortKey - the sort key value, or null if the table has no sort key
      expressionConsumer - a consumer to build the update expression
    • updateItem

      public @Nullable T updateItem(@NonNull T item)
      Updates an item directly without conditions or partial expressions.
      Parameters:
      item - the item with updated values
      Returns:
      the updated item as returned by DynamoDB
    • delete

      public @NonNull DeleteBuilder<T> delete(@NonNull Object partitionKey)
      Starts building a delete operation by partition key with optional conditions.

      Use the returned builder to set condition expressions and other options, then call execute().

      Parameters:
      partitionKey - the partition key value
      Returns:
      a delete builder for chaining
    • delete

      public @NonNull DeleteBuilder<T> delete(@NonNull Object partitionKey, @NonNull Object sortKey)
      Starts building a delete operation by partition and sort key with optional conditions.

      Use the returned builder to set condition expressions and other options, then call execute().

      Parameters:
      partitionKey - the partition key value
      sortKey - the sort key value
      Returns:
      a delete builder for chaining
    • deleteItem

      public @Nullable T deleteItem(@NonNull Object partitionKey)
      Deletes an item by partition key directly.
      Parameters:
      partitionKey - the partition key value
      Returns:
      the deleted item, or null if no item with the given key exists
    • deleteItem

      public @Nullable T deleteItem(@NonNull Object partitionKey, @NonNull Object sortKey)
      Deletes an item by partition and sort key directly.
      Parameters:
      partitionKey - the partition key value
      sortKey - the sort key value
      Returns:
      the deleted item, or null if no item with the given key exists
    • index

      public @NonNull Index<T> index(@NonNull String indexName)
      Returns a typed wrapper for the named secondary index (GSI or LSI).

      Use the returned Index to perform query and scan operations scoped to that index.

      Parameters:
      indexName - the name of the secondary index
      Returns:
      an Index<T> for the specified index
    • batchGet

      public @NonNull BatchGetBuilder<T> batchGet()
      Starts building a batch get operation to retrieve multiple items by key.

      Use the returned builder to add keys and set options, then call execute() to retrieve the items.

      Returns:
      a batch get builder for chaining
    • batchWrite

      public @NonNull BatchWriteBuilder<T> batchWrite()
      Starts building a batch write operation to put and delete multiple items.

      Use the returned builder to add put and delete operations, then call execute() to submit them.

      Returns:
      a batch write builder for chaining
    • putAll

      public @NonNull BatchWriteResult putAll(@NonNull Collection<T> items)
      Puts all items in a single batch write operation.

      Equivalent to creating a BatchWriteBuilder, adding all items, and executing it. At most 25 items per call are allowed by DynamoDB.

      Parameters:
      items - the items to put
      Returns:
      the batch write result
      Throws:
      IllegalArgumentException - if more than 25 items are provided
    • getRawTable

      public @NonNull software.amazon.awssdk.enhanced.dynamodb.DynamoDbTable<T> getRawTable()
      Returns the underlying DynamoDbTable for advanced operations.
      Returns:
      the raw DynamoDB table instance
    • getEnhancedClient

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

      public @NonNull software.amazon.awssdk.services.dynamodb.DynamoDbClient getDynamoDbClient()
      Returns the underlying low-level DynamoDbClient.
      Returns:
      the low-level DynamoDB client
    • create

      public void create()
      Creates the DynamoDB table corresponding to this Table instance.

      Uses the table schema defined during DynamoSimplifiedClient.table(String, Class) to create the table.

    • create

      public void create(@NonNull software.amazon.awssdk.enhanced.dynamodb.model.CreateTableEnhancedRequest request)
      Creates the DynamoDB table with additional options.
      Parameters:
      request - the create table request options
    • create

      public void create(@NonNull Consumer<software.amazon.awssdk.enhanced.dynamodb.model.CreateTableEnhancedRequest.Builder> configurator)
      Creates the DynamoDB table with options configured by a consumer.

      Example usage:

      table.create(b -> b
          .provisionedThroughput(p -> p
              .readCapacityUnits(10L)
              .writeCapacityUnits(10L)));
      
      Parameters:
      configurator - a consumer to configure the CreateTableEnhancedRequest.Builder
    • delete

      public void delete()
      Deletes the DynamoDB table corresponding to this Table instance permanently.
    • describe

      public @NonNull software.amazon.awssdk.enhanced.dynamodb.model.DescribeTableEnhancedResponse describe()
      Returns information about the DynamoDB table, including its status, schema, throughput settings, and indexes.
      Returns:
      the table description response
    • updateTable

      public void updateTable(@NonNull Consumer<software.amazon.awssdk.services.dynamodb.model.UpdateTableRequest.Builder> requestConsumer)
      Updates the DynamoDB table with the specified configuration.

      Example usage:

      table.updateTable(b -> b
          .provisionedThroughput(p -> p
              .readCapacityUnits(10L)
              .writeCapacityUnits(10L)));
      
      Parameters:
      requestConsumer - a consumer to configure the UpdateTableRequest.Builder
      Throws:
      OperationFailedException - if the DynamoDB API call fails
    • exists

      public boolean exists()
      Checks whether the DynamoDB table exists.

      Returns true if the table exists, false if it does not.

      Returns:
      true if the table exists, false otherwise
    • enableTtl

      public void enableTtl(@NonNull String attributeName)
      Enables Time To Live (TTL) on this table with the given attribute name.
      Parameters:
      attributeName - the attribute that stores the TTL epoch value
      Throws:
      OperationFailedException - if the DynamoDB API call fails
    • disableTtl

      public void disableTtl(@NonNull String attributeName)
      Disables TTL on this table for the given attribute name.
      Parameters:
      attributeName - the TTL attribute name to disable
      Throws:
      OperationFailedException - if the DynamoDB API call fails
    • describeTtl

      public @NonNull software.amazon.awssdk.services.dynamodb.model.TimeToLiveDescription describeTtl()
      Describes the current TTL configuration for this table.
      Returns:
      the TTL description
      Throws:
      OperationFailedException - if the DynamoDB API call fails