Search in sources :

Example 21 with Node

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

the class BidirectionalTraversalBranchPath method gatherNodes.

private Iterable<Node> gatherNodes(TraversalBranch first, TraversalBranch then) {
    // TODO Don't loop through them all up front
    LinkedList<Node> nodes = new LinkedList<>();
    TraversalBranch branch = first;
    while (branch.length() > 0) {
        nodes.addFirst(branch.endNode());
        branch = branch.parent();
    }
    if (cachedStartNode == null && first == start && branch.length() >= 0) {
        cachedStartNode = branch.endNode();
    }
    nodes.addFirst(branch.endNode());
    branch = then.parent();
    if (branch != null) {
        while (branch.length() > 0) {
            nodes.add(branch.endNode());
            branch = branch.parent();
        }
        if (branch.length() >= 0) {
            nodes.add(branch.endNode());
        }
    }
    if (cachedStartNode == null && then == start && branch.length() >= 0) {
        cachedStartNode = branch.endNode();
    }
    return nodes;
}
Also used : Node(org.neo4j.graphdb.Node) LinkedList(java.util.LinkedList) TraversalBranch(org.neo4j.graphdb.traversal.TraversalBranch)

Example 22 with Node

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

the class CreateAndLoadDenseNodeIT method loadSpecificTypeDirectionRelationshipsFast.

@Test
public void loadSpecificTypeDirectionRelationshipsFast() throws Exception {
    // GIVEN
    Node node;
    try (Transaction tx = db.beginTx()) {
        node = db.getNodeById(0);
        tx.success();
    }
    // WHEN
    loadRelationships(node, MyRelTypes.TEST, INCOMING);
    loadRelationships(node, MyRelTypes.TEST2, OUTGOING);
    loadRelationships(node, MyRelTypes.TEST_TRAVERSAL, INCOMING);
}
Also used : BatchTransaction(org.neo4j.test.BatchTransaction) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) Test(org.junit.Test)

Example 23 with Node

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

the class CreateAndLoadDenseNodeIT method createRelationships.

private void createRelationships(BatchTransaction tx, Node node, RelationshipType type, Direction direction, int count) {
    for (int i = 0; i < count; i++) {
        Node firstNode = direction == OUTGOING || direction == BOTH ? node : db.createNode();
        Node otherNode = direction == INCOMING || direction == BOTH ? node : db.createNode();
        firstNode.createRelationshipTo(otherNode, type);
        tx.increment();
    }
}
Also used : Node(org.neo4j.graphdb.Node)

Example 24 with Node

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

the class TraversalBranchImpl method next.

@Override
public TraversalBranch next(PathExpander expander, TraversalContext context) {
    if (relationships == null) {
        expandRelationships(expander);
    }
    while (relationships.hasNext()) {
        Relationship relationship = relationships.next();
        if (relationship.equals(howIGotHere)) {
            context.unnecessaryRelationshipTraversed();
            continue;
        }
        expandedCount++;
        Node node = relationship.getOtherNode(source);
        // TODO maybe an unnecessary instantiation. Instead pass in this+node+relationship to uniqueness check
        TraversalBranch next = newNextBranch(node, relationship);
        if (context.isUnique(next)) {
            context.relationshipTraversed();
            next.initialize(expander, context);
            return next;
        } else {
            context.unnecessaryRelationshipTraversed();
        }
    }
    // Just to help GC
    relationships = PRUNED_ITERATOR;
    return null;
}
Also used : Relationship(org.neo4j.graphdb.Relationship) Node(org.neo4j.graphdb.Node) TraversalBranch(org.neo4j.graphdb.traversal.TraversalBranch)

Example 25 with Node

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

the class TestReferenceDangling method ensurePropertyIsCachedLazyProperty.

private long ensurePropertyIsCachedLazyProperty(GraphDatabaseAPI slave, String key) {
    long nId;
    try (Transaction tx = slave.beginTx()) {
        Node n = slave.createNode();
        nId = n.getId();
        n.setProperty(key, new long[] { -1, 2, 2, 3, 4, 5, 5 });
        tx.success();
    }
    try (Transaction tx = slave.beginTx()) {
        slave.getNodeById(nId).hasProperty(key);
        tx.success();
    }
    return nId;
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node)

Aggregations

Node (org.neo4j.graphdb.Node)1271 Test (org.junit.Test)781 Transaction (org.neo4j.graphdb.Transaction)540 Relationship (org.neo4j.graphdb.Relationship)372 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)146 NotFoundException (org.neo4j.graphdb.NotFoundException)78 File (java.io.File)65 HashMap (java.util.HashMap)57 Label (org.neo4j.graphdb.Label)57 RelationshipType (org.neo4j.graphdb.RelationshipType)57 LinkedList (java.util.LinkedList)56 Path (org.neo4j.graphdb.Path)52 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)46 HashSet (java.util.HashSet)45 Map (java.util.Map)44 WeightedPath (org.neo4j.graphalgo.WeightedPath)37 TestGraphDatabaseFactory (org.neo4j.test.TestGraphDatabaseFactory)35 ArrayList (java.util.ArrayList)30 List (java.util.List)27 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)26