Skip to content

Commit 4e77124

Browse files
committed
Support update expressions in single request update
1 parent c260b66 commit 4e77124

File tree

3 files changed

+29
-30
lines changed

3 files changed

+29
-30
lines changed

services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/update/UpdateExpressionResolver.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import static software.amazon.awssdk.utils.CollectionUtils.filterMap;
2323

2424
import java.util.Arrays;
25+
import java.util.Collection;
2526
import java.util.Collections;
2627
import java.util.HashMap;
2728
import java.util.List;
@@ -88,7 +89,7 @@ public UpdateExpression resolve() {
8889
.orElse(null);
8990
}
9091

91-
private static Set<String> attributesPresentInOtherExpressions(List<UpdateExpression> updateExpressions) {
92+
private static Set<String> attributesPresentInOtherExpressions(Collection<UpdateExpression> updateExpressions) {
9293
return updateExpressions.stream()
9394
.filter(Objects::nonNull)
9495
.map(UpdateExpressionConverter::findAttributeNames)
@@ -106,7 +107,7 @@ public static UpdateExpression generateItemSetExpression(Map<String, AttributeVa
106107
}
107108

108109
public static UpdateExpression generateItemRemoveExpression(Map<String, AttributeValue> itemMap,
109-
Set<String> nonRemoveAttributes) {
110+
Collection<String> nonRemoveAttributes) {
110111
Map<String, AttributeValue> removeAttributes =
111112
filterMap(itemMap, e -> isNullAttributeValue(e.getValue()) && !nonRemoveAttributes.contains(e.getKey()));
112113

services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/model/TransactUpdateItemEnhancedRequest.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@
2222
import software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedAsyncClient;
2323
import software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClient;
2424
import software.amazon.awssdk.enhanced.dynamodb.Expression;
25-
import software.amazon.awssdk.enhanced.dynamodb.update.AddAction;
26-
import software.amazon.awssdk.enhanced.dynamodb.update.DeleteAction;
27-
import software.amazon.awssdk.enhanced.dynamodb.update.RemoveAction;
28-
import software.amazon.awssdk.enhanced.dynamodb.update.SetAction;
2925
import software.amazon.awssdk.enhanced.dynamodb.update.UpdateExpression;
3026
import software.amazon.awssdk.services.dynamodb.model.ReturnValuesOnConditionCheckFailure;
3127

@@ -247,19 +243,23 @@ public Builder<T> item(T item) {
247243
}
248244

249245
/**
250-
* Specifies custom update operations using DynamoDB's native update expression syntax. Enables advanced modifications
251-
* like incrementing counters or modifying lists/sets.
252-
* <p><b>Precedence:</b> Request expressions (highest) > Extension expressions > Item attributes (lowest).
253-
* This method overrides any conflicting operations from item attributes or extensions.
254-
* <p><b>Backward compatible:</b> New feature that doesn't affect existing behavior when not used.
246+
* Specifies custom update operations using DynamoDB's native update expression syntax.
247+
* <p>
248+
* <b>Precedence:</b> When performing an update, the final set of attribute modifications is determined as follows:
249+
* <ol>
250+
* <li><b>Request-level UpdateExpression</b> (set via this method) has the highest priority and overrides any
251+
* conflicting updates from extensions or POJO item attributes.</li>
252+
* <li><b>Extension-provided UpdateExpression</b> (if present) has medium priority and overrides conflicting updates
253+
* from POJO item attributes.</li>
254+
* <li><b>POJO item attributes</b> have the lowest priority; any conflicts with extension or request expressions are
255+
* overridden.</li>
256+
* </ol>
257+
* If the same attribute is updated by multiple sources, only the action from the highest-priority source is applied.
258+
* <p>
259+
* This method does not affect existing behavior if not used.
255260
*
256261
* @param updateExpression the update operations to perform
257262
* @return a builder of this type
258-
* @see UpdateExpression
259-
* @see SetAction
260-
* @see AddAction
261-
* @see RemoveAction
262-
* @see DeleteAction
263263
*/
264264
public Builder<T> updateExpression(UpdateExpression updateExpression) {
265265
this.updateExpression = updateExpression;

services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/model/UpdateItemEnhancedRequest.java

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@
2424
import software.amazon.awssdk.enhanced.dynamodb.DynamoDbAsyncTable;
2525
import software.amazon.awssdk.enhanced.dynamodb.DynamoDbTable;
2626
import software.amazon.awssdk.enhanced.dynamodb.Expression;
27-
import software.amazon.awssdk.enhanced.dynamodb.update.AddAction;
28-
import software.amazon.awssdk.enhanced.dynamodb.update.DeleteAction;
29-
import software.amazon.awssdk.enhanced.dynamodb.update.RemoveAction;
30-
import software.amazon.awssdk.enhanced.dynamodb.update.SetAction;
3127
import software.amazon.awssdk.enhanced.dynamodb.update.UpdateExpression;
3228
import software.amazon.awssdk.services.dynamodb.model.DeleteItemRequest;
3329
import software.amazon.awssdk.services.dynamodb.model.PutItemRequest;
@@ -332,21 +328,23 @@ public Builder<T> item(T item) {
332328
}
333329

334330
/**
335-
* Specifies custom update operations using DynamoDB's native update expression syntax. Enables advanced modifications
336-
* like incrementing counters or modifying lists/sets.
331+
* Specifies custom update operations using DynamoDB's native update expression syntax.
337332
* <p>
338-
* <b>Precedence:</b> Request expressions (highest) > Extension expressions > Item attributes (lowest).
339-
* This method overrides any conflicting operations from item attributes or extensions.
333+
* <b>Precedence:</b> When performing an update, the final set of attribute modifications is determined as follows:
334+
* <ol>
335+
* <li><b>Request-level UpdateExpression</b> (set via this method) has the highest priority and overrides any
336+
* conflicting updates from extensions or POJO item attributes.</li>
337+
* <li><b>Extension-provided UpdateExpression</b> (if present) has medium priority and overrides conflicting updates
338+
* from POJO item attributes.</li>
339+
* <li><b>POJO item attributes</b> have the lowest priority; any conflicts with extension or request expressions are
340+
* overridden.</li>
341+
* </ol>
342+
* If the same attribute is updated by multiple sources, only the action from the highest-priority source is applied.
340343
* <p>
341-
* <b>Backward compatible:</b> New feature that doesn't affect existing behavior when not used.
344+
* This method does not affect existing behavior if not used.
342345
*
343346
* @param updateExpression the update operations to perform
344347
* @return a builder of this type
345-
* @see UpdateExpression
346-
* @see SetAction
347-
* @see AddAction
348-
* @see RemoveAction
349-
* @see DeleteAction
350348
*/
351349
public Builder<T> updateExpression(UpdateExpression updateExpression) {
352350
this.updateExpression = updateExpression;

0 commit comments

Comments
 (0)