Class AutoGeneratedUuidExtension
- All Implemented Interfaces:
DynamoDbEnhancedClientExtension
UUID.randomUUID()
method.
This extension is not loaded by default when you instantiate a
DynamoDbEnhancedClient
. Therefore, you need to specify it in a custom
extension when creating the enhanced client.
Example to add AutoGeneratedUuidExtension along with default extensions is
DynamoDbEnhancedClient.builder().extensions(Stream.concat(ExtensionResolver.defaultExtensions().stream(),
Stream.of(AutoGeneratedUuidExtension.create())).collect(Collectors.toList())).build();
Example to just add AutoGeneratedUuidExtension without default extensions is
DynamoDbEnhancedClient.builder().extensions(AutoGeneratedUuidExtension.create()).build();
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 String
, and you need to tag it as the autoGeneratedUuidAttribute. If you are
using the BeanTableSchema
, then you should use the
DynamoDbAutoGeneratedUuid
annotation. If you are using
the StaticTableSchema
, then you should use the
AutoGeneratedUuidExtension.AttributeTags.autoGeneratedUuidAttribute()
static attribute tag.
Every time a new record is successfully put into the database, the specified attribute will be automatically populated with a
unique UUID generated using UUID.randomUUID()
. If the UUID needs to be created only for `putItem` and should
not be generated for an `updateItem`, then
UpdateBehavior.WRITE_IF_NOT_EXISTS
must be along with
DynamoDbUpdateBehavior
-
Nested Class Summary
-
Method Summary
Modifier and TypeMethodDescriptionModifies the WriteModification UUID string with the attribute updated with the extension.static AutoGeneratedUuidExtension
create()
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClientExtension
afterRead
-
Method Details
-
create
- Returns:
- an Instance of
AutoGeneratedUuidExtension
-
beforeWrite
Modifies the WriteModification UUID string with the attribute updated with the extension.- Specified by:
beforeWrite
in interfaceDynamoDbEnhancedClientExtension
- Parameters:
context
- TheDynamoDbExtensionContext.BeforeWrite
context containing the state of the execution.- Returns:
- WriteModification String updated with attribute updated with Extension.
-