Class VersionedRecordExtension
- java.lang.Object
-
- software.amazon.awssdk.enhanced.dynamodb.extensions.VersionedRecordExtension
-
- All Implemented Interfaces:
DynamoDbEnhancedClientExtension
@ThreadSafe public final class VersionedRecordExtension extends Object implements DynamoDbEnhancedClientExtension
This extension implements optimistic locking on record writes by means of a 'record version number' that is used to automatically track each revision of the record as it is modified.This extension is loaded by default when you instantiate a
DynamoDbEnhancedClient
so unless you are using a custom extension there is no need to specify it.To utilize versioned record locking, first create an attribute in your model that will be used to store the record version number. This attribute must be an 'integer' type numeric (long or integer), and you need to tag it as the version attribute. If you are using the
BeanTableSchema
then you should use theDynamoDbVersionAttribute
annotation, otherwise if you are using theStaticTableSchema
then you should use theVersionedRecordExtension.AttributeTags.versionAttribute()
static attribute tag.Then, whenever a record is written the write operation will only succeed if the version number of the record has not been modified since it was last read by the application. Every time a new version of the record is successfully written to the database, the record version number will be automatically incremented.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
VersionedRecordExtension.AttributeTags
static class
VersionedRecordExtension.Builder
-
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 VersionedRecordExtension.Builder
builder()
-
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 VersionedRecordExtension.Builder builder()
-
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:
- A
WriteModification
object that can alter the behavior of the write operation.
-
-