String username = conf.getString(dbkey + ".user"); String password = conf.getString(dbkey + ".password"); Driver driver = GraphDatabase.driver(db, AuthTokens.basic(username, password)); Session session = driver.session(); props.setProperty(DBProperties.SERVER_ROOT_URI, db);
@Test public void calls_procedures_with_simple_input_type_returning_record_with_primitive_fields() { try ( Driver driver = GraphDatabase.driver( graphDb.boltURI(), configuration() ); Session session = driver.session() ) { assertThat( session.run( "CALL " + procedureNamespace + ".simpleInput11('string') YIELD field04 AS p RETURN p" ).single() ).isNotNull(); assertThat( session.run( "CALL " + procedureNamespace + ".simpleInput12(42)" ).single() ).isNotNull(); assertThat( session.run( "CALL " + procedureNamespace + ".simpleInput13(42)" ).single() ).isNotNull(); assertThat( session.run( "CALL " + procedureNamespace + ".simpleInput14(4.2)" ).single() ).isNotNull(); assertThat( session.run( "CALL " + procedureNamespace + ".simpleInput15(true)" ).single() ).isNotNull(); assertThat( session.run( "CALL " + procedureNamespace + ".simpleInput16(false)" ).single() ).isNotNull(); assertThat( session.run( "CALL " + procedureNamespace + ".simpleInput17({foo:'bar'})" ).single() ) .isNotNull(); assertThat( session.run( "CALL " + procedureNamespace + ".simpleInput21()" ).single() ).isNotNull(); } }
@Test public void calls_simplistic_procedure() { try ( Driver driver = GraphDatabase.driver( graphDb.boltURI(), configuration() ); Session session = driver.session() ) { StatementResult result = session.run( "CALL " + procedureNamespace + ".theAnswer()" ); assertThat( result.single().get( "value" ).asLong() ).isEqualTo( 42L ); } }
@Test public void shouldStart() { boolean actual = neo4jContainer.isRunning(); assertThat(actual).isTrue(); try (Driver driver = GraphDatabase .driver(neo4jContainer.getBoltUrl(), AuthTokens.basic("neo4j", "password")); Session session = driver.session() ) { long one = session.run("RETURN 1", Collections.emptyMap()).next().get(0).asLong(); assertThat(one).isEqualTo(1L); } catch (Exception e) { fail(e.getMessage()); } }
private static Driver getDriver(Neo4jContainer container) { AuthToken authToken = AuthTokens.none(); if (container.getAdminPassword() != null) { authToken = AuthTokens.basic("neo4j", container.getAdminPassword()); } return GraphDatabase.driver(container.getBoltUrl(), authToken); } }
@Test public void calls_procedures_with_different_modes_returning_void() { try ( Driver driver = GraphDatabase.driver( graphDb.boltURI(), configuration() ); Session session = driver.session() ) { session.run( "CALL " + procedureNamespace + ".performsWrites()" ); session.run( "CALL " + procedureNamespace + ".defaultMode()" ); session.run( "CALL " + procedureNamespace + ".readMode()" ); session.run( "CALL " + procedureNamespace + ".writeMode()" ); session.run( "CALL " + procedureNamespace + ".schemaMode()" ); session.run( "CALL " + procedureNamespace + ".dbmsMode()" ); } }
@Test public void calls_procedures_with_simple_input_type_returning_void() { try ( Driver driver = GraphDatabase.driver( graphDb.boltURI(), configuration() ); Session session = driver.session() ) { session.run( "CALL " + procedureNamespace + ".simpleInput00()" ); session.run( "CALL " + procedureNamespace + ".simpleInput01('string')" ); session.run( "CALL " + procedureNamespace + ".simpleInput02(42)" ); session.run( "CALL " + procedureNamespace + ".simpleInput03(42)" ); session.run( "CALL " + procedureNamespace + ".simpleInput04(4.2)" ); session.run( "CALL " + procedureNamespace + ".simpleInput05(true)" ); session.run( "CALL " + procedureNamespace + ".simpleInput06(false)" ); session.run( "CALL " + procedureNamespace + ".simpleInput07({foo:'bar'})" ); session.run( "MATCH (n) CALL " + procedureNamespace + ".simpleInput08(n) RETURN n" ); session.run( "MATCH p=(()-[r]->()) CALL " + procedureNamespace + ".simpleInput09(p) RETURN p" ); session.run( "MATCH ()-[r]->() CALL " + procedureNamespace + ".simpleInput10(r) RETURN r" ); } }
@Procedure() @Description("apoc.bolt.load(url-or-key, kernelTransaction, params, config) - access to other databases via bolt for read") public Stream<RowResult> load(@Name("url") String url, @Name("kernelTransaction") String statement, @Name(value = "params", defaultValue = "{}") Map<String, Object> params, @Name(value = "config", defaultValue = "{}") Map<String, Object> config) throws URISyntaxException { if (params == null) params = Collections.emptyMap(); if (config == null) config = Collections.emptyMap(); boolean virtual = (boolean) config.getOrDefault("virtual", false); boolean addStatistics = (boolean) config.getOrDefault("statistics", false); boolean readOnly = (boolean) config.getOrDefault("readOnly", true); Config driverConfig = toDriverConfig(config.getOrDefault("driverConfig", map())); UriResolver uri = new UriResolver(url, "bolt"); uri.initialize(); try (Driver driver = GraphDatabase.driver(uri.getConfiguredUri(), uri.getToken(), driverConfig); Session session = driver.session()) { if (addStatistics) return Stream.of(new RowResult(toMap(runStatement(statement, session, params, readOnly).summary().counters()))); else return getRowResultStream(virtual, session, params, statement, readOnly); } catch (Exception e) { throw new RuntimeException("It's not possible to create a connection due to: " + e.getMessage()); } }
/** * Return a driver for a Neo4j instance with custom configuration. * * @param uri the URL to a Neo4j instance * @param config user defined configuration * @return a new driver to the database instance specified by the URL */ public static Driver driver( String uri, Config config ) { return driver( URI.create( uri ), config ); }
/** * Return a driver for a Neo4j instance with custom configuration. * * @param uri the URL to a Neo4j instance * @param authToken authentication to use, see {@link AuthTokens} * @param config user defined configuration * @return a new driver to the database instance specified by the URL */ public static Driver driver( String uri, AuthToken authToken, Config config ) { return driver( URI.create( uri ), authToken, config ); }
private Driver getDriver() { if (this.driver == null) { String uri = this.properties.getProperty(DBProperties.SERVER_ROOT_URI); if (this.authToken != null) this.driver = GraphDatabase.driver(uri, this.authToken); else this.driver = GraphDatabase.driver(uri); this.shutdownHook = registerShutdownHook(); } return this.driver; }
/** * Return a driver for a Neo4j instance with the default configuration settings * * @param uri the URL to a Neo4j instance * @return a new driver to the database instance specified by the URL */ public static Driver driver( URI uri ) { return driver( uri, Config.defaultConfig() ); }
/** * Return a driver for a Neo4j instance with custom configuration. * * @param uri the URL to a Neo4j instance * @param config user defined configuration * @return a new driver to the database instance specified by the URL */ public static Driver driver( URI uri, Config config ) { return driver( uri, AuthTokens.none(), config ); }
/** * Return a driver for a Neo4j instance with the default configuration settings * * @param uri the URL to a Neo4j instance * @return a new driver to the database instance specified by the URL */ public static Driver driver( String uri ) { return driver( uri, Config.defaultConfig() ); }
/** * Return a driver for a Neo4j instance with the default configuration settings * * @param uri the URL to a Neo4j instance * @param authToken authentication to use, see {@link AuthTokens} * @return a new driver to the database instance specified by the URL */ public static Driver driver( String uri, AuthToken authToken ) { return driver( uri, authToken, Config.defaultConfig() ); }
/** * Return a driver for a Neo4j instance with the default configuration settings * * @param uri the URL to a Neo4j instance * @param authToken authentication to use, see {@link AuthTokens} * @return a new driver to the database instance specified by the URL */ public static Driver driver( URI uri, AuthToken authToken ) { return driver( uri, authToken, Config.defaultConfig() ); }
@Bean(destroyMethod = "close") @ConditionalOnMissingBean public Driver neo4jDriver() { return GraphDatabase.driver(neo4jPros.getUrl() , neo4jAuthToken() , neo4jConfig()); }
@Override protected Graph createGraph() { driver = GraphDatabase.driver(neo4jUrl, AuthTokens.basic(neo4jUsername, neo4jPassword)); Neo4JElementIdProvider<?> vertexIdProvider = new DatabaseSequenceElementIdProvider(driver); Neo4JElementIdProvider<?> edgeIdProvider = new DatabaseSequenceElementIdProvider(driver); // create graph instance return new Neo4JGraph(driver, vertexIdProvider, edgeIdProvider); }
@Override protected Graph createGraph() { driver = GraphDatabase.driver(neo4jUrl, AuthTokens.basic(neo4jUsername, neo4jPassword)); Neo4JElementIdProvider<?> vertexIdProvider = new DatabaseSequenceElementIdProvider(driver); Neo4JElementIdProvider<?> edgeIdProvider = new DatabaseSequenceElementIdProvider(driver); // create graph instance return new Neo4JGraph(driver, vertexIdProvider, edgeIdProvider); }
@BeforeClass public static void startServer() { serverControls = TestServerBuilders.newInProcessBuilder().newServer(); Driver driver = GraphDatabase.driver(serverControls.boltURI(), Config.build().withoutEncryption().toConfig()); supportsBytePacking = ServerVersion.version(driver).greaterThanOrEqual(ServerVersion.v3_2_0); sessionFactory = new SessionFactory(new BoltDriver(driver), DOMAIN_PACKAGE); }