Class VersionHelper
java.lang.Object
dev.hogwai.dynamodb.simplified.internal.VersionHelper
Helper for optimistic locking via version fields.
-
Method Summary
Modifier and TypeMethodDescriptionstatic @Nullable ConditionExpressionbuildCondition(@NonNull Object item) Builds a condition expression that verifies the version hasn't changed.static @Nullable IntegergetVersion(@NonNull Object item) Returns the version from an item with aVersionfield.static voidincrementVersion(@NonNull Object item) Increments the version on an item with aVersionfield.static <T> booleanisVersioned(@NonNull T item) Checks whether the given item has a field annotated withVersion.
-
Method Details
-
getVersion
-
incrementVersion
-
isVersioned
public static <T> boolean isVersioned(@NonNull T item) Checks whether the given item has a field annotated withVersion.- Type Parameters:
T- the item type- Parameters:
item- the item to check- Returns:
- true if the item has a @Version field
-
buildCondition
Builds a condition expression that verifies the version hasn't changed.For a new item (version == null or 0): attribute_not_exists(version) For an existing item (version > 0): version = :expectedVersion
- Parameters:
item- the item being written- Returns:
- a condition expression, or null if version is not applicable
-