Class AbstractUpdateBuilder<T, S extends AbstractUpdateBuilder<T,S>>

java.lang.Object
dev.hogwai.dynamodb.simplified.builder.base.AbstractUpdateBuilder<T,S>
Type Parameters:
T - the item type
S - the concrete builder type (for fluent chaining)
Direct Known Subclasses:
AsyncUpdateBuilder, UpdateBuilder

public abstract class AbstractUpdateBuilder<T, S extends AbstractUpdateBuilder<T,S>> extends Object
Abstract base for sync and async update-item builders.

Supports both full-item replacement and partial updates via an UpdateExpression. Concrete subclasses provide the DynamoDB table and client references and implement the execute logic.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    Optional condition expression that gates the update operation.
    protected boolean
    Whether to ignore null attributes in full-item replacement.
    protected final T
    The item to update, or null for key-only partial updates.
    protected @Nullable Map<String, software.amazon.awssdk.services.dynamodb.model.AttributeValue>
    Pre-built key map for key-only update path.
    protected static final org.slf4j.Logger
    Logger for this builder class.
    protected boolean
    Whether optimistic locking is enabled.
    protected software.amazon.awssdk.services.dynamodb.model.ReturnValue
    Optional return values setting.
    Optional update expression for partial updates.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    No-arg constructor for the key-only path (partial updates without a full item).
    protected
    AbstractUpdateBuilder(@NonNull T item)
    Constructs a new AbstractUpdateBuilder with an item for full-item replacement or as a template for partial updates.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    Applies optimistic locking by merging a version condition into the existing condition expression (if any).
    protected @NonNull Map<String, software.amazon.awssdk.services.dynamodb.model.AttributeValue>
    Builds a key map for low-level update requests from the item or from a pre-built key map (set via buildKeyMapFromValues(Object, Object)).
    protected final void
    buildKeyMapFromValues(@NonNull Object partitionKey, @Nullable Object sortKey)
    Builds a key map directly from partition and sort key values and stores it for later use by buildKeyMap().
    @NonNull S
    condition(@Nullable ConditionExpression condition)
    Configures a condition expression that gates the update operation.
    @NonNull S
    Configures a condition expression that gates the update operation.
    protected abstract @NonNull software.amazon.awssdk.enhanced.dynamodb.Key
    Returns a Key built from the current item.
    protected abstract @NonNull software.amazon.awssdk.enhanced.dynamodb.TableSchema<T>
    Returns the table schema for the item type.
    @NonNull S
    ignoreNulls(boolean ignoreNulls)
    Controls whether null-valued attributes in the item are ignored during full-item replacement.
    protected void
    Increments the version field on the item if optimistic locking is enabled and the item is not null.
    @NonNull S
    returnValues(@Nullable software.amazon.awssdk.services.dynamodb.model.ReturnValue returnValues)
    Configures which item attributes to return after the update.
    protected abstract S
    Returns this typed as S for fluent chaining.
    protected abstract @NonNull String
    Returns the DynamoDB table name.
    @NonNull S
    update(@NonNull Consumer<UpdateExpression> updateBuilder)
    Defines a partial update expression (SET, REMOVE, ADD, DELETE).
    @NonNull S
    Enables optimistic locking for this update operation.

    Methods inherited from class Object

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

    • LOG

      protected static final org.slf4j.Logger LOG
      Logger for this builder class.
    • item

      protected final T item
      The item to update, or null for key-only partial updates.
    • keyMap

      protected @Nullable Map<String, software.amazon.awssdk.services.dynamodb.model.AttributeValue> keyMap
      Pre-built key map for key-only update path.
    • updateExpression

      protected UpdateExpression updateExpression
      Optional update expression for partial updates.
    • conditionExpression

      protected ConditionExpression conditionExpression
      Optional condition expression that gates the update operation.
    • ignoreNulls

      protected boolean ignoreNulls
      Whether to ignore null attributes in full-item replacement.
    • returnValues

      protected software.amazon.awssdk.services.dynamodb.model.ReturnValue returnValues
      Optional return values setting.
    • optimisticLocking

      protected boolean optimisticLocking
      Whether optimistic locking is enabled.
  • Constructor Details

    • AbstractUpdateBuilder

      protected AbstractUpdateBuilder(@NonNull T item)
      Constructs a new AbstractUpdateBuilder with an item for full-item replacement or as a template for partial updates.
      Parameters:
      item - the item to update
    • AbstractUpdateBuilder

      protected AbstractUpdateBuilder()
      No-arg constructor for the key-only path (partial updates without a full item). Subclasses must call buildKeyMapFromValues(Object, Object) after setting up the table reference.
  • Method Details

    • self

      protected abstract S self()
      Returns this typed as S for fluent chaining.
      Returns:
      this builder
    • tableName

      protected abstract @NonNull String tableName()
      Returns the DynamoDB table name.
      Returns:
      the DynamoDB table name
    • getKeyFromItem

      protected abstract @NonNull software.amazon.awssdk.enhanced.dynamodb.Key getKeyFromItem()
      Returns a Key built from the current item. Used internally to build key maps for partial update requests.
      Returns:
      the key derived from the item
    • getTableSchema

      protected abstract @NonNull software.amazon.awssdk.enhanced.dynamodb.TableSchema<T> getTableSchema()
      Returns the table schema for the item type. Used internally for key and attribute conversion.
      Returns:
      the table schema
    • update

      public @NonNull S update(@NonNull Consumer<UpdateExpression> updateBuilder)
      Defines a partial update expression (SET, REMOVE, ADD, DELETE). When set, this replaces the full-item replacement with a targeted partial update.
      Parameters:
      updateBuilder - a consumer that configures the UpdateExpression
      Returns:
      this builder for chaining
    • condition

      public @NonNull S condition(@NonNull Consumer<ConditionExpression.Builder> configurator)
      Configures a condition expression that gates the update operation. DynamoDB evaluates this condition before updating the item (unlike a filter expression which applies after reading).
      Parameters:
      configurator - a consumer to build the condition expression
      Returns:
      this builder for chaining
    • condition

      public @NonNull S condition(@Nullable ConditionExpression condition)
      Configures a condition expression that gates the update operation. DynamoDB evaluates this condition before updating the item (unlike a filter expression which applies after reading).
      Parameters:
      condition - the condition expression
      Returns:
      this builder for chaining
    • ignoreNulls

      public @NonNull S ignoreNulls(boolean ignoreNulls)
      Controls whether null-valued attributes in the item are ignored during full-item replacement. Has no effect when using a partial update expression.
      Parameters:
      ignoreNulls - true (default) to skip null attributes, false to persist them
      Returns:
      this builder for chaining
    • returnValues

      public @NonNull S returnValues(@Nullable software.amazon.awssdk.services.dynamodb.model.ReturnValue returnValues)
      Configures which item attributes to return after the update.

      When set, controls the ReturnValues parameter of the underlying UpdateItemRequest. Common values: ReturnValue.ALL_NEW (default if not set), ReturnValue.NONE, ReturnValue.ALL_OLD, ReturnValue.UPDATED_NEW, ReturnValue.UPDATED_OLD.

      Parameters:
      returnValues - the return value setting, or null to use the default
      Returns:
      this builder for chaining
    • withOptimisticLocking

      public @NonNull S withOptimisticLocking()
      Enables optimistic locking for this update operation.

      When enabled, the library adds a condition expression checking that the version attribute hasn't changed, and increments the version on success.

      This is only supported for full-item replacement. For partial updates (update(Consumer)), the item must be provided in the constructor.

      Returns:
      this builder for chaining
    • applyOptimisticLocking

      protected void applyOptimisticLocking()
      Applies optimistic locking by merging a version condition into the existing condition expression (if any). Has no effect when the item is null (key-only update) or when optimistic locking is not enabled.
    • incrementVersion

      protected void incrementVersion()
      Increments the version field on the item if optimistic locking is enabled and the item is not null.
    • buildKeyMap

      protected @NonNull Map<String, software.amazon.awssdk.services.dynamodb.model.AttributeValue> buildKeyMap()
      Builds a key map for low-level update requests from the item or from a pre-built key map (set via buildKeyMapFromValues(Object, Object)).
      Returns:
      the key attribute map
    • buildKeyMapFromValues

      protected final void buildKeyMapFromValues(@NonNull Object partitionKey, @Nullable Object sortKey)
      Builds a key map directly from partition and sort key values and stores it for later use by buildKeyMap(). Used by the key-only constructor path.
      Parameters:
      partitionKey - the partition key value
      sortKey - the sort key value, or null if the table has no sort key