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 the BeanTableSchema then you should use the DynamoDbAutoGeneratedTimestampAttribute annotation, otherwise if you are using the StaticTableSchema then you should use the AutoGeneratedTimestampRecordExtension.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.