Skip to content

Instantly share code, notes, and snippets.

@wreulicke
Last active November 10, 2017 07:57
Show Gist options
  • Save wreulicke/59aaf6a0bd7aed559d25b5ce5b9d0943 to your computer and use it in GitHub Desktop.
Save wreulicke/59aaf6a0bd7aed559d25b5ce5b9d0943 to your computer and use it in GitHub Desktop.
interface Versioned {
long getVersion();
void verifyVersion(Long version) default {
if (version == null) return;
if(getVersion() != version) throw new OptimisticLockFailureException("Unable to lock");
}
void setVersion(long version);
long incrementVersion() default {
long next = getVersion() + 1;
setVersion(next);
return next;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment