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
feat(6418): Add customizable UUID supplier in AutoGeneratedUuidExtension
- Introduced a customizable `uuidSupplier` in `AutoGeneratedUuidExtension` with default `UUID.randomUUID()` functionality.
- Added a builder pattern to create extensions with custom suppliers.
- Enhanced tests to validate the custom UUID supplier functionality and maintain backward compatibility.
- Refactoring all tests and add more scenarios;
- Fixing AutoGeneratedUuidExtension`s JavaDoc
Copy file name to clipboardExpand all lines: services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/extensions/AutoGeneratedUuidExtension.java
* This extension facilitates the automatic generation of a unique UUID (Universally Unique Identifier) for a specified attribute
39
-
* every time a new record is written to the database. The generated UUID is obtained using the
40
-
* {@link java.util.UUID#randomUUID()} method.
39
+
* This extension facilitates the automatic generation of a unique UUID (Universally Unique Identifier) for a specified attribute every time a new record is
40
+
* written to the database. The generated UUID is obtained using the {@link java.util.UUID#randomUUID()} method by default or a custom UUID supplier instance
41
+
* provided by the user.
41
42
* <p>
42
-
* This extension is not loaded by default when you instantiate a
43
-
* {@link software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClient}. Therefore, you need to specify it in a custom
44
-
* extension when creating the enhanced client.
43
+
* This extension is not loaded by default when you instantiate a {@link software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClient}. Therefore, you need
44
+
* to specify it in a custom extension when creating the enhanced client.
45
45
* <p>
46
46
* Example to add AutoGeneratedUuidExtension along with default extensions is
* To utilize the auto-generated UUID feature, first, create a field in your model that will store the UUID for the attribute. This class field must be of type
57
+
* {@link java.lang.String}, and you need to tag it as the autoGeneratedUuidAttribute. If you are using the
58
+
* {@link software.amazon.awssdk.enhanced.dynamodb.mapper.BeanTableSchema}, then you should use the
59
+
* {@link software.amazon.awssdk.enhanced.dynamodb.extensions.annotations.DynamoDbAutoGeneratedUuid} annotation. If you are using the
60
+
* {@link software.amazon.awssdk.enhanced.dynamodb.mapper.StaticTableSchema}, then you should use the {@link AttributeTags#autoGeneratedUuidAttribute()} static
61
+
* attribute tag.
67
62
* </p>
68
63
* <p>
69
-
* Every time a new record is successfully put into the database, the specified attribute will be automatically populated with a
70
-
* unique UUID generated using {@link java.util.UUID#randomUUID()}. If the UUID needs to be created only for `putItem` and should
71
-
* not be generated for an `updateItem`, then
72
-
* {@link software.amazon.awssdk.enhanced.dynamodb.mapper.UpdateBehavior#WRITE_IF_NOT_EXISTS} must be along with
73
-
* {@link DynamoDbUpdateBehavior}
74
-
*
64
+
* Every time a new record is successfully put into the database, the specified attribute will be automatically populated with a unique UUID generated using
65
+
* {@link java.util.UUID#randomUUID()}.
66
+
* </br>
67
+
* If the UUID needs to be created only for `putItem` and should not be generated for an `updateItem`, then
68
+
* {@link software.amazon.awssdk.enhanced.dynamodb.mapper.UpdateBehavior#WRITE_IF_NOT_EXISTS} must be along with {@link DynamoDbUpdateBehavior}.
* Builder for a {@link AutoGeneratedUuidExtension}
182
+
*/
183
+
@NotThreadSafe
184
+
publicstaticfinalclassBuilder {
185
+
186
+
privateSupplier<UUID> uuidSupplier;
187
+
188
+
privateBuilder() {
189
+
}
190
+
191
+
/**
192
+
* Sets the UUID supplier instance , else {@link UUID#randomUUID()} is used by default. Every time a new UUID is generated this supplier will be used to
193
+
* get the current UUID. If a custom supplier is not specified, the default randomUUID supplier will be used.
194
+
*
195
+
* @param uuidSupplier Supplier instance to set the current UUID.
0 commit comments