Search in sources :

Example 91 with Session

use of org.neo4j.driver.v1.Session in project open-kilda by telstra.

the class NeoDriver method getFlowInfo.

/**
 * {@inheritDoc}
 */
@Override
public List<FlowInfo> getFlowInfo() {
    List<FlowInfo> flows = new ArrayList<>();
    String subject = "MATCH (:switch)-[f:flow]->(:switch) " + "RETURN f.flowid as flow_id, " + " f.cookie as cookie, " + " f.meter_id as meter_id, " + " f.transit_vlan as transit_vlan, " + " f.src_switch as src_switch";
    Session session = driver.session();
    StatementResult result = session.run(subject);
    for (Record record : result.list()) {
        flows.add(new FlowInfo().setFlowId(record.get("flow_id").asString()).setSrcSwitchId(record.get("src_switch").asString()).setCookie(record.get("cookie").asLong()).setMeterId(record.get("meter_id").asInt()).setTransitVlanId(record.get("transit_vlan").asInt()));
    }
    return flows;
}
Also used : StatementResult(org.neo4j.driver.v1.StatementResult) Record(org.neo4j.driver.v1.Record) Session(org.neo4j.driver.v1.Session)

Example 92 with Session

use of org.neo4j.driver.v1.Session in project acceptance-test-harness by jenkinsci.

the class Ssh method executeRemoteCommand.

public int executeRemoteCommand(String cmd, OutputStream os) {
    Session session = null;
    try {
        session = connection.openSession();
        int status = connection.exec(cmd, os);
        if (status != 0) {
            throw new RuntimeException("Failed to execute command: " + cmd + ", exit code = " + status);
        }
        return status;
    } catch (InterruptedException | IOException e) {
        throw new AssertionError(e);
    } finally {
        if (session != null) {
            session.close();
        }
    }
}
Also used : IOException(java.io.IOException) Session(com.trilead.ssh2.Session)

Example 93 with Session

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

the class Neo4JServerLiveTest method standAloneDriver.

@Test
public void standAloneDriver() {
    Driver driver = GraphDatabase.driver("bolt://localhost:7687", AuthTokens.basic("neo4j", "12345"));
    Session session = driver.session();
    session.run("CREATE (baeldung:Company {name:\"Baeldung\"}) " + "-[:owns]-> (tesla:Car {make: 'tesla', model: 'modelX'})" + "RETURN baeldung, tesla");
    StatementResult result = session.run("MATCH (company:Company)-[:owns]-> (car:Car)" + "WHERE car.make='tesla' and car.model='modelX'" + "RETURN company.name");
    Assert.assertTrue(result.hasNext());
    Assert.assertEquals(result.next().get("company.name").asString(), "Baeldung");
    session.close();
    driver.close();
}
Also used : StatementResult(org.neo4j.driver.v1.StatementResult) Driver(org.neo4j.driver.v1.Driver) Session(org.neo4j.driver.v1.Session) Test(org.junit.Test)

Example 94 with Session

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

the class BoltDatabaseService method createUUIDConstraint.

// ----- private methods -----
private void createUUIDConstraint() {
    // add UUID uniqueness constraint
    try (final Session session = driver.session()) {
        // this call may fail silently (e.g. if the index does not exist yet)
        try (final org.neo4j.driver.v1.Transaction tx = session.beginTransaction()) {
            tx.run("DROP INDEX ON :NodeInterface(id)");
            tx.success();
        } catch (Throwable t) {
        }
        // this call may NOT fail silently, hence we don't catch any exceptions
        try (final org.neo4j.driver.v1.Transaction tx = session.beginTransaction()) {
            tx.run("CREATE CONSTRAINT ON (node:NodeInterface) ASSERT node.id IS UNIQUE");
            tx.success();
        }
    }
}
Also used : Session(org.neo4j.driver.v1.Session)

Example 95 with Session

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

the class BoltDatabaseService method beginTx.

@Override
public Transaction beginTx() {
    SessionTransaction session = sessions.get();
    if (session == null || session.isClosed()) {
        try {
            session = new SessionTransaction(this, driver.session());
            sessions.set(session);
        } catch (ServiceUnavailableException ex) {
            throw new NetworkException(ex.getMessage(), ex);
        } catch (ClientException cex) {
            logger.warn("Cannot connect to Neo4j database server at {}: {}", databaseUrl, cex.getMessage());
        }
    }
    return session;
}
Also used : ServiceUnavailableException(org.neo4j.driver.v1.exceptions.ServiceUnavailableException) ClientException(org.neo4j.driver.v1.exceptions.ClientException) NetworkException(org.structr.api.NetworkException)

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