Search in sources :

Example 71 with Relationship

use of org.neo4j.graphdb.Relationship in project graphdb by neo4j-attic.

the class TestRelationship method countRelationships.

private void countRelationships(int expectedCount, Iterable<Relationship> rels) {
    int count = 0;
    for (Relationship r : rels) {
        count++;
    }
    assertEquals(expectedCount, count);
}
Also used : Relationship(org.neo4j.graphdb.Relationship)

Example 72 with Relationship

use of org.neo4j.graphdb.Relationship in project graphdb by neo4j-attic.

the class TestRelationship method testRollbackDeleteRelationship.

@Test
public void testRollbackDeleteRelationship() {
    Node node1 = getGraphDb().createNode();
    Node node2 = getGraphDb().createNode();
    Relationship rel1 = node1.createRelationshipTo(node2, MyRelTypes.TEST);
    newTransaction();
    node1.delete();
    rel1.delete();
    getTransaction().failure();
    getTransaction().finish();
    setTransaction(getGraphDb().beginTx());
    node1.delete();
    node2.delete();
    rel1.delete();
}
Also used : Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) Test(org.junit.Test)

Example 73 with Relationship

use of org.neo4j.graphdb.Relationship in project graphdb by neo4j-attic.

the class TestRelationship method testSimple3.

@Test
public void testSimple3() {
    Node node1 = getGraphDb().createNode();
    Node node2 = getGraphDb().createNode();
    for (int i = 0; i < 1; i++) {
        node1.createRelationshipTo(node2, MyRelTypes.TEST);
        node1.createRelationshipTo(node2, MyRelTypes.TEST_TRAVERSAL);
        node1.createRelationshipTo(node2, MyRelTypes.TEST2);
    }
    allGetRelationshipMethods2(node1, Direction.OUTGOING);
    allGetRelationshipMethods2(node2, Direction.INCOMING);
    newTransaction();
    allGetRelationshipMethods2(node1, Direction.OUTGOING);
    allGetRelationshipMethods2(node2, Direction.INCOMING);
    node1.getRelationships(MyRelTypes.TEST, Direction.OUTGOING).iterator().next().delete();
    node1.getRelationships(MyRelTypes.TEST_TRAVERSAL, Direction.OUTGOING).iterator().next().delete();
    node1.getRelationships(MyRelTypes.TEST2, Direction.OUTGOING).iterator().next().delete();
    node1.createRelationshipTo(node2, MyRelTypes.TEST);
    node1.createRelationshipTo(node2, MyRelTypes.TEST_TRAVERSAL);
    node1.createRelationshipTo(node2, MyRelTypes.TEST2);
    allGetRelationshipMethods2(node1, Direction.OUTGOING);
    allGetRelationshipMethods2(node2, Direction.INCOMING);
    newTransaction();
    allGetRelationshipMethods2(node1, Direction.OUTGOING);
    allGetRelationshipMethods2(node2, Direction.INCOMING);
    for (Relationship rel : node1.getRelationships()) {
        rel.delete();
    }
    node1.delete();
    node2.delete();
}
Also used : Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) Test(org.junit.Test)

Example 74 with Relationship

use of org.neo4j.graphdb.Relationship in project graphdb by neo4j-attic.

the class TestRelationship method testRelationshipIsType.

@Test
public void testRelationshipIsType() {
    Node node1 = getGraphDb().createNode();
    Node node2 = getGraphDb().createNode();
    Relationship rel = node1.createRelationshipTo(node2, MyRelTypes.TEST);
    assertTrue(rel.isType(MyRelTypes.TEST));
    assertTrue(rel.isType(new RelationshipType() {

        public String name() {
            return MyRelTypes.TEST.name();
        }
    }));
    assertFalse(rel.isType(MyRelTypes.TEST_TRAVERSAL));
    rel.delete();
    node1.delete();
    node2.delete();
}
Also used : Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) RelationshipType(org.neo4j.graphdb.RelationshipType) Test(org.junit.Test)

Example 75 with Relationship

use of org.neo4j.graphdb.Relationship in project neo4j by neo4j.

the class LegacyIndexTest method createRelationshipLegacyIndexWithSingleRelationship.

private static void createRelationshipLegacyIndexWithSingleRelationship(GraphDatabaseService db, String indexName) {
    try (Transaction tx = db.beginTx()) {
        Relationship relationship = db.createNode().createRelationshipTo(db.createNode(), TYPE);
        Index<Relationship> relationshipIndexIndex = db.index().forRelationships(indexName);
        relationshipIndexIndex.add(relationship, "key", System.currentTimeMillis());
        tx.success();
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Relationship(org.neo4j.graphdb.Relationship)

Aggregations

Relationship (org.neo4j.graphdb.Relationship)490 Node (org.neo4j.graphdb.Node)370 Test (org.junit.Test)250 Transaction (org.neo4j.graphdb.Transaction)138 LinkedList (java.util.LinkedList)48 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)48 RelationshipType (org.neo4j.graphdb.RelationshipType)38 NotFoundException (org.neo4j.graphdb.NotFoundException)35 Path (org.neo4j.graphdb.Path)29 HashMap (java.util.HashMap)27 Direction (org.neo4j.graphdb.Direction)26 HashSet (java.util.HashSet)24 ArrayList (java.util.ArrayList)18 RelationshipIndex (org.neo4j.graphdb.index.RelationshipIndex)18 Map (java.util.Map)14 WeightedPath (org.neo4j.graphalgo.WeightedPath)14 EmbeddedGraphDatabase (org.neo4j.kernel.EmbeddedGraphDatabase)14 List (java.util.List)13 PropertyContainer (org.neo4j.graphdb.PropertyContainer)12 Graph (org.neo4j.test.GraphDescription.Graph)11