Reputation: 1181
In my java project, I can create in-memory "GraphTraversalSource
" and I can create traversal queries easily. But I wonder how can I create script queries like client.submit(query)
?
public GraphTraversalSource gremlinGraph()
{
final Graph graph = TinkerGraph.open();
return graph.traversal();
}
I need a create Client
object from TinkerGraph. Then I want to call client.submit(query)
queries.
Is there any suggestion?
Upvotes: 0
Views: 308
Reputation: 46206
I'd say that the easiest way is to reference the gremlin-groovy
module and create a GremlinGroovyScriptEngine
instance (source code). Then you can just do:
Graph graph = TinkerGraph.open();
ScriptEngine engine = new GremlinGroovyScriptEngine();
Bindings b = new SimpleBindings();
b.put("g", graph);
Traversal t = (Traversal) engine.eval("g.V()", b);
Note that client.submit()
is meant to submit Gremlin to a Gremlin Server compliant system. To use TinkerGraph in that context would mean hosting TinkerGraph in Gremlin Server.
Upvotes: 1