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 typeS- the concrete builder type (for fluent chaining)
- Direct Known Subclasses:
AsyncUpdateBuilder, UpdateBuilder
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
FieldsModifier and TypeFieldDescriptionprotected ConditionExpressionOptional condition expression that gates the update operation.protected booleanWhether to ignore null attributes in full-item replacement.protected final TThe item to update, ornullfor key-only partial updates.Pre-built key map for key-only update path.protected static final org.slf4j.LoggerLogger for this builder class.protected booleanWhether optimistic locking is enabled.protected software.amazon.awssdk.services.dynamodb.model.ReturnValueOptional return values setting.protected UpdateExpressionOptional update expression for partial updates. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedNo-arg constructor for the key-only path (partial updates without a full item).protectedAbstractUpdateBuilder(@NonNull T item) Constructs a newAbstractUpdateBuilderwith an item for full-item replacement or as a template for partial updates. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidApplies optimistic locking by merging a version condition into the existing condition expression (if any).Builds a key map for low-level update requests from the item or from a pre-built key map (set viabuildKeyMapFromValues(Object, Object)).protected final voidbuildKeyMapFromValues(@NonNull Object partitionKey, @Nullable Object sortKey) Builds a key map directly from partition and sort key values and stores it for later use bybuildKeyMap().@NonNull Scondition(@Nullable ConditionExpression condition) Configures a condition expression that gates the update operation.@NonNull Scondition(@NonNull Consumer<ConditionExpression.Builder> configurator) Configures a condition expression that gates the update operation.protected abstract @NonNull software.amazon.awssdk.enhanced.dynamodb.KeyReturns aKeybuilt from the current item.protected abstract @NonNull software.amazon.awssdk.enhanced.dynamodb.TableSchema<T> Returns the table schema for the item type.@NonNull SignoreNulls(boolean ignoreNulls) Controls whether null-valued attributes in the item are ignored during full-item replacement.protected voidIncrements the version field on the item if optimistic locking is enabled and the item is not null.@NonNull SreturnValues(@Nullable software.amazon.awssdk.services.dynamodb.model.ReturnValue returnValues) Configures which item attributes to return after the update.protected abstract Sself()Returnsthistyped asSfor fluent chaining.protected abstract @NonNull StringReturns the DynamoDB table name.@NonNull Supdate(@NonNull Consumer<UpdateExpression> updateBuilder) Defines a partial update expression (SET,REMOVE,ADD,DELETE).@NonNull SEnables optimistic locking for this update operation.
-
Field Details
-
LOG
protected static final org.slf4j.Logger LOGLogger for this builder class. -
item
The item to update, ornullfor key-only partial updates. -
keyMap
-
updateExpression
Optional update expression for partial updates. -
conditionExpression
Optional condition expression that gates the update operation. -
ignoreNulls
protected boolean ignoreNullsWhether to ignore null attributes in full-item replacement. -
returnValues
protected software.amazon.awssdk.services.dynamodb.model.ReturnValue returnValuesOptional return values setting. -
optimisticLocking
protected boolean optimisticLockingWhether optimistic locking is enabled.
-
-
Constructor Details
-
AbstractUpdateBuilder
Constructs a newAbstractUpdateBuilderwith 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 callbuildKeyMapFromValues(Object, Object)after setting up the table reference.
-
-
Method Details
-
self
-
tableName
Returns the DynamoDB table name.- Returns:
- the DynamoDB table name
-
getKeyFromItem
protected abstract @NonNull software.amazon.awssdk.enhanced.dynamodb.Key getKeyFromItem()Returns aKeybuilt 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
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 theUpdateExpression- Returns:
- this builder for chaining
-
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:
configurator- a consumer to build the condition expression- Returns:
- this builder for chaining
-
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
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,falseto 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
ReturnValuesparameter of the underlyingUpdateItemRequest. 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, ornullto use the default- Returns:
- this builder for chaining
-
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 isnull(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 viabuildKeyMapFromValues(Object, Object)).- Returns:
- the key attribute map
-
buildKeyMapFromValues
Builds a key map directly from partition and sort key values and stores it for later use bybuildKeyMap(). Used by the key-only constructor path.- Parameters:
partitionKey- the partition key valuesortKey- the sort key value, ornullif the table has no sort key
-