2

Using the new-style (Spring Data Neo4j 4.1.2.RELEASE) Neo4jConfiguration can I get a reference to the underlying embedded GraphDatabaseService to pass to the web ui?

New style config:

@Configuration
@EnableNeo4jRepositories(basePackages = "fu.bar")
@EnableTransactionManagement
public class Neo4j extends Neo4jConfiguration {

    @Bean
    @Scope(value = ConfigurableBeanFactory.SCOPE_SINGLETON, proxyMode = ScopedProxyMode.TARGET_CLASS)
    public Session getSession() throws Exception {
        return super.getSession();
    }

    @Bean
    public org.neo4j.ogm.config.Configuration getConfiguration() {
        org.neo4j.ogm.config.Configuration config = new org.neo4j.ogm.config.Configuration();
        config.driverConfiguration()
            .setDriverClassName("org.neo4j.ogm.drivers.embedded.driver.EmbeddedDriver")
            .setURI("file:///var/tmp/graph.db");
        return config;
    }

    @Bean
    public SessionFactory getSessionFactory() {
        SessionFactory sessionFactory = new SessionFactory(getConfiguration(), "fu.bar");
        return sessionFactory;
    }

I'm not seeing anything in the Javadoc that helps but I suspect Boot has an instance someplace.

Thanks.

Mike Summers
  • 2,139
  • 3
  • 27
  • 57

1 Answers1

2

If you're using the embedded driver, the GraphDatabaseService can be obtained as follows:

EmbeddedDriver embeddedDriver = (EmbeddedDriver) Components.driver();
GraphDatabaseService databaseService = embeddedDriver.getGraphDatabaseService();

With HTTP, direct access to the database can be achieved with:

String uri = Components.driver().getConfiguration().getURI() +
                        "/db/data/index/node/" + indexName;
HttpPost httpPost = new HttpPost(uri);

These examples come from the section on indexes of the Spring Data Neo4j reference guide.

Jasper Blues
  • 28,258
  • 22
  • 102
  • 185