5

I am trying out neo4j traversal api. All examples online work with GraphDatabaseService instance to use its traversalDescription() afterwards to define traversal pattern.

However online examples (like this one) uses GraphDatabaseFactory to obtain GraphDatabaseService instance from embedded database / database file:

GraphDatabaseService graphDb = new GraphDatabaseFactory().newEmbeddedDatabase("/tmp/neo4j/");

I want to use it with neo4j server instance running locally. Usually I use to do this by calling methods on session opbtained instance as follows:

Driver driver = GraphDatabase.driver( "bolt://localhost", AuthTokens.basic( "neo4j", "password" ) );
session session = driver.session();

How do we get GraphDatabaseService instance from driver or session instance or by other means so that we can work with the locally running neo4j server instance? Or is it like we can use traversal api only with embedded neo4j database?

Mahesha999
  • 22,693
  • 29
  • 116
  • 189

1 Answers1

2

The GraphDatabaseService comes from the internal Java API of Neo4j. So to obtain it, you should be on the database side (not on the client/driver side).

Drivers only speak Cypher (not Java).

To do this, many examples create an embedded DB directly into the Java code, so they have access to the service.

An other solution is to make a Java procedure that can be called in Cypher. Take a look at this documentation : http://neo4j.com/docs/developer-manual/current/extending-neo4j/procedures/

logisima
  • 7,340
  • 1
  • 18
  • 31