Optimistic locking differences between version 1 and version 2 of the SDK for Java
Both V1 and V2 implement optimistic locking with an attribute annotation that marks one property on your bean class to store the version number.
V1 | V2 | |
---|---|---|
Bean class annotation | @DynamoDBVersionAttribute |
@DynamoDbVersionAttribute (note that V2 uses a lowercase
"b") |
Initial save | Version number attribute set to 1. |
The starting value for the version attribute set with
|
Update | The version number attribute is incremented by 1 if the conditional check verifies that the version number of the object being updated matches the number in the database. |
The version number attribute is incremented if the conditional check verifies that the version number of the object being updated matches the number in the database. The version number attribute incremented by the
|
Delete | DynamoDBMapper adds a conditional check that the version
number of the object being deleted matches the version number in the
database. |
V2 does not does not automatically add conditions for the delete operations. You must add condition expressions manually if you want to control the delete behavior. In the following example
|
Transactional Write with a Condition Check | You cannot use a bean class that is
annotated with @DynamoDBVersionAttribute in an
addConditionCheck method. |
You can use a bean class with the
@DynamoDbVersionAttribute annotation in an
addConditionCheck builder method for a
transactWriteItems request. |
Disable | Disable optimistic locking by changing the
DynamoDBMapperConfig.SaveBehavior enumeration value from
UPDATE to CLOBBER . |
Do not use the |