Working on a proof of concept if I add vertex and edge using the Graph instance inside my application and then I query those sometimes the query result send me the vertex and edge and sometimes doesn't, but if I create a JUnit test pointing to the server I'm able to see the vertex and edge persisted. Same happen if I drop a vertex or a edge
What I'm missing?
============= Class to work with Vertex and Edge =================
public class JanusGraphRepository implements GraphRepository {
private Graph graph;
private GraphTraversalSource g;
public JanusGraphRepository(Graph janusGraph) {
this.graph = janusGraph;
this.g = graph.traversal();
}
@Override
public void dropE(Object id) {
g.E(id).drop().iterate();
g.tx().commit();
}
@Override
public void dropV(Object id) {
g.V(id).drop().iterate();
g.tx().commit();
}
@Override
public Vertex addV(final Object... keyValues) {
Vertex v = graph.addVertex(keyValues);
graph.tx().commit();
return v;
}
@Override
public Edge addE(String edgeLabel, Object fromVertex, Object toVertex,
Object... keyValues) {
Edge e = graph.vertices(fromVertex).next().addEdge(edgeLabel,
graph.vertices(toVertex).next(), keyValues);
graph.tx().commit();
return e;
}
}
======================== Code to get vertices and edges ======================
JanusGraphFactory.Builder config = JanusGraphFactory.build();
config.set("storage.backend", "cql");
config.set("storage.hostname", "10.2.1.134");
config.set("storage.cql.keyspace", "janusgraph");
config.set("index.search.backend", "elasticsearch");
config.set("index.search.hostname", "10.2.1.134");
// config.set("index.search.elasticsearch.client-only", "true");
// ip address where cassandra is installed
// config.set("storage.username", "cassandra");
// config.set("storage.password", "cassandra");
// config.set("storage.port", "8182");
// Get the instance of graph
JanusGraph graph = config.open();
graph.vertices().forEachRemaining(x -> {
System.out.println(x.id());
});
System.out.println("------ Edges -------");
graph.edges().forEachRemaining(x -> {
System.out.println(x.toString());
});
Thanks