How do I configure OGM with an embedded database that I can connect to remotely?


(Joe) #1

In older versions of Spring-Data-Neo4j it was possible to configure an embedded database, but enable remote access to it via the Neo4j-shell. This was done by using a GraphDatabaseFactory to construct a preconfigured GraphDatabaseService:

GraphDatabaseService newEmbeddedGraphDatabase(String dbDir) {
    db = factory.newEmbeddedDatabaseBuilder(dbDir)
        .setConfig(ShellSettings.remote_shell_enabled, "true")
        .setConfig(ShellSettings.remote_shell_port, "5555")
        .newGraphDatabase()
    db
}

and then wire that as a dependency when initialising the spring beans:

beans {
    graphDatabaseFactory(GraphDatabaseFactory)
    trueDbGraphDatabaseFactory(OurGraphDatabaseFactory, graphDatabaseFactory)
    graphDatabaseService(GraphDatabaseService, db) { bean ->
        bean.factoryBean = "ourGraphDatabaseFactory"
        bean.factoryMethod = "newEmbeddedGraphDatabase"
        bean.destroyMethod = "shutdown"
    }
}

I'm trying to work out how to achieve this in the new OGM project. Is it possible?

If I configure OGM using:

SessionFactory newSessionFactory() {
    GraphDatabaseSettings
    def configuration = new Configuration()
    configuration.driverConfiguration()
            .setDriverClassName("org.neo4j.ogm.drivers.embedded.driver.EmbeddedDriver")
            .setURI("file:///var/tmp/neo4j.db")
    new SessionFactory(configuration, "test.my.domain.path")
}

How do I inject my own instance of a GraphDatabaseService into the EmbeddedDriver? (There is a constructor to EmdeddedDriver that takes one, but it's not clear which constructor OGM is using).


(Michael Hunger) #2

You can configure a bolt connector for your embedded database if you have the dependencies setup.
Basically the same connector settings as in neo4j.conf


(Gerrit Meier) #4

You are on the right track. You can instantiate and pre-configure a GraphDatabaseService and handle it over to the embedded driver.

GraphDatabaseService graphDatabaseService = new GraphDatabaseFactory()
	.newEmbeddedDatabase(...)
	// do your configuration	
	.newGraphDatabase();
	
EmbeddedDriver driver = new EmbeddedDriver(graphDatabaseService);
SessionFactory sessionFactory = new SessionFactory(driver, "package");

(Joe) #5

@gerrit.meier It doesn't look like the SessionFactory() in OGM version 2.1.6 has a constructer that takes a database. :(. Maybe that was added in a later version. (I'm still on Neo4j 2.3.x so I can't move to the latest OGM yet).


(Joe) #6

@michael.hunger Neo4j 2.3.x doesn't support bolt yet; but maybe I can use do the same thing with the web connector perhaps?


(Gerrit Meier) #7

Yes, sorry, this is only available in Neo4j-OGM 3.0+ and I have no solution for you in this case that I would recommend.