aws-sdk-java-v2 icon indicating copy to clipboard operation
aws-sdk-java-v2 copied to clipboard

DDB Enhanced: Allow custom versioning

Open RanVaknin opened this issue 9 months ago • 2 comments

Motivation and Context

This PR builds on the work started in issue #3894 where the VersionedRecordExtension didn't support starting version numbers at 0, requiring clients to use Integer objects (with null initial values) rather than long primitives. As mentioned by @akiesler in the original issue, developers might expect versions to start at 0 and increment from there, rather than having a special case where the value must be initialized to null.

This implementation allows the extension to be more flexible by allowing:

  • Starting versions at 0 (or any non-negative long)
  • Configuring custom increment values (only positive numbers)
  • Supporting these configs both at the extension level and via annotations

Modifications

  • Refactored the VersionedRecordExtension to support explicit startAt and incrementBy values via builder methods (making it opt-in).
  • Expanded the DynamoDbVersionAttribute annotation to support startAt and incrementBy parameters
  • Added validation to prevent negative startAt values and non-positive incrementBy values

Testing

  • Custom startAt and incrementBy values through both builder and annotations
  • Validation of illegal values (negative startAt, zero/negative incrementBy)
  • Precedence rules between annotation and builder configurations
  • Version incrementation for both initial and existing records
  • Edge cases with different configuration combinations

RanVaknin avatar Apr 09 '25 22:04 RanVaknin

Thank you for picking up this change! It will greatly simplify our version handling. Please let me know if I can do anything to help.

akiesler avatar Apr 15 '25 20:04 akiesler

Fixed edge case in the isInitialVersion function. Previously it was not evaluating the precedence that annotation values should take over builder values.

This caused inconsistent behavior when both annotation and builder values were both provided with different values, potentially treating records as initial versions incorrectly when their version matched the builder's startAt value but not the annotation's value.

This is now fixed. Added a test case that combines input from both the builder and the annotation.

RanVaknin avatar Jul 17 '25 22:07 RanVaknin

This pull request has been closed and the conversation has been locked. Comments on closed PRs are hard for our team to see. If you need more assistance, please open a new issue that references this one.

github-actions[bot] avatar Jul 22 '25 19:07 github-actions[bot]