Class AutoGeneratedTimestampRecordExtension
- java.lang.Object
-
- software.amazon.awssdk.enhanced.dynamodb.extensions.AutoGeneratedTimestampRecordExtension
-
- All Implemented Interfaces:
DynamoDbEnhancedClientExtension
@ThreadSafe public final class AutoGeneratedTimestampRecordExtension extends Object implements DynamoDbEnhancedClientExtension
This extension enables selected attributes to be automatically updated with a current timestamp every time they are written to the database.This extension is not loaded by default when you instantiate a
DynamoDbEnhancedClient
. Thus you need to specify it in custom extension while creating the enhanced client.Example to add AutoGeneratedTimestampRecordExtension along with default extensions is
DynamoDbEnhancedClient.builder().extensions(Stream.concat(ExtensionResolver.defaultExtensions().stream(), Stream.of(AutoGeneratedTimestampRecordExtension.create())).collect(Collectors.toList())).build();
Example to just add AutoGeneratedTimestampRecordExtension without default extensions is
DynamoDbEnhancedClient.builder().extensions(AutoGeneratedTimestampRecordExtension.create())).build();
To utilize auto generated timestamp update, first create a field in your model that will be used to store the record timestamp of modification. This class field must be an
Instant
Class type, and you need to tag it as the autoGeneratedTimeStampAttribute. If you are using theBeanTableSchema
then you should use theDynamoDbAutoGeneratedTimestampAttribute
annotation, otherwise if you are using theStaticTableSchema
then you should use theAutoGeneratedTimestampRecordExtension.AttributeTags.autoGeneratedTimestampAttribute()
static attribute tag.Every time a new update of the record is successfully written to the database, the timestamp at which it was modified will be automatically updated. This extension applies the conversions as defined in the attribute convertor.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
AutoGeneratedTimestampRecordExtension.AttributeTags
Attribute tag to identify the meta data forAutoGeneratedTimestampRecordExtension
.static class
AutoGeneratedTimestampRecordExtension.Builder
Builder for aAutoGeneratedTimestampRecordExtension
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description WriteModification
beforeWrite(DynamoDbExtensionContext.BeforeWrite context)
This hook is called just before an operation is going to write data to the database.static AutoGeneratedTimestampRecordExtension.Builder
builder()
Create a builder that can be used to create aAutoGeneratedTimestampRecordExtension
.static AutoGeneratedTimestampRecordExtension
create()
AutoGeneratedTimestampRecordExtension.Builder
toBuilder()
Returns a builder initialized with all existing values on the Extension object.-
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
-
builder
public static AutoGeneratedTimestampRecordExtension.Builder builder()
Create a builder that can be used to create aAutoGeneratedTimestampRecordExtension
.- Returns:
- Builder to create AutoGeneratedTimestampRecordExtension,
-
toBuilder
public AutoGeneratedTimestampRecordExtension.Builder toBuilder()
Returns a builder initialized with all existing values on the Extension object.
-
create
public static AutoGeneratedTimestampRecordExtension create()
- Returns:
- an Instance of
AutoGeneratedTimestampRecordExtension
-
beforeWrite
public WriteModification beforeWrite(DynamoDbExtensionContext.BeforeWrite context)
Description copied from interface:DynamoDbEnhancedClientExtension
This hook is called just before an operation is going to write data to the database. The extension that implements this method can choose to transform the item itself, or add a condition to the write operation or both.- Specified by:
beforeWrite
in interfaceDynamoDbEnhancedClientExtension
- Parameters:
context
- TheDynamoDbExtensionContext.BeforeWrite
context containing the state of the execution.- Returns:
- WriteModification Instance updated with attribute updated with Extension.
-
-