use of org.neo4j.graphdb.Relationship in project neo4j-clean-remote-db-addon by jexp.
the class Neo4jDatabaseCleaner method removeNodes.
private void removeNodes(Map<String, Object> result, long maxNodesToDelete) {
Node refNode = graph.getReferenceNode();
long nodes = 0, relationships = 0;
for (Node node : graph.getAllNodes()) {
for (Relationship rel : node.getRelationships()) {
rel.delete();
relationships++;
}
if (!refNode.equals(node)) {
node.delete();
nodes++;
}
if (nodes >= maxNodesToDelete)
break;
}
result.put("maxNodesToDelete", maxNodesToDelete);
result.put("nodes", nodes);
result.put("relationships", relationships);
}
use of org.neo4j.graphdb.Relationship in project neo4j-clean-remote-db-addon by jexp.
the class DeleteDatabaseTest method createData.
private void createData(GraphDatabaseAPI db, int max) {
Transaction tx = db.beginTx();
try {
final IndexManager indexManager = db.index();
Node[] nodes = new Node[max];
for (int i = 0; i < max; i++) {
nodes[i] = db.createNode();
final Index<Node> index = indexManager.forNodes("node_index_" + String.valueOf(i % 5));
index.add(nodes[i], "ID", i);
}
Random random = new Random();
for (int i = 0; i < max * 2; i++) {
int from = random.nextInt(max);
final int to = (from + 1 + random.nextInt(max - 1)) % max;
final Relationship relationship = nodes[from].createRelationshipTo(nodes[to], DynamicRelationshipType.withName("TEST_" + i));
final Index<Relationship> index = indexManager.forRelationships("rel_index_" + String.valueOf(i % 5));
index.add(relationship, "ID", i);
}
tx.success();
} finally {
tx.finish();
}
}
use of org.neo4j.graphdb.Relationship in project neo4j by neo4j.
the class ImportToolTest method verifyData.
private void verifyData(Validator<Node> nodeAdditionalValidation, Validator<Relationship> relationshipAdditionalValidation) {
GraphDatabaseService db = dbRule.getGraphDatabaseAPI();
try (Transaction tx = db.beginTx()) {
int nodeCount = 0, relationshipCount = 0;
for (Node node : db.getAllNodes()) {
assertTrue(node.hasProperty("name"));
nodeAdditionalValidation.validate(node);
nodeCount++;
}
assertEquals(NODE_COUNT, nodeCount);
for (Relationship relationship : db.getAllRelationships()) {
assertTrue(relationship.hasProperty("created"));
relationshipAdditionalValidation.validate(relationship);
relationshipCount++;
}
assertEquals(RELATIONSHIP_COUNT, relationshipCount);
tx.success();
}
}
use of org.neo4j.graphdb.Relationship 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.Relationship in project neo4j by neo4j.
the class BigStoreIT method testHighIds.
private void testHighIds(long highMark, int minus, int requiredHeapMb) throws IOException {
if (!machineIsOkToRunThisTest(requiredHeapMb)) {
return;
}
long idBelow = highMark - minus;
setHighIds(idBelow);
String propertyKey = "name";
int intPropertyValue = 123;
String stringPropertyValue = "Long string, longer than would fit in shortstring";
long[] arrayPropertyValue = new long[] { 1021L, 321L, 343212L };
Transaction tx = db.beginTx();
Node nodeBelowTheLine = db.createNode();
nodeBelowTheLine.setProperty(propertyKey, intPropertyValue);
assertEquals(idBelow, nodeBelowTheLine.getId());
Node nodeAboveTheLine = db.createNode();
nodeAboveTheLine.setProperty(propertyKey, stringPropertyValue);
Relationship relBelowTheLine = nodeBelowTheLine.createRelationshipTo(nodeAboveTheLine, this);
relBelowTheLine.setProperty(propertyKey, arrayPropertyValue);
assertEquals(idBelow, relBelowTheLine.getId());
Relationship relAboveTheLine = nodeAboveTheLine.createRelationshipTo(nodeBelowTheLine, this);
assertEquals(highMark, relAboveTheLine.getId());
assertEquals(highMark, nodeAboveTheLine.getId());
assertEquals(intPropertyValue, nodeBelowTheLine.getProperty(propertyKey));
assertEquals(stringPropertyValue, nodeAboveTheLine.getProperty(propertyKey));
assertTrue(Arrays.equals(arrayPropertyValue, (long[]) relBelowTheLine.getProperty(propertyKey)));
tx.success();
tx.close();
for (int i = 0; i < 2; i++) {
try (Transaction transaction = db.beginTx()) {
assertEquals(nodeAboveTheLine, db.getNodeById(highMark));
assertEquals(idBelow, nodeBelowTheLine.getId());
assertEquals(highMark, nodeAboveTheLine.getId());
assertEquals(idBelow, relBelowTheLine.getId());
assertEquals(highMark, relAboveTheLine.getId());
assertEquals(relBelowTheLine, db.getNodeById(idBelow).getSingleRelationship(this, Direction.OUTGOING));
assertEquals(relAboveTheLine, db.getNodeById(idBelow).getSingleRelationship(this, Direction.INCOMING));
assertEquals(idBelow, relBelowTheLine.getId());
assertEquals(highMark, relAboveTheLine.getId());
assertEquals(asSet(asList(relBelowTheLine, relAboveTheLine)), asSet(Iterables.asCollection(db.getNodeById(idBelow).getRelationships())));
transaction.success();
}
if (i == 0) {
db = dbRule.restartDatabase();
}
}
}
Aggregations