Class TransactWriteBuilder


public class TransactWriteBuilder extends AbstractTransactWriteBuilder<TransactWriteBuilder>
Builds a transactional write operation that groups up to 100 put, update, delete, and condition check actions atomically across one or more tables.

Obtain via DynamoSimplifiedClient.transactWrite().

All actions succeed or none are applied. If any condition fails or a conflict occurs, the entire transaction is rejected.

  • Constructor Details

    • TransactWriteBuilder

      public TransactWriteBuilder(@NonNull software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClient enhancedClient, @NonNull software.amazon.awssdk.services.dynamodb.DynamoDbClient dynamoDbClient)
      Constructs a transactional write builder.

      Typically obtained via DynamoSimplifiedClient.transactWrite().

      Parameters:
      enhancedClient - the enhanced DynamoDB client
      dynamoDbClient - the low-level DynamoDB client (used for expression-based update fallback)
  • Method Details

    • self

      protected @NonNull TransactWriteBuilder self()
      Description copied from class: AbstractTransactWriteBuilder
      Returns this typed as S for fluent chaining.
      Specified by:
      self in class AbstractTransactWriteBuilder<TransactWriteBuilder>
      Returns:
      this builder
    • getTableName

      protected @NonNull String getTableName(@NonNull AbstractTransactWriteBuilder.Operation operation)
      Description copied from class: AbstractTransactWriteBuilder
      Extracts the DynamoDB table name from an operation's table reference.
      Specified by:
      getTableName in class AbstractTransactWriteBuilder<TransactWriteBuilder>
      Parameters:
      operation - the operation whose table name to extract
      Returns:
      the DynamoDB table name
    • getTableSchema

      protected @NonNull software.amazon.awssdk.enhanced.dynamodb.TableSchema<?> getTableSchema(@NonNull AbstractTransactWriteBuilder.Operation operation)
      Description copied from class: AbstractTransactWriteBuilder
      Extracts the table schema from an operation's table reference.
      Specified by:
      getTableSchema in class AbstractTransactWriteBuilder<TransactWriteBuilder>
      Parameters:
      operation - the operation whose table schema to extract
      Returns:
      the table schema
    • keyFromItem

      protected @NonNull software.amazon.awssdk.enhanced.dynamodb.Key keyFromItem(@NonNull AbstractTransactWriteBuilder.Operation operation, @NonNull Object item)
      Description copied from class: AbstractTransactWriteBuilder
      Creates a Key from the given item using the operation's table reference.
      Specified by:
      keyFromItem in class AbstractTransactWriteBuilder<TransactWriteBuilder>
      Parameters:
      operation - the operation providing the table reference
      item - the item from which to extract the key
      Returns:
      the constructed key
    • put

      public <T> @NonNull TransactWriteBuilder put(@NonNull Table<T> table, @NonNull T item)
      Adds a put action to insert or replace an item.
      Type Parameters:
      T - the item type
      Parameters:
      table - the typed table to write to
      item - the item to put
      Returns:
      this builder
    • update

      public <T> @NonNull TransactWriteBuilder update(@NonNull Table<T> table, @NonNull T item)
      Adds an update action to modify an existing item.
      Type Parameters:
      T - the item type
      Parameters:
      table - the typed table to update
      item - the item with updated values
      Returns:
      this builder
    • update

      public <T> @NonNull TransactWriteBuilder update(@NonNull Table<T> table, @NonNull T item, @NonNull Consumer<UpdateExpression> expressionConfigurator)
      Adds an update action with a partial update expression for fine-grained attribute modifications.

      Use the expressionConfigurator to specify SET, REMOVE, ADD, and/or DELETE clauses. When an expression-based update is included in the transaction, the entire transaction is sent via the low-level DynamoDB API rather than the enhanced client.

      Type Parameters:
      T - the item type
      Parameters:
      table - the typed table to update
      item - the item providing the key identifying the item to update
      expressionConfigurator - a consumer to build the update expression
      Returns:
      this builder
    • delete

      public <T> @NonNull TransactWriteBuilder delete(@NonNull Table<T> table, @NonNull Object partitionKey)
      Adds a delete action by partition key.
      Type Parameters:
      T - the item type
      Parameters:
      table - the typed table to delete from
      partitionKey - the partition key value
      Returns:
      this builder
    • delete

      public <T> @NonNull TransactWriteBuilder delete(@NonNull Table<T> table, @NonNull Object partitionKey, @NonNull Object sortKey)
      Adds a delete action by partition and sort key.
      Type Parameters:
      T - the item type
      Parameters:
      table - the typed table to delete from
      partitionKey - the partition key value
      sortKey - the sort key value
      Returns:
      this builder
    • conditionCheck

      public <T> @NonNull TransactWriteBuilder conditionCheck(@NonNull Table<T> table, @NonNull Object partitionKey, @NonNull Consumer<ConditionExpression.Builder> condition)
      Adds a condition check action that verifies a condition on an item without modifying it.

      If the condition is not satisfied, the entire transaction is rejected.

      Type Parameters:
      T - the item type
      Parameters:
      table - the typed table to check
      partitionKey - the partition key value
      condition - a consumer to build the condition expression (e.g. expr -> expr.eq("status", "active"))
      Returns:
      this builder
    • conditionCheck

      public <T> @NonNull TransactWriteBuilder conditionCheck(@NonNull Table<T> table, @NonNull Object partitionKey, @Nullable Object sortKey, @NonNull Consumer<ConditionExpression.Builder> condition)
      Adds a condition check action with sort key.
      Type Parameters:
      T - the item type
      Parameters:
      table - the typed table to check
      partitionKey - the partition key value
      sortKey - the sort key value
      condition - a consumer to build the condition expression
      Returns:
      this builder
    • returnConsumedCapacity

      public @NonNull TransactWriteBuilder returnConsumedCapacity(@NonNull software.amazon.awssdk.services.dynamodb.model.ReturnConsumedCapacity returnConsumedCapacity)
      Configures whether to return consumed capacity information for the operation.
      Parameters:
      returnConsumedCapacity - the consumed capacity reporting level
      Returns:
      this builder for chaining
    • execute

      public void execute()
      Executes the transactional write operation.

      All actions are applied atomically. If any action fails, a TransactionCanceledException is thrown.

      If any operation in the transaction uses an UpdateExpression, the entire transaction is sent via the low-level DynamoDB API. Otherwise, the enhanced DynamoDB client is used.