TinkerGraph: why mutating through GraphTraversalSource doesn't persist/store while using Graph does?

170 views Asked by At

Hi I am trying to use TinkerGraph for some small cases of demonstration and it seems that it doesn't persist using GraphTraversalSource. Here is the code I currently have:

    GraphTraversalSource g = TinkerGraph.open().traversal();
    System.out.println(g.V().addV("testlabel").iterate());
    System.out.println(g.V().count().next().intValue()); //returns 0
    try {g.close(); }
    catch(Exception e){
        e.printStackTrace();
    }
    System.out.println(g.V().count().next().intValue()); //returns 0

and here is the output:

[TinkerGraphStep(vertex,[]), AddVertexStep({label=[testlabel]})]
0
0

I know that this works instead:

Graph graph = TinkerGraph.open();
Vertex gremlin = graph.addVertex("testlabel");
System.out.println(IteratorUtils.count(graph.vertices()) == 1);

Thank you :)

1

There are 1 answers

1
Alaa Mahmoud On BEST ANSWER

It looks like you need to use addV right from the GraphTraversalSource object not from V() (At least for the first object). The following code persists the vertexes in the gremlin console

gremlin> g = TinkerGraph.open().traversal();
==>graphtraversalsource[tinkergraph[vertices:0 edges:0], standard]
gremlin> g.V().addV("testing")
gremlin> g.V().count()
==>0
gremlin> g.V().addV("testing")
gremlin> g.V().count()
==>0
gremlin> g.addV("test");
==>v[0]
gremlin> g.V().count()
==>1
gremlin> g.addV("test2");
==>v[1]
gremlin> g.V().count()
==>2
gremlin> g.V().addV("testing3")
==>v[2]
==>v[3]
gremlin> g.V().count()
==>4