updated versioning to cover bases types, added gitea support
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
package com.binarygolem.clotho.model;
|
||||
|
||||
/**
|
||||
* A manual version guard for version-checked writes on graph elements that are not
|
||||
* mapped to a registered Clotho entity class — such as {@link GenericVertex},
|
||||
* {@link GenericEdge}, or any vertex/edge from an unregistered label.
|
||||
*
|
||||
* <p>Use the factory methods {@link #onVertex} and {@link #onEdge} for clarity.
|
||||
* The default version property name ({@value #DEFAULT_VERSION_PROPERTY}) matches
|
||||
* the default value of {@code @Version}.
|
||||
*
|
||||
* <p>Example — version-checked write on an unregistered vertex:
|
||||
* <pre>{@code
|
||||
* // Read the version from the graph
|
||||
* long v = (long) executeRaw(g().V(id.asString()).values("_version")).get(0);
|
||||
*
|
||||
* session.executeUpdate(
|
||||
* g().V(id.asString()).property("status", "archived"),
|
||||
* VersionGuard.onVertex(id, v)
|
||||
* );
|
||||
* }</pre>
|
||||
*
|
||||
* <p>After a successful {@code executeUpdate}, the version in the graph is
|
||||
* {@code expectedVersion + 1}. This guard instance is consumed — create a new one
|
||||
* (or reload the entity) before the next write.
|
||||
*/
|
||||
public record VersionGuard(ARID id, String versionProperty, long expectedVersion, boolean vertex) {
|
||||
|
||||
public static final String DEFAULT_VERSION_PROPERTY = "_version";
|
||||
|
||||
/** Guard on a vertex using the default {@value #DEFAULT_VERSION_PROPERTY} property. */
|
||||
public static VersionGuard onVertex(ARID id, long expectedVersion) {
|
||||
return new VersionGuard(id, DEFAULT_VERSION_PROPERTY, expectedVersion, true);
|
||||
}
|
||||
|
||||
/** Guard on a vertex using a custom version property name. */
|
||||
public static VersionGuard onVertex(ARID id, String versionProperty, long expectedVersion) {
|
||||
return new VersionGuard(id, versionProperty, expectedVersion, true);
|
||||
}
|
||||
|
||||
/** Guard on an edge using the default {@value #DEFAULT_VERSION_PROPERTY} property. */
|
||||
public static VersionGuard onEdge(ARID id, long expectedVersion) {
|
||||
return new VersionGuard(id, DEFAULT_VERSION_PROPERTY, expectedVersion, false);
|
||||
}
|
||||
|
||||
/** Guard on an edge using a custom version property name. */
|
||||
public static VersionGuard onEdge(ARID id, String versionProperty, long expectedVersion) {
|
||||
return new VersionGuard(id, versionProperty, expectedVersion, false);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user