base version
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
|
||||
http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>com.binarygolem.clotho</groupId>
|
||||
<artifactId>clotho-parent</artifactId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>clotho-dev-app</artifactId>
|
||||
<name>Clotho Dev App</name>
|
||||
<description>
|
||||
Development sandbox — connects to a live ArcadeDB instance for manual and
|
||||
exploratory testing during library development. Not a production artifact.
|
||||
</description>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.binarygolem.clotho</groupId>
|
||||
<artifactId>clotho-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Spring Boot baseline: context, logging, autoconfigure -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.jspecify</groupId>
|
||||
<artifactId>jspecify</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<!-- Test -->
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<annotationProcessorPaths>
|
||||
<path>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>${lombok.version}</version>
|
||||
</path>
|
||||
</annotationProcessorPaths>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.binarygolem.clotho.dev;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class ClothoDevApp {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(ClothoDevApp.class, args);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.binarygolem.clotho.dev;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
@Order(1)
|
||||
@RequiredArgsConstructor
|
||||
public class ConnectionSmokeTest implements ApplicationRunner {
|
||||
|
||||
private final GraphTraversalSource traversalSource;
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) {
|
||||
log.info("Testing Gremlin connection...");
|
||||
long count = traversalSource.V().count().next();
|
||||
log.info("Connection OK — total vertex count: {}", count);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.binarygolem.clotho.dev;
|
||||
|
||||
import org.apache.tinkerpop.gremlin.driver.Cluster;
|
||||
import org.apache.tinkerpop.gremlin.driver.remote.DriverRemoteConnection;
|
||||
import org.apache.tinkerpop.gremlin.process.traversal.AnonymousTraversalSource;
|
||||
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
|
||||
import org.apache.tinkerpop.gremlin.util.ser.GraphSONMessageSerializerV3;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
@Configuration
|
||||
@EnableConfigurationProperties(GremlinProperties.class)
|
||||
public class GremlinConfig {
|
||||
|
||||
@Bean(destroyMethod = "close")
|
||||
public Cluster gremlinCluster(GremlinProperties props) {
|
||||
URI uri = URI.create(props.getUrl());
|
||||
int port = uri.getPort() > 0 ? uri.getPort() : 8182;
|
||||
return Cluster.build()
|
||||
.addContactPoint(uri.getHost())
|
||||
.port(port)
|
||||
.credentials(props.getUsername(), props.getPassword())
|
||||
.serializer(new GraphSONMessageSerializerV3())
|
||||
.create();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DriverRemoteConnection remoteConnection(Cluster cluster, GremlinProperties props) {
|
||||
return DriverRemoteConnection.using(cluster, props.getTraversalSource());
|
||||
}
|
||||
|
||||
@Bean(destroyMethod = "close")
|
||||
public GraphTraversalSource traversalSource(DriverRemoteConnection connection) {
|
||||
return AnonymousTraversalSource.traversal().withRemote(connection);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.binarygolem.clotho.dev;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
@ConfigurationProperties("clotho.gremlin")
|
||||
@Data
|
||||
public class GremlinProperties {
|
||||
|
||||
private String url = "";
|
||||
private String username = "";
|
||||
private String password = "";
|
||||
private String traversalSource = "g";
|
||||
}
|
||||
@@ -0,0 +1,301 @@
|
||||
package com.binarygolem.clotho.dev.demo;
|
||||
|
||||
import com.binarygolem.clotho.dev.demo.model.Company;
|
||||
import com.binarygolem.clotho.dev.demo.model.Person;
|
||||
import com.binarygolem.clotho.dev.demo.model.WorksAt;
|
||||
import com.binarygolem.clotho.dev.demo.repository.PersonRepository;
|
||||
import com.binarygolem.clotho.model.ARID;
|
||||
import com.binarygolem.clotho.session.ClothoSession;
|
||||
import com.binarygolem.clotho.session.ClothoSessionFactory;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Demonstrates core Clotho features against a live ArcadeDB instance.
|
||||
*
|
||||
* <p>Requires these ArcadeDB types to exist before running:
|
||||
* <pre>
|
||||
* CREATE VERTEX TYPE Person;
|
||||
* CREATE PROPERTY Person.name STRING;
|
||||
* CREATE PROPERTY Person.email STRING;
|
||||
* CREATE PROPERTY Person.age INTEGER;
|
||||
*
|
||||
* CREATE VERTEX TYPE Company;
|
||||
* CREATE PROPERTY Company.name STRING;
|
||||
* CREATE PROPERTY Company.industry STRING;
|
||||
*
|
||||
* CREATE EDGE TYPE WORKS_AT;
|
||||
* CREATE PROPERTY WORKS_AT.role STRING;
|
||||
* CREATE PROPERTY WORKS_AT.startYear INTEGER;
|
||||
* </pre>
|
||||
*
|
||||
* <p>All demo data is cleaned up after the run regardless of success or failure.
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
@Order(2)
|
||||
@RequiredArgsConstructor
|
||||
public class FeatureDemo implements ApplicationRunner {
|
||||
|
||||
private final ClothoSessionFactory sessionFactory;
|
||||
private final PersonRepository personRepository;
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) {
|
||||
log.info("");
|
||||
log.info("══════════════════════════════════════");
|
||||
log.info(" Clotho Feature Demo ");
|
||||
log.info("══════════════════════════════════════");
|
||||
|
||||
@Nullable ARID personId = null;
|
||||
@Nullable ARID bobId = null;
|
||||
@Nullable ARID charlieId = null;
|
||||
@Nullable ARID companyId = null;
|
||||
|
||||
try {
|
||||
// ── 1. Create entities (session cascades: person → edge → company) ──
|
||||
log.info("");
|
||||
log.info("1. Creating entities");
|
||||
|
||||
try (ClothoSession session = sessionFactory.openSession()) {
|
||||
Company acme = new Company();
|
||||
acme.setName("Acme Corp");
|
||||
acme.setIndustry("Technology");
|
||||
|
||||
Person alice = new Person();
|
||||
alice.setName("Alice Smith");
|
||||
alice.setEmail("alice@example.com");
|
||||
alice.setAge(32);
|
||||
WorksAt aliceJob = new WorksAt();
|
||||
aliceJob.setCompany(acme);
|
||||
aliceJob.setRole("Senior Engineer");
|
||||
aliceJob.setStartYear(2020);
|
||||
alice.setJobs(List.of(aliceJob));
|
||||
|
||||
Person bob = new Person();
|
||||
bob.setName("Bob Jones");
|
||||
bob.setEmail("bob@example.com");
|
||||
bob.setAge(28);
|
||||
WorksAt bobJob = new WorksAt();
|
||||
bobJob.setCompany(acme);
|
||||
bobJob.setRole("Engineer");
|
||||
bobJob.setStartYear(2022);
|
||||
bob.setJobs(List.of(bobJob));
|
||||
|
||||
Person charlie = new Person();
|
||||
charlie.setName("Charlie Lee");
|
||||
charlie.setEmail("charlie@example.com");
|
||||
charlie.setAge(41);
|
||||
WorksAt charlieJob = new WorksAt();
|
||||
charlieJob.setCompany(acme);
|
||||
charlieJob.setRole("Engineering Manager");
|
||||
charlieJob.setStartYear(2018);
|
||||
charlie.setJobs(List.of(charlieJob));
|
||||
|
||||
session.save(alice);
|
||||
session.save(bob);
|
||||
session.save(charlie);
|
||||
|
||||
personId = alice.getId();
|
||||
bobId = bob.getId();
|
||||
charlieId = charlie.getId();
|
||||
companyId = acme.getId();
|
||||
|
||||
log.info(" ✓ Company {} → {}", acme.getName(), acme.getId());
|
||||
log.info(" ✓ Person {} ({}) → {}", alice.getName(), aliceJob.getRole(), alice.getId());
|
||||
log.info(" ✓ Person {} ({}) → {}", bob.getName(), bobJob.getRole(), bob.getId());
|
||||
log.info(" ✓ Person {} ({}) → {}", charlie.getName(), charlieJob.getRole(), charlie.getId());
|
||||
}
|
||||
|
||||
// ── 2. Load by ID — @Include boundary auto-populated in a single query ──
|
||||
log.info("");
|
||||
log.info("2. Loading by ID (@Include populated atomically)");
|
||||
|
||||
try (ClothoSession session = sessionFactory.openSession()) {
|
||||
Person alice = session.load(Person.class, personId);
|
||||
List<WorksAt> jobs = alice.getJobs();
|
||||
|
||||
log.info(" ✓ Loaded: {} (age {}), {} job(s)", alice.getName(), alice.getAge(),
|
||||
jobs == null ? 0 : jobs.size());
|
||||
|
||||
if (jobs != null && !jobs.isEmpty()) {
|
||||
WorksAt job = jobs.get(0);
|
||||
String companyName = job.getCompany() != null ? job.getCompany().getName() : "?";
|
||||
log.info(" └─ {} at {} (since {})", job.getRole(), companyName, job.getStartYear());
|
||||
}
|
||||
}
|
||||
|
||||
// ── 3. Dirty tracking — only modified fields are written ──
|
||||
log.info("");
|
||||
log.info("3. Dirty tracking (partial update)");
|
||||
|
||||
try (ClothoSession session = sessionFactory.openSession()) {
|
||||
Person alice = session.load(Person.class, personId);
|
||||
alice.setEmail("alice.smith@example.com"); // dirty: email
|
||||
alice.setAge(33); // dirty: age
|
||||
// name is unchanged — not written
|
||||
session.save(alice);
|
||||
log.info(" ✓ Saved 2 dirty fields (email, age); name not touched");
|
||||
}
|
||||
|
||||
try (ClothoSession session = sessionFactory.openSession()) {
|
||||
Person alice = session.load(Person.class, personId);
|
||||
log.info(" ✓ Verified: email={}, age={}", alice.getEmail(), alice.getAge());
|
||||
}
|
||||
|
||||
// ── 4. Auto-save on session close ──
|
||||
log.info("");
|
||||
log.info("4. Auto-save on session close");
|
||||
|
||||
try (ClothoSession session = sessionFactory.openSession()) {
|
||||
Person alice = session.load(Person.class, personId);
|
||||
alice.setAge(34);
|
||||
// no explicit save() — session.close() persists dirty MANAGED entities
|
||||
}
|
||||
|
||||
try (ClothoSession session = sessionFactory.openSession()) {
|
||||
Person alice = session.load(Person.class, personId);
|
||||
log.info(" ✓ Age auto-saved on close: {}", alice.getAge());
|
||||
}
|
||||
|
||||
// ── 5. Repository queries ──
|
||||
log.info("");
|
||||
log.info("5. Repository queries");
|
||||
|
||||
List<Person> byName = personRepository.findByName("Alice Smith");
|
||||
log.info(" ✓ findByName(\"Alice Smith\"): {} result(s)", byName.size());
|
||||
|
||||
List<Person> byAge = personRepository.findByAgeGreaterThan(30);
|
||||
log.info(" ✓ findByAgeGreaterThan(30): {} result(s)", byAge.size());
|
||||
|
||||
List<Person> employed = personRepository.findEmployed();
|
||||
log.info(" ✓ findEmployed(): {} result(s)", employed.size());
|
||||
|
||||
long total = personRepository.count();
|
||||
log.info(" ✓ count(): {} total Person(s) in graph", total);
|
||||
|
||||
// ── 6. Ad-hoc traversal + session-aware execute ──
|
||||
log.info("");
|
||||
log.info("6. Ad-hoc traversal: findCoworkers() with session-aware execute");
|
||||
log.info(" (traverses WORKS_AT not declared as @Include — results are MANAGED)");
|
||||
|
||||
@Nullable ARID firstCoworkerId = null;
|
||||
|
||||
try (ClothoSession session = sessionFactory.openSession()) {
|
||||
Person alice = session.load(Person.class, personId);
|
||||
// session-aware overload: returned entities are MANAGED in this session
|
||||
List<Person> coworkers = personRepository.findCoworkers(alice, session);
|
||||
log.info(" ✓ Alice's co-workers at Acme Corp: {} found", coworkers.size());
|
||||
for (Person cw : coworkers) {
|
||||
String role = cw.getJobs() != null && !cw.getJobs().isEmpty()
|
||||
? cw.getJobs().get(0).getRole() : "?";
|
||||
log.info(" └─ {} ({})", cw.getName(), role);
|
||||
}
|
||||
if (!coworkers.isEmpty()) {
|
||||
firstCoworkerId = coworkers.get(0).getId();
|
||||
coworkers.get(0).setEmail("updated-by-demo@example.com");
|
||||
// no explicit save() — dirty tracking fires; auto-saved on session close
|
||||
}
|
||||
} // ← session.close() auto-saves the dirty co-worker here
|
||||
|
||||
if (firstCoworkerId != null) {
|
||||
try (ClothoSession session = sessionFactory.openSession()) {
|
||||
Person cw = session.load(Person.class, firstCoworkerId);
|
||||
log.info(" ✓ Co-worker email auto-saved on close: {}", cw.getEmail());
|
||||
}
|
||||
}
|
||||
|
||||
// ── 7. Transactional session ──
|
||||
log.info("");
|
||||
log.info("7. Transactional session (atomic multi-step write)");
|
||||
|
||||
ARID txPersonId = null;
|
||||
try (ClothoSession session = sessionFactory.openTransactionalSession()) {
|
||||
Company startupCo = new Company();
|
||||
startupCo.setName("StartupCo");
|
||||
startupCo.setIndustry("FinTech");
|
||||
|
||||
Person diana = new Person();
|
||||
diana.setName("Diana Prince");
|
||||
diana.setEmail("diana@startupco.io");
|
||||
diana.setAge(29);
|
||||
|
||||
// openSession() inside a transactional session borrows the same session
|
||||
ClothoSession borrowed = sessionFactory.openSession();
|
||||
log.info(" openSession() inside @Transactional returns same session? {}",
|
||||
borrowed == session ? "yes" : "no");
|
||||
borrowed.close(); // borrow close — no-op
|
||||
|
||||
session.save(diana);
|
||||
txPersonId = diana.getId();
|
||||
log.info(" ✓ Diana created: {} → {}", diana.getName(), diana.getId());
|
||||
log.info(" ✓ (company would be linked here; session commits on close)");
|
||||
} // ← tx.commit() fires here
|
||||
|
||||
if (txPersonId != null) {
|
||||
try (ClothoSession session = sessionFactory.openSession()) {
|
||||
Person diana = session.load(Person.class, txPersonId);
|
||||
log.info(" ✓ Verified commit: {} loaded after tx close", diana.getName());
|
||||
session.delete(diana);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("Demo failed — check that the required ArcadeDB schema exists", e);
|
||||
log.error("Required types: Person, Company, WORKS_AT (see FeatureDemo Javadoc)");
|
||||
|
||||
} finally {
|
||||
cleanup(personId, bobId, charlieId, companyId);
|
||||
}
|
||||
}
|
||||
|
||||
private void cleanup(@Nullable ARID personId, @Nullable ARID bobId,
|
||||
@Nullable ARID charlieId, @Nullable ARID companyId) {
|
||||
log.info("");
|
||||
log.info("Cleaning up demo data");
|
||||
try {
|
||||
// Delete all persons in one traversal. Sequential per-session deletes cause OrientDB's
|
||||
// Gremlin Server to cache the Company vertex at its initial @version and then fail the
|
||||
// MVCC check when cascade-deleting later edges bumps the DB version above the cached one.
|
||||
// A single g.V(...).drop() request loads Company once and applies all cascades atomically.
|
||||
List<Object> personIds = new ArrayList<>();
|
||||
if (personId != null) personIds.add(personId.asString());
|
||||
if (bobId != null) personIds.add(bobId.asString());
|
||||
if (charlieId != null) personIds.add(charlieId.asString());
|
||||
if (!personIds.isEmpty()) {
|
||||
sessionFactory.traversal().V(personIds.toArray()).drop().iterate();
|
||||
log.info(" ✓ Deleted {} Person(s) (+ incident WORKS_AT edge(s))", personIds.size());
|
||||
}
|
||||
if (companyId != null) {
|
||||
try {
|
||||
sessionFactory.traversal().V(companyId.asString()).drop().iterate();
|
||||
log.info(" ✓ Deleted Company");
|
||||
} catch (Exception e) {
|
||||
// OrientDB cascade-deletes the Company when the last incident WORKS_AT edge is
|
||||
// removed by the person bulk-drop above — treat "not found" as already gone.
|
||||
if (e.getMessage() != null && e.getMessage().contains("was not found")) {
|
||||
log.info(" ✓ Company already removed (cascade)");
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("Cleanup failed — demo data may remain in the graph: {}", e.getMessage());
|
||||
}
|
||||
|
||||
log.info("");
|
||||
log.info("══════════════════════════════════════");
|
||||
log.info(" Demo complete ");
|
||||
log.info("══════════════════════════════════════");
|
||||
log.info("");
|
||||
}
|
||||
}
|
||||
+103
@@ -0,0 +1,103 @@
|
||||
package com.binarygolem.clotho.dev.demo;
|
||||
|
||||
import com.binarygolem.clotho.session.ClothoSessionFactory;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
|
||||
import org.apache.tinkerpop.gremlin.structure.Vertex;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* Confirms that Clotho's application-managed {@code @Version} OCC mechanism works
|
||||
* against a live ArcadeDB instance.
|
||||
*
|
||||
* <p>ArcadeDB's internal {@code @version} property is not accessible via the Gremlin
|
||||
* WebSocket interface. Clotho therefore manages the version counter itself as a regular
|
||||
* graph property (default: {@code "_version"}). This probe verifies that the Gremlin
|
||||
* filter step {@code .has("_version", expectedValue)} works correctly with ArcadeDB for
|
||||
* regular properties — the foundation of the pre-flight conflict check.
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
@Order(3)
|
||||
@RequiredArgsConstructor
|
||||
public class VersionConflictProbe implements ApplicationRunner {
|
||||
|
||||
private final ClothoSessionFactory sessionFactory;
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) {
|
||||
log.info("");
|
||||
log.info("══════════════════════════════════════════════════════");
|
||||
log.info(" Clotho @Version OCC Mechanism Smoke Test ");
|
||||
log.info("══════════════════════════════════════════════════════");
|
||||
|
||||
GraphTraversalSource g = sessionFactory.traversal();
|
||||
String probeId = null;
|
||||
|
||||
try {
|
||||
// Create a vertex with an initial _version=0 (mimics what Clotho does on persist)
|
||||
Vertex v = g.addV("Person")
|
||||
.property("name", "OccProbe")
|
||||
.property("_version", 0L)
|
||||
.next();
|
||||
probeId = v.id().toString();
|
||||
log.info(" Probe vertex created: {}", probeId);
|
||||
|
||||
// ── Part 1: does .has("_version", value) actually filter? ──
|
||||
log.info("");
|
||||
log.info("Part 1: _version filter works with regular properties");
|
||||
|
||||
long matchCorrect = g.V(probeId).has("_version", 0L).count().next();
|
||||
long matchWrong = g.V(probeId).has("_version", 99L).count().next();
|
||||
log.info(" .has('_version', 0L) → {}", matchCorrect);
|
||||
log.info(" .has('_version', 99L) → {}", matchWrong);
|
||||
boolean filterWorks = matchCorrect == 1 && matchWrong == 0;
|
||||
log.info(" → Filter functional? → {}", filterWorks ? "YES ✓" : "NO ✗");
|
||||
|
||||
// ── Part 2: pre-flight check + atomic version-increment update ──
|
||||
log.info("");
|
||||
log.info("Part 2: check-and-increment update (Clotho's write step)");
|
||||
|
||||
// This is what Clotho's updateEntity() does: filter by version, write dirty props,
|
||||
// increment version — all in one traversal.
|
||||
long updated = g.V(probeId)
|
||||
.has("_version", 0L)
|
||||
.property("name", "OccProbe-v1")
|
||||
.property("_version", 1L)
|
||||
.count().next();
|
||||
log.info(" Update with correct version (0→1): matched={}", updated);
|
||||
|
||||
// Try stale update — version is now 1, so filtering by 0 must return 0
|
||||
long stale = g.V(probeId)
|
||||
.has("_version", 0L)
|
||||
.property("name", "MUST-NOT-BE-WRITTEN")
|
||||
.count().next();
|
||||
log.info(" Update with stale version (0 after bump): matched={}", stale);
|
||||
|
||||
String finalName = (String) g.V(probeId).values("name").next();
|
||||
Long finalVer = (Long) g.V(probeId).values("_version").next();
|
||||
log.info(" Final name: {} (expected: OccProbe-v1)", finalName);
|
||||
log.info(" Final _version: {} (expected: 1)", finalVer);
|
||||
|
||||
boolean occWorks = updated == 1 && stale == 0
|
||||
&& "OccProbe-v1".equals(finalName) && Long.valueOf(1L).equals(finalVer);
|
||||
log.info(" → Application-managed OCC works? → {}", occWorks ? "YES ✓" : "NO ✗");
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("Probe failed unexpectedly", e);
|
||||
} finally {
|
||||
if (probeId != null) {
|
||||
try { g.V(probeId).drop().iterate(); } catch (Exception ignored) {}
|
||||
}
|
||||
log.info("");
|
||||
log.info("══════════════════════════════════════════════════════");
|
||||
log.info(" Probe complete ");
|
||||
log.info("══════════════════════════════════════════════════════");
|
||||
log.info("");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.binarygolem.clotho.dev.demo.model;
|
||||
|
||||
import com.binarygolem.clotho.annotation.Property;
|
||||
import com.binarygolem.clotho.annotation.VertexType;
|
||||
import com.binarygolem.clotho.model.ClothoVertex;
|
||||
import lombok.Getter;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* ArcadeDB type: {@code Company}.
|
||||
*
|
||||
* <p>Required schema:
|
||||
* <pre>
|
||||
* CREATE VERTEX TYPE Company;
|
||||
* CREATE PROPERTY Company.name STRING;
|
||||
* CREATE PROPERTY Company.industry STRING;
|
||||
* </pre>
|
||||
*/
|
||||
@VertexType("Company")
|
||||
@Getter
|
||||
public class Company extends ClothoVertex {
|
||||
|
||||
@Property("name")
|
||||
private @Nullable String name;
|
||||
|
||||
@Property("industry")
|
||||
private @Nullable String industry;
|
||||
|
||||
public void setName(@Nullable String name) {
|
||||
this.name = name;
|
||||
notifyFieldChanged("name");
|
||||
}
|
||||
|
||||
public void setIndustry(@Nullable String industry) {
|
||||
this.industry = industry;
|
||||
notifyFieldChanged("industry");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package com.binarygolem.clotho.dev.demo.model;
|
||||
|
||||
import com.binarygolem.clotho.annotation.Include;
|
||||
import com.binarygolem.clotho.annotation.Property;
|
||||
import com.binarygolem.clotho.annotation.VertexType;
|
||||
import com.binarygolem.clotho.annotation.Via;
|
||||
import com.binarygolem.clotho.model.ClothoVertex;
|
||||
import lombok.Getter;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* ArcadeDB type: {@code Person}.
|
||||
*
|
||||
* <p>Required schema:
|
||||
* <pre>
|
||||
* CREATE VERTEX TYPE Person;
|
||||
* CREATE PROPERTY Person.name STRING;
|
||||
* CREATE PROPERTY Person.email STRING;
|
||||
* CREATE PROPERTY Person.age INTEGER;
|
||||
* </pre>
|
||||
*/
|
||||
@VertexType("Person")
|
||||
@Getter
|
||||
public class Person extends ClothoVertex {
|
||||
|
||||
@Property("name")
|
||||
private @Nullable String name;
|
||||
|
||||
@Property("email")
|
||||
private @Nullable String email;
|
||||
|
||||
@Property("age")
|
||||
private @Nullable Integer age;
|
||||
|
||||
@Include
|
||||
@Via("WORKS_AT")
|
||||
private @Nullable List<WorksAt> jobs;
|
||||
|
||||
public void setName(@Nullable String name) {
|
||||
this.name = name;
|
||||
notifyFieldChanged("name");
|
||||
}
|
||||
|
||||
public void setEmail(@Nullable String email) {
|
||||
this.email = email;
|
||||
notifyFieldChanged("email");
|
||||
}
|
||||
|
||||
public void setAge(@Nullable Integer age) {
|
||||
this.age = age;
|
||||
notifyFieldChanged("age");
|
||||
}
|
||||
|
||||
public void setJobs(@Nullable List<WorksAt> jobs) {
|
||||
this.jobs = jobs;
|
||||
notifyFieldChanged("jobs");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package com.binarygolem.clotho.dev.demo.model;
|
||||
|
||||
import com.binarygolem.clotho.annotation.EdgeType;
|
||||
import com.binarygolem.clotho.annotation.InVertex;
|
||||
import com.binarygolem.clotho.annotation.OutVertex;
|
||||
import com.binarygolem.clotho.annotation.Property;
|
||||
import com.binarygolem.clotho.model.ClothoEdge;
|
||||
import lombok.Getter;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* ArcadeDB type: {@code WORKS_AT}.
|
||||
*
|
||||
* <p>Required schema:
|
||||
* <pre>
|
||||
* CREATE EDGE TYPE WORKS_AT;
|
||||
* CREATE PROPERTY WORKS_AT.role STRING;
|
||||
* CREATE PROPERTY WORKS_AT.startYear INTEGER;
|
||||
* </pre>
|
||||
*/
|
||||
@EdgeType("WORKS_AT")
|
||||
@Getter
|
||||
public class WorksAt extends ClothoEdge {
|
||||
|
||||
@Property("role")
|
||||
private @Nullable String role;
|
||||
|
||||
@Property("startYear")
|
||||
private @Nullable Integer startYear;
|
||||
|
||||
@OutVertex
|
||||
private @Nullable Person person;
|
||||
|
||||
@InVertex
|
||||
private @Nullable Company company;
|
||||
|
||||
public void setRole(@Nullable String role) {
|
||||
this.role = role;
|
||||
notifyFieldChanged("role");
|
||||
}
|
||||
|
||||
public void setStartYear(@Nullable Integer startYear) {
|
||||
this.startYear = startYear;
|
||||
notifyFieldChanged("startYear");
|
||||
}
|
||||
|
||||
public void setPerson(@Nullable Person person) {
|
||||
this.person = person;
|
||||
notifyFieldChanged("person");
|
||||
}
|
||||
|
||||
public void setCompany(@Nullable Company company) {
|
||||
this.company = company;
|
||||
notifyFieldChanged("company");
|
||||
}
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
package com.binarygolem.clotho.dev.demo.repository;
|
||||
|
||||
import com.binarygolem.clotho.dev.demo.model.Person;
|
||||
import com.binarygolem.clotho.repository.ClothoRepository;
|
||||
import com.binarygolem.clotho.session.ClothoSession;
|
||||
import com.binarygolem.clotho.session.ClothoSessionFactory;
|
||||
import org.apache.tinkerpop.gremlin.process.traversal.P;
|
||||
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@com.binarygolem.clotho.annotation.ClothoRepository
|
||||
public class PersonRepository extends ClothoRepository<Person> {
|
||||
|
||||
public PersonRepository(ClothoSessionFactory factory) {
|
||||
super(factory);
|
||||
}
|
||||
|
||||
public List<Person> findByName(String name) {
|
||||
return execute(g().V().has("Person", "name", name));
|
||||
}
|
||||
|
||||
public List<Person> findByAgeGreaterThan(int minAge) {
|
||||
return execute(allEntities(), t -> t.has("age", P.gt(minAge)));
|
||||
}
|
||||
|
||||
/** Returns all people who have at least one outgoing WORKS_AT edge. */
|
||||
public List<Person> findEmployed() {
|
||||
return execute(allEntities(), t -> t.where(__.outE("WORKS_AT")));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns co-workers as detached (untracked) entities — suitable for read-only use.
|
||||
*
|
||||
* <p>Traverses WORKS_AT edges that are not declared as {@code @Include} on
|
||||
* {@code Person}, demonstrating that repository methods can freely cross any
|
||||
* edge in the graph regardless of object-boundary declarations.
|
||||
*/
|
||||
public List<Person> findCoworkers(Person person) {
|
||||
return execute(
|
||||
g().V(person.getId().asString()).as("self")
|
||||
.out("WORKS_AT") // Person → Company
|
||||
.in("WORKS_AT") // Company → all Persons at that company
|
||||
.where(P.neq("self"))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns co-workers registered into {@code session} as MANAGED entities.
|
||||
* Dirty-field changes on the returned objects are tracked and auto-saved when
|
||||
* the session closes — no explicit {@code save()} needed.
|
||||
*/
|
||||
public List<Person> findCoworkers(Person person, ClothoSession session) {
|
||||
return execute(session,
|
||||
g().V(person.getId().asString()).as("self")
|
||||
.out("WORKS_AT")
|
||||
.in("WORKS_AT")
|
||||
.where(P.neq("self"))
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
@NullMarked
|
||||
package com.binarygolem.clotho.dev;
|
||||
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
@@ -0,0 +1,14 @@
|
||||
spring.application.name=clotho-dev-app
|
||||
|
||||
# OrientDB Gremlin endpoint (no auth — Gremlin Server configured without authentication)
|
||||
clotho.gremlin.url=ws://localhost:8182/gremlin
|
||||
clotho.gremlin.username=
|
||||
clotho.gremlin.password=
|
||||
clotho.gremlin.traversal-source=g
|
||||
|
||||
# Clotho behaviour
|
||||
clotho.default-direction=OUT
|
||||
clotho.unknown-type-behavior=STRICT
|
||||
|
||||
# Packages to scan for @VertexType / @EdgeType / @ClothoRepository
|
||||
clotho.packages=com.binarygolem.clotho.dev
|
||||
Reference in New Issue
Block a user