use of org.neo4j.graphdb.RelationshipType in project neo4j by neo4j.
the class TestRelationship method deleteRelsWithCommitInMiddle.
@Test
public void deleteRelsWithCommitInMiddle() throws Exception {
Node node = getGraphDb().createNode();
Node otherNode = getGraphDb().createNode();
RelationshipType[] types = new RelationshipType[] { withName("r1"), withName("r2"), withName("r3"), withName("r4") };
// 30*4 > 100 (rel grabSize)
int count = 30;
for (int i = 0; i < types.length * count; i++) {
node.createRelationshipTo(otherNode, types[i % types.length]);
}
newTransaction();
int delCount = 0;
int loopCount = 0;
while (delCount < count) {
loopCount++;
for (Relationship rel : node.getRelationships(types[1])) {
rel.delete();
if (++delCount == count / 2) {
newTransaction();
}
}
}
assertEquals(1, loopCount);
assertEquals(count, delCount);
}
use of org.neo4j.graphdb.RelationshipType in project neo4j by neo4j.
the class Ls method displayRelationships.
private void displayRelationships(AppCommandParser parser, NodeOrRelationship thing, Session session, Output out, boolean verbose, boolean quiet, Map<String, Object> filterMap, boolean caseInsensitiveFilters, boolean looseFilters, boolean brief) throws ShellException, RemoteException {
boolean sortByType = parser.options().containsKey("s");
Node node = thing.asNode();
Iterable<Relationship> relationships = getRelationships(node, filterMap, caseInsensitiveFilters, looseFilters, sortByType | brief);
if (brief) {
Iterator<Relationship> iterator = relationships.iterator();
if (!iterator.hasNext()) {
return;
}
Relationship sampleRelationship = iterator.next();
RelationshipType lastType = sampleRelationship.getType();
int currentCounter = 1;
while (iterator.hasNext()) {
Relationship rel = iterator.next();
if (!rel.isType(lastType)) {
displayBriefRelationships(thing, session, out, sampleRelationship, currentCounter);
sampleRelationship = rel;
lastType = sampleRelationship.getType();
currentCounter = 1;
} else {
currentCounter++;
}
}
displayBriefRelationships(thing, session, out, sampleRelationship, currentCounter);
} else {
Iterator<Relationship> iterator = relationships.iterator();
if (parser.options().containsKey("m")) {
iterator = wrapInLimitingIterator(parser, iterator, filterMap, caseInsensitiveFilters, looseFilters);
}
while (iterator.hasNext()) {
Relationship rel = iterator.next();
StringBuffer buf = new StringBuffer(getDisplayName(getServer(), session, thing, true));
String relDisplay = quiet ? "" : getDisplayName(getServer(), session, rel, verbose, true);
buf.append(withArrows(rel, relDisplay, thing.asNode()));
buf.append(getDisplayName(getServer(), session, rel.getOtherNode(node), true));
out.println(buf);
}
}
}
use of org.neo4j.graphdb.RelationshipType in project neo4j by neo4j.
the class AutoIndexOperationsTest method shouldNotSeeDeletedRelationshipWhenQueryingWithStartAndEndNode.
@Test
public void shouldNotSeeDeletedRelationshipWhenQueryingWithStartAndEndNode() {
RelationshipType type = MyRelTypes.TEST;
long startId;
long endId;
Relationship rel;
try (Transaction tx = db.beginTx()) {
Node start = db.createNode();
Node end = db.createNode();
startId = start.getId();
endId = end.getId();
rel = start.createRelationshipTo(end, type);
rel.setProperty("Type", type.name());
tx.success();
}
try (Transaction tx = db.beginTx()) {
ReadableRelationshipIndex autoRelationshipIndex = db.index().getRelationshipAutoIndexer().getAutoIndex();
Node start = db.getNodeById(startId);
Node end = db.getNodeById(endId);
IndexHits<Relationship> hits = autoRelationshipIndex.get("Type", type.name(), start, end);
assertEquals(1, count(hits));
assertEquals(1, hits.size());
rel.delete();
autoRelationshipIndex = db.index().getRelationshipAutoIndexer().getAutoIndex();
hits = autoRelationshipIndex.get("Type", type.name(), start, end);
assertEquals(0, count(hits));
assertEquals(0, hits.size());
tx.success();
}
}
use of org.neo4j.graphdb.RelationshipType in project neo4j by neo4j.
the class DatabaseActions method filteredRelationshipConstraints.
private Iterable<ConstraintDefinition> filteredRelationshipConstraints(String typeName, Predicate<ConstraintDefinition> filter) {
RelationshipType type = RelationshipType.withName(typeName);
Iterable<ConstraintDefinition> constraints = graphDb.schema().getConstraints(type);
return filter(filter, constraints);
}
use of org.neo4j.graphdb.RelationshipType in project neo4j by neo4j.
the class TestImpermanentGraphDatabase method should_remove_all_data.
@Test
public void should_remove_all_data() {
try (Transaction tx = db.beginTx()) {
RelationshipType relationshipType = RelationshipType.withName("R");
Node n1 = db.createNode();
Node n2 = db.createNode();
Node n3 = db.createNode();
n1.createRelationshipTo(n2, relationshipType);
n2.createRelationshipTo(n1, relationshipType);
n3.createRelationshipTo(n1, relationshipType);
tx.success();
}
cleanDatabaseContent(db);
assertThat(nodeCount(), is(0L));
}
Aggregations