You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/extensions/AutoGeneratedKeyExtension.java
+44-11Lines changed: 44 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -42,6 +42,14 @@
42
42
* Generates a random UUID (via {@link java.util.UUID#randomUUID()}) for any attribute tagged with
43
43
* {@code @DynamoDbAutoGeneratedKey} when that attribute is missing or empty on a write (put/update).
44
44
* <p>
45
+
* <b>Key Difference from @DynamoDbAutoGeneratedUuid:</b> This extension only generates UUIDs when the
46
+
* attribute value is null or empty, preserving existing values. In contrast, {@code @DynamoDbAutoGeneratedUuid}
47
+
* always generates new UUIDs regardless of existing values.
48
+
* <p>
49
+
* <b>Conflict Detection:</b> This extension cannot be used together with {@code @DynamoDbAutoGeneratedUuid} on the same
50
+
* attribute. If both annotations are applied to the same field, an {@link IllegalArgumentException} will be thrown
51
+
* at runtime to prevent unpredictable behavior based on extension load order.
52
+
* <p>
45
53
* The annotation may be placed <b>only</b> on key attributes:
46
54
* <ul>
47
55
* <li>Primary partition key (PK) or primary sort key (SK)</li>
@@ -51,6 +59,9 @@
51
59
* <p><b>Validation:</b> The extension enforces this at runtime during {@link #beforeWrite} by comparing the
52
60
* annotated attributes against the table's known key attributes. If an annotated attribute
53
61
* is not a PK/SK or an GSI/LSI, an {@link IllegalArgumentException} is thrown.</p>
62
+
*
63
+
* <p><b>UpdateBehavior Limitations:</b> {@code @DynamoDbUpdateBehavior} has no effect on primary keys due to
64
+
* DynamoDB's UpdateItem API requirements. It only affects secondary index keys.</p>
54
65
*/
55
66
@SdkPublicApi
56
67
@ThreadSafe
@@ -62,6 +73,12 @@ public final class AutoGeneratedKeyExtension implements DynamoDbEnhancedClientEx
Copy file name to clipboardExpand all lines: services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/extensions/AutoGeneratedUuidExtension.java
+30-2Lines changed: 30 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -39,6 +39,14 @@
39
39
* every time a new record is written to the database. The generated UUID is obtained using the
40
40
* {@link java.util.UUID#randomUUID()} method.
41
41
* <p>
42
+
* <b>Key Difference from @DynamoDbAutoGeneratedKey:</b> This extension always generates new UUIDs on every write,
43
+
* regardless of existing values. In contrast, {@code @DynamoDbAutoGeneratedKey} only generates UUIDs when the
44
+
* attribute value is null or empty, preserving existing values.
45
+
* <p>
46
+
* <b>Conflict Detection:</b> This extension cannot be used together with {@code @DynamoDbAutoGeneratedKey} on the same
47
+
* attribute. If both annotations are applied to the same field, an {@link IllegalArgumentException} will be thrown
48
+
* at runtime to prevent unpredictable behavior.
49
+
* <p>
42
50
* This extension is not loaded by default when you instantiate a
43
51
* {@link software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClient}. Therefore, you need to specify it in a custom
Copy file name to clipboardExpand all lines: services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/extensions/annotations/DynamoDbAutoGeneratedKey.java
Copy file name to clipboardExpand all lines: services-custom/dynamodb-enhanced/src/test/java/software/amazon/awssdk/enhanced/dynamodb/extensions/AutoGeneratedKeyExtensionTest.java
+115Lines changed: 115 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -251,6 +251,121 @@ public void autoGeneratedKey_onNonKey_throwsIllegalArgumentException() {
0 commit comments