Search in sources :

Example 1 with RelationshipType

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);
}
Also used : Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) RelationshipType(org.neo4j.graphdb.RelationshipType) Test(org.junit.Test)

Example 2 with RelationshipType

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);
        }
    }
}
Also used : Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) RelationshipType(org.neo4j.graphdb.RelationshipType)

Example 3 with RelationshipType

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();
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Relationship(org.neo4j.graphdb.Relationship) Node(org.neo4j.graphdb.Node) RelationshipType(org.neo4j.graphdb.RelationshipType) ReadableRelationshipIndex(org.neo4j.graphdb.index.ReadableRelationshipIndex) Test(org.junit.Test)

Example 4 with RelationshipType

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);
}
Also used : RelationshipType(org.neo4j.graphdb.RelationshipType) ConstraintDefinition(org.neo4j.graphdb.schema.ConstraintDefinition)

Example 5 with RelationshipType

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));
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) RelationshipType(org.neo4j.graphdb.RelationshipType) Test(org.junit.Test)

Aggregations

RelationshipType (org.neo4j.graphdb.RelationshipType)147 Node (org.neo4j.graphdb.Node)84 Relationship (org.neo4j.graphdb.Relationship)59 Transaction (org.neo4j.graphdb.Transaction)52 Test (org.junit.Test)35 Test (org.junit.jupiter.api.Test)32 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)20 Direction (org.neo4j.graphdb.Direction)19 Label (org.neo4j.graphdb.Label)18 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)15 InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)15 ArrayList (java.util.ArrayList)13 NotFoundException (org.neo4j.graphdb.NotFoundException)10 Traverser (org.neo4j.graphdb.Traverser)10 HashSet (java.util.HashSet)9 RelationshipRecord (org.neo4j.kernel.impl.nioneo.store.RelationshipRecord)7 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)7 Collection (java.util.Collection)6 HashMap (java.util.HashMap)6 LinkedList (java.util.LinkedList)6