Sebastian Lobentanzer
Sebastian Lobentanzer

Reputation: 31

Use bolt driver and Java API of Neo4j simultaneously

Hello everybody!

I have developed a JavaFX application to support my scientific work (molecular biology/neuropharmacology), implementing Neo4j, at the time Version 2.x.

Now, since Version 3 (using 3.1.0-M05) is out, I am switching over to Bolt protocol access of the Database, with the Driver (1.1.0-M01) interface. Some functions of my application still require Java API access though, so I cannot completely abandon the old code. I am using a singleton GraphDatabaseFactory to start up the database, like so

private static GraphDatabaseService instance;

private GraphDb() {
    instance = new GraphDatabaseFactory().newEmbeddedDatabaseBuilder(new File(FilePaths.DATABASE_PATH))
            .setConfig(ShellSettings.remote_shell_enabled, "true").newGraphDatabase();
}

public static synchronized GraphDatabaseService getInstance() {
    return instance;
}

(Or, just the .newEmbeddedDatabase())But now, since Version 3, I also use a singleton Driver instance for the Bolt interaction, like so

private static Driver instance;

private GraphDbDriver() {
    startLocalDb();
    instance = GraphDatabase.driver("bolt://localhost");
}

private static void startLocalDb() {
//start database here?
}


public static synchronized Driver getInstance() {
    return instance;
}

My question now, is this (since I gathered that using both at the same time can only breed complications): How do I use these two ways of communicating with the DB without them getting in the way of each other?

Can I somehow get the Driver to load "onto" the already created GraphDatabaseService singleton?

Thanks for reading!

Upvotes: 2

Views: 362

Answers (1)

Sebastian Lobentanzer
Sebastian Lobentanzer

Reputation: 31

So, for anybody who's interested, in Neo4j 3.x it is recommended to use 'User-defined procedures' to implement API commands (like, e.g., traversals) and then calling it (via CALL) from cypher.

Upvotes: 1

Related Questions