Search in sources :

Example 66 with Session

use of org.neo4j.driver.v1.Session in project neo4j by neo4j.

the class BoltCausalClusteringIT method shouldUseBookmarkFromAReadSessionInAWriteSession.

@Test
public void shouldUseBookmarkFromAReadSessionInAWriteSession() throws Exception {
    // given
    cluster = clusterRule.withNumberOfReadReplicas(1).startCluster();
    CoreClusterMember leader = cluster.awaitLeader();
    try (Driver driver = GraphDatabase.driver(leader.directURI(), AuthTokens.basic("neo4j", "neo4j"))) {
        inExpirableSession(driver, (d) -> d.session(AccessMode.WRITE), (session) -> {
            session.run("CREATE (p:Person {name: {name} })", Values.parameters("name", "Jim"));
            return null;
        });
        String bookmark;
        try (Session session = driver.session(AccessMode.READ)) {
            try (Transaction tx = session.beginTransaction()) {
                tx.run("MATCH (n:Person) RETURN COUNT(*) AS count").next();
                tx.success();
            }
            bookmark = session.lastBookmark();
        }
        assertNotNull(bookmark);
        inExpirableSession(driver, (d) -> d.session(AccessMode.WRITE), (session) -> {
            try (Transaction tx = session.beginTransaction(bookmark)) {
                tx.run("CREATE (p:Person {name: {name} })", Values.parameters("name", "Alistair"));
                tx.success();
            }
            return null;
        });
        try (Session session = driver.session()) {
            Record record = session.run("MATCH (n:Person) RETURN COUNT(*) AS count").next();
            assertEquals(2, record.get("count").asInt());
        }
    }
}
Also used : Transaction(org.neo4j.driver.v1.Transaction) CoreClusterMember(org.neo4j.causalclustering.discovery.CoreClusterMember) Driver(org.neo4j.driver.v1.Driver) Record(org.neo4j.driver.v1.Record) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Session(org.neo4j.driver.v1.Session) RoutingNetworkSession(org.neo4j.driver.internal.RoutingNetworkSession) Test(org.junit.Test)

Example 67 with Session

use of org.neo4j.driver.v1.Session in project neo4j by neo4j.

the class BoltCausalClusteringIT method executeReadQuery.

private void executeReadQuery(String bookmark, Session session) {
    try (Transaction tx = session.beginTransaction(bookmark)) {
        Record record = tx.run("MATCH (n:Person) RETURN COUNT(*) AS count").next();
        assertEquals(1, record.get("count").asInt());
    }
}
Also used : Transaction(org.neo4j.driver.v1.Transaction) Record(org.neo4j.driver.v1.Record)

Example 68 with Session

use of org.neo4j.driver.v1.Session in project neo4j by neo4j.

the class ProcedureTest method calls_procedures_with_simple_input_type_returning_void.

@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");
    }
}
Also used : Driver(org.neo4j.driver.v1.Driver) Session(org.neo4j.driver.v1.Session) Test(org.junit.Test)

Example 69 with Session

use of org.neo4j.driver.v1.Session in project neo4j by neo4j.

the class ProcedureTest method calls_procedures_with_simple_input_type_returning_record_with_primitive_fields.

@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();
    }
}
Also used : Driver(org.neo4j.driver.v1.Driver) Session(org.neo4j.driver.v1.Session) Test(org.junit.Test)

Example 70 with Session

use of org.neo4j.driver.v1.Session in project intellij-community by JetBrains.

the class Basic method main.

public static void main(String[] args) {
    String hostname = "127.0.0.1";
    String username = "joe";
    String password = "joespass";
    try {
        /* Create a connection instance */
        Connection conn = new Connection(hostname);
        /* Now connect */
        conn.connect();
        /* Authenticate.
			 * If you get an IOException saying something like
			 * "Authentication method password not supported by the server at this stage."
			 * then please check the FAQ.
			 */
        boolean isAuthenticated = conn.authenticateWithPassword(username, password);
        if (isAuthenticated == false)
            throw new IOException("Authentication failed.");
        /* Create a session */
        Session sess = conn.openSession();
        sess.execCommand("uname -a && date && uptime && who");
        System.out.println("Here is some information about the remote host:");
        /* 
			 * This basic example does not handle stderr, which is sometimes dangerous
			 * (please read the FAQ).
			 */
        InputStream stdout = new StreamGobbler(sess.getStdout());
        BufferedReader br = new BufferedReader(new InputStreamReader(stdout));
        while (true) {
            String line = br.readLine();
            if (line == null)
                break;
            System.out.println(line);
        }
        /* Show exit status, if available (otherwise "null") */
        System.out.println("ExitCode: " + sess.getExitStatus());
        /* Close this session */
        sess.close();
        /* Close the connection */
        conn.close();
    } catch (IOException e) {
        e.printStackTrace(System.err);
        System.exit(2);
    }
}
Also used : StreamGobbler(com.trilead.ssh2.StreamGobbler) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) Connection(com.trilead.ssh2.Connection) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) Session(com.trilead.ssh2.Session)

Aggregations

Session (com.trilead.ssh2.Session)43 Session (org.neo4j.driver.v1.Session)38 Connection (com.trilead.ssh2.Connection)32 IOException (java.io.IOException)30 Test (org.junit.Test)30 Driver (org.neo4j.driver.v1.Driver)29 InputStream (java.io.InputStream)28 StatementResult (org.neo4j.driver.v1.StatementResult)20 Record (org.neo4j.driver.v1.Record)15 Session (iaik.pkcs.pkcs11.Session)10 TokenException (iaik.pkcs.pkcs11.TokenException)10 CoreClusterMember (org.neo4j.causalclustering.discovery.CoreClusterMember)10 P11TokenException (org.xipki.security.exception.P11TokenException)10 RoutingNetworkSession (org.neo4j.driver.internal.RoutingNetworkSession)9 Session (ch.ethz.ssh2.Session)8 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)8 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)8 HttpException (org.apache.commons.httpclient.HttpException)8 Transaction (org.neo4j.driver.v1.Transaction)8 SCPClient (com.trilead.ssh2.SCPClient)6