Search in sources :

Example 1 with RelationshipIterator

use of org.neo4j.kernel.impl.api.store.RelationshipIterator in project neo4j by neo4j.

the class CompiledExpandUtils method connectingRelationships.

public static RelationshipIterator connectingRelationships(ReadOperations readOperations, long fromNode, Direction direction, long toNode) throws EntityNotFoundException {
    int fromDegree = readOperations.nodeGetDegree(fromNode, direction);
    if (fromDegree == 0) {
        return RelationshipIterator.EMPTY;
    }
    int toDegree = readOperations.nodeGetDegree(toNode, direction.reverse());
    if (toDegree == 0) {
        return RelationshipIterator.EMPTY;
    }
    long startNode;
    long endNode;
    Direction relDirection;
    if (fromDegree < toDegree) {
        startNode = fromNode;
        endNode = toNode;
        relDirection = direction;
    } else {
        startNode = toNode;
        endNode = fromNode;
        relDirection = direction.reverse();
    }
    RelationshipIterator allRelationships = readOperations.nodeGetRelationships(startNode, relDirection);
    return connectingRelationshipsIterator(allRelationships, startNode, endNode);
}
Also used : RelationshipIterator(org.neo4j.kernel.impl.api.store.RelationshipIterator) Direction(org.neo4j.graphdb.Direction)

Example 2 with RelationshipIterator

use of org.neo4j.kernel.impl.api.store.RelationshipIterator in project neo4j by neo4j.

the class RelationshipChangesForNodeTest method testIncomingRelsWithTypeAndLoop.

@Test
public void testIncomingRelsWithTypeAndLoop() throws Exception {
    RelationshipChangesForNode changes = new RelationshipChangesForNode(RelationshipChangesForNode.DiffStrategy.ADD, mock(RelationshipVisitor.Home.class));
    changes.addRelationship(REL_0, TYPE_SELF, Direction.BOTH);
    changes.addRelationship(REL_1, TYPE_DIR, INCOMING);
    RelationshipIterator iterator = changes.augmentRelationships(INCOMING, new int[] { TYPE_DIR }, EMPTY);
    assertEquals(true, iterator.hasNext());
    assertEquals(REL_1, iterator.next());
    assertEquals("should have no next relationships but has ", false, iterator.hasNext());
}
Also used : RelationshipIterator(org.neo4j.kernel.impl.api.store.RelationshipIterator) Test(org.junit.Test)

Example 3 with RelationshipIterator

use of org.neo4j.kernel.impl.api.store.RelationshipIterator in project neo4j by neo4j.

the class CompiledExpandUtils method connectingRelationships.

public static RelationshipIterator connectingRelationships(ReadOperations readOperations, long fromNode, Direction direction, long toNode, int[] relTypes) throws EntityNotFoundException {
    int fromDegree = calculateTotalDegree(readOperations, fromNode, direction, relTypes);
    if (fromDegree == 0) {
        return RelationshipIterator.EMPTY;
    }
    int toDegree = calculateTotalDegree(readOperations, toNode, direction.reverse(), relTypes);
    if (toDegree == 0) {
        return RelationshipIterator.EMPTY;
    }
    long startNode;
    long endNode;
    Direction relDirection;
    if (fromDegree < toDegree) {
        startNode = fromNode;
        endNode = toNode;
        relDirection = direction;
    } else {
        startNode = toNode;
        endNode = fromNode;
        relDirection = direction.reverse();
    }
    RelationshipIterator allRelationships = readOperations.nodeGetRelationships(startNode, relDirection, relTypes);
    return connectingRelationshipsIterator(allRelationships, startNode, endNode);
}
Also used : RelationshipIterator(org.neo4j.kernel.impl.api.store.RelationshipIterator) Direction(org.neo4j.graphdb.Direction)

Example 4 with RelationshipIterator

use of org.neo4j.kernel.impl.api.store.RelationshipIterator in project neo4j by neo4j.

the class RelationshipChangesForNodeTest method testOutgoingRelsWithTypeAndLoop.

@Test
public void testOutgoingRelsWithTypeAndLoop() throws Exception {
    RelationshipChangesForNode changes = new RelationshipChangesForNode(RelationshipChangesForNode.DiffStrategy.ADD, mock(RelationshipVisitor.Home.class));
    changes.addRelationship(REL_0, TYPE_SELF, Direction.BOTH);
    changes.addRelationship(REL_1, TYPE_DIR, OUTGOING);
    RelationshipIterator iterator = changes.augmentRelationships(OUTGOING, new int[] { TYPE_DIR }, EMPTY);
    assertEquals(true, iterator.hasNext());
    assertEquals(REL_1, iterator.next());
    assertEquals("should have no next relationships but has ", false, iterator.hasNext());
}
Also used : RelationshipIterator(org.neo4j.kernel.impl.api.store.RelationshipIterator) Test(org.junit.Test)

Aggregations

RelationshipIterator (org.neo4j.kernel.impl.api.store.RelationshipIterator)4 Test (org.junit.Test)2 Direction (org.neo4j.graphdb.Direction)2