Class AutoGeneratedUuidExtension
- All Implemented Interfaces:
DynamoDbEnhancedClientExtension
UUID.randomUUID().
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 use auto-generated UUID values, create a field in your model that stores the UUID attribute.
This field must be of type String, and you need to tag it as auto-generated UUID. 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.
Generation behavior is controlled by DynamoDbAutoGenerateStrategy:
ALWAYS: generate a new UUID on every write handled by this extension.CREATE: generate a UUID only when the current value is missing. For values present in the write item map, missing means DynamoDBNULL; an empty string is treated as present.
For a non-primary-key CREATE attribute omitted from an updateItem write item map, this extension uses
if_not_exists so DynamoDB applies the supplied UUID only when the stored attribute is absent. An existing stored
value, including DynamoDB NULL or an empty string, is preserved. In contrast, an explicit DynamoDB NULL in
the write item map is replaced with a generated UUID before the request is sent.
putItem remains a full replacement operation. Each putItem whose CREATE value is missing generates
a UUID, including a subsequent put using the same primary key.
UpdateBehavior is a separate concern used while building update
expressions for updateItem. It does not change this extension's strategy decision.
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionModifies the WriteModification UUID string with the attribute updated with the extension.static AutoGeneratedUuidExtensioncreate()Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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:
beforeWritein interfaceDynamoDbEnhancedClientExtension- Parameters:
context- TheDynamoDbExtensionContext.BeforeWritecontext containing the state of the execution.- Returns:
- WriteModification String updated with attribute updated with Extension.
-