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;
}
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);
}
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();
}
}
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;
}
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;
}
Aggregations