Class VersionHelper

java.lang.Object
dev.hogwai.dynamodb.simplified.internal.VersionHelper

public final class VersionHelper extends Object
Helper for optimistic locking via version fields.
  • Method Details

    • getVersion

      public static @Nullable Integer getVersion(@NonNull Object item)
      Returns the version from an item with a Version field.
      Parameters:
      item - the item to check
      Returns:
      the version, or null if the item has no version field or version is null
    • incrementVersion

      public static void incrementVersion(@NonNull Object item)
      Increments the version on an item with a Version field.
      Parameters:
      item - the item to update
    • isVersioned

      public static <T> boolean isVersioned(@NonNull T item)
      Checks whether the given item has a field annotated with Version.
      Type Parameters:
      T - the item type
      Parameters:
      item - the item to check
      Returns:
      true if the item has a @Version field
    • buildCondition

      public static @Nullable ConditionExpression buildCondition(@NonNull Object item)
      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