Search in sources :

Example 6 with Relationship

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

the class PathComputerTest method testGetFlowInfo.

@Test
public void testGetFlowInfo() {
    try (Transaction tx = graphDb.beginTx()) {
        Node node1, node2;
        node1 = graphDb.createNode(Label.label("switch"));
        node1.setProperty("name", "00:03");
        node2 = graphDb.createNode(Label.label("switch"));
        node2.setProperty("name", "00:04");
        Relationship rel1 = node1.createRelationshipTo(node2, RelationshipType.withName("flow"));
        rel1.setProperty("flowid", "f1");
        rel1.setProperty("cookie", 3);
        rel1.setProperty("meter_id", 2);
        rel1.setProperty("transit_vlan", 1);
        rel1.setProperty("src_switch", "00:03");
        tx.success();
    }
    Driver driver = GraphDatabase.driver("bolt://localhost:7878", AuthTokens.basic("neo4j", "password"));
    NeoDriver nd = new NeoDriver(driver);
    List<FlowInfo> fi = nd.getFlowInfo();
    Assert.assertEquals(fi.get(0).getFlowId(), "f1");
    Assert.assertEquals(fi.get(0).getCookie(), 3);
    Assert.assertEquals(fi.get(0).getMeterId(), 2);
    Assert.assertEquals(fi.get(0).getTransitVlanId(), 1);
    Assert.assertEquals(fi.get(0).getSrcSwitchId(), "00:03");
}
Also used : OkNode(org.openkilda.neo.OkNode) Driver(org.neo4j.driver.v1.Driver)

Example 7 with Relationship

use of org.neo4j.driver.v1.types.Relationship in project structr by structr.

the class SessionTransaction method close.

@Override
public void close() {
    if (!success) {
        // be sure that they contain the correct values after a rollback.
        for (final EntityWrapper entity : modifiedEntities) {
            entity.stale();
        }
    } else {
        // so that the relationship caches are rebuilt.
        for (final EntityWrapper entity : modifiedEntities) {
            entity.clearCaches();
        }
    }
    // mark this transaction as closed BEFORE trying to actually close it
    // so that it is closed in case of a failure
    closed = true;
    try {
        tx.close();
        session.close();
    } catch (TransientException tex) {
        // transient exceptions can be retried
        throw new RetryException(tex);
    } finally {
        // so that the relationship caches are rebuilt.
        for (final EntityWrapper entity : modifiedEntities) {
            entity.onClose();
        }
        // make sure that the resources are freed
        if (session.isOpen()) {
            session.close();
        }
    }
}
Also used : TransientException(org.neo4j.driver.v1.exceptions.TransientException) EntityWrapper(org.structr.bolt.wrapper.EntityWrapper) RetryException(org.structr.api.RetryException)

Aggregations

Relationship (org.neo4j.driver.v1.types.Relationship)4 Driver (org.neo4j.driver.v1.Driver)3 Record (org.neo4j.driver.v1.Record)3 Session (org.neo4j.driver.v1.Session)3 StatementResult (org.neo4j.driver.v1.StatementResult)3 Test (org.junit.Test)2 Node (org.neo4j.driver.v1.types.Node)2 VirtualNode (apoc.result.VirtualNode)1 VirtualRelationship (apoc.result.VirtualRelationship)1 File (java.io.File)1 InternalEntity (org.neo4j.driver.internal.InternalEntity)1 Statement (org.neo4j.driver.v1.Statement)1 NoSuchRecordException (org.neo4j.driver.v1.exceptions.NoSuchRecordException)1 ServiceUnavailableException (org.neo4j.driver.v1.exceptions.ServiceUnavailableException)1 TransientException (org.neo4j.driver.v1.exceptions.TransientException)1 Path (org.neo4j.driver.v1.types.Path)1 GraphDatabaseBuilder (org.neo4j.graphdb.factory.GraphDatabaseBuilder)1 GraphDatabaseFactory (org.neo4j.graphdb.factory.GraphDatabaseFactory)1 BoltConnector (org.neo4j.kernel.configuration.BoltConnector)1 PathInfoData (org.openkilda.messaging.info.event.PathInfoData)1