Search in sources :

Example 16 with Relationship

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

the class RelationshipProxyTest method shouldPrintCypherEsqueRelationshipToString.

@Test
public void shouldPrintCypherEsqueRelationshipToString() throws Exception {
    // GIVEN
    Node start, end;
    RelationshipType type = RelationshipType.withName("NICE");
    Relationship relationship;
    try (Transaction tx = db.beginTx()) {
        // GIVEN
        start = db.createNode();
        end = db.createNode();
        relationship = start.createRelationshipTo(end, type);
        tx.success();
        // WHEN
        String toString = relationship.toString();
        // THEN
        assertEquals("(" + start.getId() + ")-[" + type + "," + relationship.getId() + "]->(" + end.getId() + ")", toString);
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) RelationshipType(org.neo4j.graphdb.RelationshipType) Test(org.junit.Test)

Example 17 with Relationship

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

the class TestDenseNodeRelChainPositionIT method givenDenseNodeWhenAskForWrongDirectionThenIncorrectNrOfRelsReturned.

/*
     * Tests for a particular bug with dense nodes. It used to be that if a dense node had relationships
     * for only one direction, if a request for relationships of the other direction was made, no relationships
     * would be returned, ever.
     */
@Test
public void givenDenseNodeWhenAskForWrongDirectionThenIncorrectNrOfRelsReturned() throws Exception {
    // Given
    final int denseNodeThreshold = Integer.parseInt(GraphDatabaseSettings.dense_node_threshold.getDefaultValue()) + // We must be over the dense node threshold for the bug to manifest
    1;
    Node node1;
    try (Transaction tx = db.beginTx()) {
        node1 = db.createNode();
        Node node2 = db.createNode();
        for (int i = 0; i < denseNodeThreshold; i++) {
            node1.createRelationshipTo(node2, RelationshipType.withName("FOO"));
        }
        tx.success();
    }
    // When/Then
    try (Transaction ignored = db.beginTx()) {
        Node node1b = db.getNodeById(node1.getId());
        Iterable<Relationship> rels = node1b.getRelationships(Direction.INCOMING);
        assertEquals(0, Iterables.count(rels));
        Iterable<Relationship> rels2 = node1b.getRelationships(Direction.OUTGOING);
        assertEquals(denseNodeThreshold, Iterables.count(rels2));
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) Test(org.junit.Test)

Example 18 with Relationship

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

the class TestExceptionTypeOnInvalidIds method getRelationshipById.

private void getRelationshipById(long index) {
    Relationship value = graphdb.getRelationshipById(index);
    fail(String.format("Returned Relationship [0x%x] for index 0x%x (int value: 0x%x)", value.getId(), index, (int) index));
}
Also used : Relationship(org.neo4j.graphdb.Relationship)

Example 19 with Relationship

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

the class SubGraphExporter method appendRelationships.

private long appendRelationships(PrintWriter out) {
    long relationships = 0;
    for (Node node : graph.getNodes()) {
        for (Relationship rel : node.getRelationships(Direction.OUTGOING)) {
            appendRelationship(out, rel);
            relationships++;
        }
    }
    return relationships;
}
Also used : Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship)

Example 20 with Relationship

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

the class DeleteRelationshipStressIT method setup.

@Before
public void setup() {
    for (int i = 0; i < 100; i++) {
        try (Transaction tx = db.beginTx()) {
            Node prev = null;
            for (int j = 0; j < 100; j++) {
                Node node = db.createNode(label("L"));
                if (prev != null) {
                    Relationship rel = prev.createRelationshipTo(node, DynamicRelationshipType.withName("T"));
                    rel.setProperty("prop", i + j);
                }
                prev = node;
            }
            tx.success();
        }
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) Before(org.junit.Before)

Aggregations

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