Class AutoGeneratedUuidExtension
- java.lang.Object
-
- software.amazon.awssdk.enhanced.dynamodb.extensions.AutoGeneratedUuidExtension
-
- All Implemented Interfaces:
DynamoDbEnhancedClientExtension
@ThreadSafe public final class AutoGeneratedUuidExtension extends Object implements DynamoDbEnhancedClientExtension
This extension facilitates the automatic generation of a unique UUID (Universally Unique Identifier) for a specified attribute every time a new record is written to the database. The generated UUID is obtained using theUUID.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
Example to just add AutoGeneratedUuidExtension without 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
String
, and you need to tag it as the autoGeneratedUuidAttribute. If you are using theBeanTableSchema
, then you should use theDynamoDbAutoGeneratedUuid
annotation. If you are using theStaticTableSchema
, then you should use theAutoGeneratedUuidExtension.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`, thenUpdateBehavior.WRITE_IF_NOT_EXISTS
must be along withDynamoDbUpdateBehavior
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
AutoGeneratedUuidExtension.AttributeTags
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description WriteModification
beforeWrite(DynamoDbExtensionContext.BeforeWrite context)
Modifies the WriteModification UUID string with the attribute updated with the extension.static AutoGeneratedUuidExtension
create()
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClientExtension
afterRead
-
-
-
-
Method Detail
-
create
public static AutoGeneratedUuidExtension create()
- Returns:
- an Instance of
AutoGeneratedUuidExtension
-
beforeWrite
public WriteModification beforeWrite(DynamoDbExtensionContext.BeforeWrite context)
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.
-
-