Class AbstractPutBuilder<T, S extends AbstractPutBuilder<T,S>>

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

public abstract class AbstractPutBuilder<T, S extends AbstractPutBuilder<T,S>> extends Object
Abstract base for sync and async put-item builders.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    Optional condition expression that gates the put operation.
    protected final T
    The item to put.
    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 for the put operation.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    AbstractPutBuilder(@NonNull T item)
    Constructs a new AbstractPutBuilder with the item to put.
  • 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 software.amazon.awssdk.enhanced.dynamodb.model.PutItemEnhancedRequest<T>
    Builds a high-level PutItemEnhancedRequest with the item and optional condition expression.
    protected @NonNull software.amazon.awssdk.services.dynamodb.model.PutItemRequest
    buildLowLevelRequest(@NonNull Map<String, software.amazon.awssdk.services.dynamodb.model.AttributeValue> itemMap)
    Builds a low-level PutItemRequest from the given item attribute map, using the configured return values and condition expression.
    @NonNull S
    condition(@Nullable ConditionExpression condition)
    Configures a condition expression that gates the put operation.
    @NonNull S
    Configures a condition expression that gates the put operation.
    protected void
    Increments the version field on the item if optimistic locking is enabled.
    @NonNull S
    onlyIfNotExists(@NonNull String attribute)
    Adds a condition that the specified attribute must not already exist on an item with the same key for the put to succeed.
    @NonNull S
    returnValues(@Nullable software.amazon.awssdk.services.dynamodb.model.ReturnValue returnValues)
    Configures which item attributes to return after the put.
    protected abstract S
    Returns this typed as S for fluent chaining.
    protected abstract @NonNull String
    Returns the DynamoDB table name.
    @NonNull S
    Enables optimistic locking for this put 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 put.
    • conditionExpression

      protected ConditionExpression conditionExpression
      Optional condition expression that gates the put operation.
    • returnValues

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

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

    • AbstractPutBuilder

      protected AbstractPutBuilder(@NonNull T item)
      Constructs a new AbstractPutBuilder with the item to put.
      Parameters:
      item - the item to put
  • Method Details

    • self

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

      public @NonNull S condition(@NonNull Consumer<ConditionExpression.Builder> configurator)
      Configures a condition expression that gates the put operation. DynamoDB evaluates this condition before writing 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 put operation. DynamoDB evaluates this condition before writing the item (unlike a filter expression which applies after reading).
      Parameters:
      condition - the condition expression
      Returns:
      this builder for chaining
    • onlyIfNotExists

      public @NonNull S onlyIfNotExists(@NonNull String attribute)
      Adds a condition that the specified attribute must not already exist on an item with the same key for the put to succeed.
      Parameters:
      attribute - the attribute name to check for absence
      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 put.

      When set, uses the low-level PutItemRequest with the specified ReturnValues. Common values: ReturnValue.ALL_OLD (returns the previous item if one existed), ReturnValue.NONE.

      To retrieve the previous item when using ReturnValue#ALL_OLD, use executeReturning() instead of execute().

      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 put operation.

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

      Returns:
      this builder for chaining
    • applyOptimisticLocking

      protected void applyOptimisticLocking()
      Applies optimistic locking by merging a version condition into the existing condition expression (if any).
    • incrementVersion

      protected void incrementVersion()
      Increments the version field on the item if optimistic locking is enabled.
    • buildEnhancedRequest

      protected @NonNull software.amazon.awssdk.enhanced.dynamodb.model.PutItemEnhancedRequest<T> buildEnhancedRequest()
      Builds a high-level PutItemEnhancedRequest with the item and optional condition expression.
      Returns:
      the built enhanced request
    • buildLowLevelRequest

      protected @NonNull software.amazon.awssdk.services.dynamodb.model.PutItemRequest buildLowLevelRequest(@NonNull Map<String, software.amazon.awssdk.services.dynamodb.model.AttributeValue> itemMap)
      Builds a low-level PutItemRequest from the given item attribute map, using the configured return values and condition expression.
      Parameters:
      itemMap - the item attribute map
      Returns:
      the built low-level request
    • tableName

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