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 typeS- the concrete builder type (for fluent chaining)
- Direct Known Subclasses:
AsyncPutBuilder, PutBuilder
Abstract base for sync and async put-item builders.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ConditionExpressionOptional condition expression that gates the put operation.protected final TThe item to put.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 for the put operation. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractPutBuilder(@NonNull T item) Constructs a newAbstractPutBuilderwith the item to put. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidApplies 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-levelPutItemEnhancedRequestwith the item and optional condition expression.protected @NonNull software.amazon.awssdk.services.dynamodb.model.PutItemRequestbuildLowLevelRequest(@NonNull Map<String, software.amazon.awssdk.services.dynamodb.model.AttributeValue> itemMap) Builds a low-levelPutItemRequestfrom the given item attribute map, using the configured return values and condition expression.@NonNull Scondition(@Nullable ConditionExpression condition) Configures a condition expression that gates the put operation.@NonNull Scondition(@NonNull Consumer<ConditionExpression.Builder> configurator) Configures a condition expression that gates the put operation.protected voidIncrements the version field on the item if optimistic locking is enabled.@NonNull SonlyIfNotExists(@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 SreturnValues(@Nullable software.amazon.awssdk.services.dynamodb.model.ReturnValue returnValues) Configures which item attributes to return after the put.protected abstract Sself()Returnsthistyped asSfor fluent chaining.protected abstract @NonNull StringReturns the DynamoDB table name.@NonNull SEnables optimistic locking for this put operation.
-
Field Details
-
LOG
protected static final org.slf4j.Logger LOGLogger for this builder class. -
item
The item to put. -
conditionExpression
Optional condition expression that gates the put operation. -
returnValues
protected software.amazon.awssdk.services.dynamodb.model.ReturnValue returnValuesOptional return values setting for the put operation. -
optimisticLocking
protected boolean optimisticLockingWhether optimistic locking is enabled.
-
-
Constructor Details
-
AbstractPutBuilder
Constructs a newAbstractPutBuilderwith the item to put.- Parameters:
item- the item to put
-
-
Method Details
-
self
-
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:
configurator- a consumer to build the condition expression- Returns:
- this builder for chaining
-
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
-
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
PutItemRequestwith the specifiedReturnValues. Common values:ReturnValue.ALL_OLD(returns the previous item if one existed),ReturnValue.NONE.To retrieve the previous item when using
ReturnValue#ALL_OLD, useexecuteReturning()instead ofexecute().- Parameters:
returnValues- the return value setting, ornullto use the default- Returns:
- this builder for chaining
-
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-levelPutItemEnhancedRequestwith 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-levelPutItemRequestfrom 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
Returns the DynamoDB table name.- Returns:
- the DynamoDB table name
-