当前位置: 首页>>代码示例>>Java>>正文


Java Driver类代码示例

本文整理汇总了Java中org.neo4j.driver.v1.Driver的典型用法代码示例。如果您正苦于以下问题:Java Driver类的具体用法?Java Driver怎么用?Java Driver使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Driver类属于org.neo4j.driver.v1包,在下文中一共展示了Driver类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: generates_executable_dump

import org.neo4j.driver.v1.Driver; //导入依赖的package包/类
@Test
public void generates_executable_dump() throws IOException {
    exporter.accept(dump, asList(
            exercise("foo", "MATCH (n:Foo) RETURN COUNT(n) AS foo_count"),
            exercise("bar", "MATCH (n:Bar) RETURN COUNT(n) AS bar_count"),
            exercise("baz", "MATCH (n:Baz) RETURN COUNT(n) AS baz_count", "CREATE (:Baz {name:'meh'})")));

    lines(dump.toPath(), UTF_8).forEachOrdered(line -> {
        try (Driver driver = GraphDatabase.driver(graphDb.boltURI(), config()); Session session = driver.session()) {
            session.run(line);
        }
    });

    try (Driver driver = GraphDatabase.driver(graphDb.boltURI(), config()); Session session = driver.session()) {
        StatementResult result = session.run(
                "MATCH p=(e1:Exercise)-[:NEXT*]->(e2:Exercise) WITH p ORDER BY LENGTH(p) DESC LIMIT 1 " +
                        "RETURN EXTRACT(exercise IN NODES(p) | exercise.instructions) AS instructions");
        assertThat(result.single().get("instructions").asList(Value::asString)).containsExactly("foo", "bar", "baz");
        result = session.run(
                "MATCH (e:Exercise) WHERE EXISTS(e.validationQuery) RETURN e.instructions AS instruction");
        assertThat(result.single().get("instruction").asString()).isEqualTo("baz");
    }
}
 
开发者ID:fbiville,项目名称:hands-on-neo4j-devoxx-fr-2017,代码行数:24,代码来源:ExerciseExporterTest.java

示例2: addNewUser

import org.neo4j.driver.v1.Driver; //导入依赖的package包/类
private PrivateKey addNewUser( PrivateKey defaultUserPrivateKey, String username, String... roles )
{
    KeyPair newUserKeyPair = generateKeyPair();

    AuthToken authToken = pkiAuthToken( DEFAULT_USER, defaultUserPrivateKey );
    try ( Driver driver = GraphDatabase.driver( server.boltURI(), authToken );
            Session session = driver.session() )
    {
        String query = "CALL addPkiUser({username}, {key}, {roles})";

        Map<String,Object> params = new HashMap<>();
        params.put( "username", username );
        params.put( "key", publicKeyAsString( newUserKeyPair.getPublic() ) );
        params.put( "roles", roles );

        session.run( query, params ).consume();
    }

    return newUserKeyPair.getPrivate();
}
 
开发者ID:neo4j,项目名称:neo4j-example-auth-plugins,代码行数:21,代码来源:PkiAuthPluginIT.java

示例3: shouldAuthenticateAndAuthorizeKalleMoraeusAsAdmin

import org.neo4j.driver.v1.Driver; //导入依赖的package包/类
@Test
public void shouldAuthenticateAndAuthorizeKalleMoraeusAsAdmin() throws Exception
{
    Driver driver = GraphDatabase.driver( server.boltURI(), AuthTokens.basic( "moraeus", "suearom" ) );
    Session session = driver.session();

    session.run( "CREATE (a:Person {name:'Kalle Moraeus', title:'Riksspelman'})" );

    StatementResult result =
            session.run( "MATCH (a:Person) WHERE a.name = 'Kalle Moraeus' RETURN a.name AS name, a.title AS title" );
    assertTrue( result.hasNext() );
    while ( result.hasNext() )
    {
        Record record = result.next();
        assertThat( record.get( "name" ).asString(), equalTo( "Kalle Moraeus" ) );
        assertThat( record.get( "title" ).asString(), equalTo( "Riksspelman" ) );
        System.out.println( record.get( "title" ).asString() + " " + record.get( "name" ).asString() );
    }

    session.close();
    driver.close();
}
 
开发者ID:neo4j,项目名称:neo4j-example-auth-plugins,代码行数:23,代码来源:MyAuthPluginIT.java

示例4: shouldRunHelloWorldExample

import org.neo4j.driver.v1.Driver; //导入依赖的package包/类
@Test
public void shouldRunHelloWorldExample() throws Throwable
{
    System.in.read();
    // Given
    try( Driver driver = GraphDatabase.driver( "bolt://localhost" ) )
    {
        Session session = driver.session();

        // Register a cypher query as a GraphQL field
        session.run( "CALL graphql.createQueryField('hello', 'RETURN \"hello, world!\"')" );

        // And then run a graphQL query against the updated schema
        System.out.println(
                session.run( "CALL graphql.query('{hello}')" )
                .single()
                .get(0).asMap());

    }
}
 
开发者ID:jakewins,项目名称:neo4j-procedure-template,代码行数:21,代码来源:GraphQLProceduresIT.java

示例5: calls_procedures_with_simple_input_type_returning_void

import org.neo4j.driver.v1.Driver; //导入依赖的package包/类
@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" );
    }
}
 
开发者ID:fbiville,项目名称:neo4j-sproc-compiler,代码行数:21,代码来源:ProcedureTest.java

示例6: calls_procedures_with_simple_input_type_returning_record_with_primitive_fields

import org.neo4j.driver.v1.Driver; //导入依赖的package包/类
@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')" ).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();
    }

}
 
开发者ID:fbiville,项目名称:neo4j-sproc-compiler,代码行数:20,代码来源:ProcedureTest.java

示例7: Neo4JGraph

import org.neo4j.driver.v1.Driver; //导入依赖的package包/类
/**
 * Creates a {@link Neo4JGraph} instance.
 *
 * @param driver           The {@link Driver} instance with the database connection information.
 * @param vertexIdProvider The {@link Neo4JElementIdProvider} for the {@link Vertex} id generation.
 * @param edgeIdProvider   The {@link Neo4JElementIdProvider} for the {@link Edge} id generation.
 */
public Neo4JGraph(Driver driver, Neo4JElementIdProvider<?> vertexIdProvider, Neo4JElementIdProvider<?> edgeIdProvider) {
    Objects.requireNonNull(driver, "driver cannot be null");
    Objects.requireNonNull(vertexIdProvider, "vertexIdProvider cannot be null");
    Objects.requireNonNull(edgeIdProvider, "edgeIdProvider cannot be null");
    // no label partition
    this.partition = new NoReadPartition();
    this.vertexLabels = Collections.emptySet();
    // store driver instance
    this.driver = driver;
    // store providers
    this.vertexIdProvider = vertexIdProvider;
    this.edgeIdProvider = edgeIdProvider;
    // graph factory configuration (required for tinkerpop test suite)
    this.configuration = null;
}
 
开发者ID:SteelBridgeLabs,项目名称:neo4j-gremlin-bolt,代码行数:23,代码来源:Neo4JGraph.java

示例8: loadProvider

import org.neo4j.driver.v1.Driver; //导入依赖的package包/类
static Neo4JElementIdProvider<?> loadProvider(Driver driver, String className) throws ClassNotFoundException, IllegalAccessException, InstantiationException {
    // check class name
    if (className != null) {
        // load class
        Class<?> type = Class.forName(className);
        try {
            // check class has constructor with a Driver parameter
            Constructor<?> constructor = type.getConstructor(Driver.class);
            // create instance
            return (Neo4JElementIdProvider<?>)constructor.newInstance(driver);
        }
        catch (NoSuchMethodException | InvocationTargetException ex) {
            // create instance
            return (Neo4JElementIdProvider<?>)type.newInstance();
        }
    }
    return null;
}
 
开发者ID:SteelBridgeLabs,项目名称:neo4j-gremlin-bolt,代码行数:19,代码来源:Neo4JGraphFactory.java

示例9: clear

import org.neo4j.driver.v1.Driver; //导入依赖的package包/类
@Override
public void clear(Graph graph, Configuration configuration) throws Exception {
    // check graph instance
    if (graph != null) {
        // close graph instance
        graph.close();
    }
    // connect to server
    try (Driver driver = GraphDatabase.driver(configuration.getString(Neo4JGraphConfigurationBuilder.Neo4JUrlConfigurationKey), AuthTokens.basic(configuration.getString(Neo4JGraphConfigurationBuilder.Neo4JUsernameConfigurationKey), configuration.getString(Neo4JGraphConfigurationBuilder.Neo4JPasswordConfigurationKey)), Config.defaultConfig())) {
        // open session
        try (Session session = driver.session()) {
            // begin transaction
            try (org.neo4j.driver.v1.Transaction transaction = session.beginTransaction()) {
                // delete everything in database
                transaction.run(new Statement("MATCH (n) DETACH DELETE n"));
                // commit
                transaction.success();
            }
        }
    }
}
 
开发者ID:SteelBridgeLabs,项目名称:neo4j-gremlin-bolt,代码行数:22,代码来源:Neo4JTestGraphProvider.java

示例10: exceptionsFromSilentDisconnectAreSuppressedToReportOriginalErrors

import org.neo4j.driver.v1.Driver; //导入依赖的package包/类
@Test
public void exceptionsFromSilentDisconnectAreSuppressedToReportOriginalErrors() throws CommandException {
    Session session = mock(Session.class);
    StatementResult resultMock = mock(StatementResult.class);

    RuntimeException originalException = new RuntimeException("original exception");
    RuntimeException thrownFromSilentDisconnect = new RuntimeException("exception from silent disconnect");


    Driver mockedDriver = stubVersionInAnOpenSession(resultMock, session, "neo4j-version");
    OfflineBoltStateHandler boltStateHandler = new OfflineBoltStateHandler(mockedDriver);

    when(resultMock.consume()).thenThrow(originalException);
    doThrow(thrownFromSilentDisconnect).when(session).close();

    try {
        boltStateHandler.connect();
        fail("should fail on silent disconnect");
    } catch (Exception e) {
        assertThat(e.getSuppressed()[0], is(thrownFromSilentDisconnect));
        assertThat(e, is(originalException));
    }
}
 
开发者ID:neo4j,项目名称:cypher-shell,代码行数:24,代码来源:BoltStateHandlerTest.java

示例11: shouldRunCypherQuery

import org.neo4j.driver.v1.Driver; //导入依赖的package包/类
@Test
public void shouldRunCypherQuery() throws CommandException {
    Session sessionMock = mock(Session.class);
    StatementResult versionMock = mock(StatementResult.class);
    StatementResult resultMock = mock(StatementResult.class);
    Record recordMock = mock(Record.class);
    Value valueMock = mock(Value.class);

    Driver driverMock = stubVersionInAnOpenSession(versionMock, sessionMock, "neo4j-version");

    when(resultMock.list()).thenReturn(asList(recordMock));

    when(valueMock.toString()).thenReturn("999");
    when(recordMock.get(0)).thenReturn(valueMock);
    when(sessionMock.run(any(Statement.class))).thenReturn(resultMock);

    OfflineBoltStateHandler boltStateHandler = new OfflineBoltStateHandler(driverMock);

    boltStateHandler.connect();

    BoltResult boltResult = boltStateHandler.runCypher("RETURN 999",
            new HashMap<>()).get();
    verify(sessionMock).run(any(Statement.class));

    assertEquals("999", boltResult.getRecords().get(0).get(0).toString());
}
 
开发者ID:neo4j,项目名称:cypher-shell,代码行数:27,代码来源:BoltStateHandlerTest.java

示例12: resetSessionOnReset

import org.neo4j.driver.v1.Driver; //导入依赖的package包/类
@Test
public void resetSessionOnReset() throws Exception {
    // given
    Session sessionMock = mock(Session.class);
    Driver driverMock = stubVersionInAnOpenSession(mock(StatementResult.class), sessionMock, "neo4j-version");

    OfflineBoltStateHandler boltStateHandler = new OfflineBoltStateHandler(driverMock);

    boltStateHandler.connect();
    boltStateHandler.beginTransaction();

    // when
    boltStateHandler.reset();

    // then
    verify(sessionMock).reset();
    assertNull(boltStateHandler.getTransactionStatements());
}
 
开发者ID:neo4j,项目名称:cypher-shell,代码行数:19,代码来源:BoltStateHandlerTest.java

示例13: executeShouldPrintResult

import org.neo4j.driver.v1.Driver; //导入依赖的package包/类
@Test
public void executeShouldPrintResult() throws CommandException {
    Driver mockedDriver = mock(Driver.class);
    Session session = mock(Session.class);
    BoltResult result = mock(BoltResult.class);

    BoltStateHandler boltStateHandler = mock(BoltStateHandler.class);

    when(boltStateHandler.isConnected()).thenReturn(true);
    when(boltStateHandler.runCypher(anyString(), anyMap())).thenReturn(Optional.of(result));
    when(mockedPrettyPrinter.format(result)).thenReturn("999");
    when(mockedDriver.session()).thenReturn(session);

    OfflineTestShell shell = new OfflineTestShell(logger, boltStateHandler, mockedPrettyPrinter);
    shell.execute("RETURN 999");
    verify(logger).printOut(contains("999"));
}
 
开发者ID:neo4j,项目名称:cypher-shell,代码行数:18,代码来源:CypherShellTest.java

示例14: executeOperation

import org.neo4j.driver.v1.Driver; //导入依赖的package包/类
@Override
public void executeOperation(LdbcUpdate2AddPostLike operation,
    DbConnectionState dbConnectionState,
    ResultReporter reporter) throws DbException {

  Driver driver = ((Neo4jDbConnectionState) dbConnectionState).getDriver();

  try (Session session = driver.session(AccessMode.WRITE)) {
    try (Transaction tx = session.beginTransaction()) {
      String statement =
          "   MATCH (p:Person {id:{personId}}),"
          + "       (m:Post {id:{postId}})"
          + " CREATE (p)-[:LIKES {creationDate:{creationDate}}]->(m)";
      Value parameters = parameters(
          "personId", String.valueOf(operation.personId()),
          "postId", String.valueOf(operation.postId()),
          "creationDate", operation.creationDate().getTime());

      tx.run(statement, parameters);
      tx.success();
      tx.close();
    }
  }

  reporter.report(0, LdbcNoResult.INSTANCE, operation);
}
 
开发者ID:PlatformLab,项目名称:ldbc-snb-impls,代码行数:27,代码来源:Neo4jDb.java

示例15: bolt

import org.neo4j.driver.v1.Driver; //导入依赖的package包/类
@Test
public void bolt() throws Exception {
  new MockUnit(Env.class, Config.class, Binder.class)
      .expect(hasPath("db.url", true))
      .expect(confString("db.url", "bolt://localhost:7687"))
      .expect(hasPath("com.graphaware", false))
      .expect(hasPath("neo4j", false))
      .expect(hasPath("db", true))
      .expect(confConf("db", ConfigFactory.empty()))
      .expect(hasPath("neo4j.db", false))
      .expect(serviceKey())
      .expect(confString("db.user", "test"))
      .expect(confString("db.password", "test"))
      .expect(bolt("bolt://localhost:7687", "db", "test", "test"))
      .expect(props())
      .expect(setProp("server_root_uri", "bolt://localhost:7687"))
      .expect(boltAccess("db"))
      .expect(logdb("bolt://localhost:7687", null))
      .expect(onStop())
      .run(unit -> {
            Neo4j neo4j = new Neo4j();
            neo4j.configure(unit.get(Env.class), unit.get(Config.class), unit.get(Binder.class));
          }, closeOnStop(),
          bind(Driver.class, 0),
          bind(Session.class, 1));
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:27,代码来源:Neo4jTest.java


注:本文中的org.neo4j.driver.v1.Driver类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。