Search in sources :

Example 1 with DirectionWrapper

use of org.neo4j.kernel.impl.util.DirectionWrapper in project neo4j by neo4j.

the class RelationshipCreator method connectRelationshipToDenseNode.

private void connectRelationshipToDenseNode(NodeRecord node, RelationshipRecord rel, RecordAccess<Long, RelationshipRecord, Void> relRecords, RecordAccess<Long, RelationshipGroupRecord, Integer> relGroupRecords, ResourceLocker locks) {
    RelationshipGroupRecord group = relGroupGetter.getOrCreateRelationshipGroup(node, rel.getType(), relGroupRecords).forChangingData();
    DirectionWrapper dir = DirectionIdentifier.wrapDirection(rel, node);
    long nextRel = dir.getNextRel(group);
    setCorrectNextRel(node, rel, nextRel);
    connect(node.getId(), nextRel, rel, relRecords, locks);
    dir.setNextRel(group, rel.getId());
}
Also used : DirectionWrapper(org.neo4j.kernel.impl.util.DirectionWrapper) RelationshipGroupRecord(org.neo4j.kernel.impl.store.record.RelationshipGroupRecord)

Example 2 with DirectionWrapper

use of org.neo4j.kernel.impl.util.DirectionWrapper in project neo4j by neo4j.

the class RelationshipDeleter method updateNodesForDeletedRelationship.

private void updateNodesForDeletedRelationship(RelationshipRecord rel, RecordAccessSet recordChanges, ResourceLocker locks) {
    RecordProxy<Long, NodeRecord, Void> startNodeChange = recordChanges.getNodeRecords().getOrLoad(rel.getFirstNode(), null);
    RecordProxy<Long, NodeRecord, Void> endNodeChange = recordChanges.getNodeRecords().getOrLoad(rel.getSecondNode(), null);
    NodeRecord startNode = recordChanges.getNodeRecords().getOrLoad(rel.getFirstNode(), null).forReadingLinkage();
    NodeRecord endNode = recordChanges.getNodeRecords().getOrLoad(rel.getSecondNode(), null).forReadingLinkage();
    boolean loop = startNode.getId() == endNode.getId();
    if (!startNode.isDense()) {
        if (rel.isFirstInFirstChain()) {
            startNode = startNodeChange.forChangingLinkage();
            startNode.setNextRel(rel.getFirstNextRel());
        }
        decrementTotalRelationshipCount(startNode.getId(), rel, startNode.getNextRel(), recordChanges.getRelRecords(), locks);
    } else {
        RecordProxy<Long, RelationshipGroupRecord, Integer> groupChange = relGroupGetter.getRelationshipGroup(startNode, rel.getType(), recordChanges.getRelGroupRecords()).group();
        assert groupChange != null : "Relationship group " + rel.getType() + " should have existed here";
        RelationshipGroupRecord group = groupChange.forReadingData();
        DirectionWrapper dir = DirectionIdentifier.wrapDirection(rel, startNode);
        if (rel.isFirstInFirstChain()) {
            group = groupChange.forChangingData();
            dir.setNextRel(group, rel.getFirstNextRel());
            if (groupIsEmpty(group)) {
                deleteGroup(startNodeChange, group, recordChanges.getRelGroupRecords());
            }
        }
        decrementTotalRelationshipCount(startNode.getId(), rel, dir.getNextRel(group), recordChanges.getRelRecords(), locks);
    }
    if (!endNode.isDense()) {
        if (rel.isFirstInSecondChain()) {
            endNode = endNodeChange.forChangingLinkage();
            endNode.setNextRel(rel.getSecondNextRel());
        }
        if (!loop) {
            decrementTotalRelationshipCount(endNode.getId(), rel, endNode.getNextRel(), recordChanges.getRelRecords(), locks);
        }
    } else {
        RecordProxy<Long, RelationshipGroupRecord, Integer> groupChange = relGroupGetter.getRelationshipGroup(endNode, rel.getType(), recordChanges.getRelGroupRecords()).group();
        DirectionWrapper dir = DirectionIdentifier.wrapDirection(rel, endNode);
        assert groupChange != null || loop : "Group has been deleted";
        if (groupChange != null) {
            RelationshipGroupRecord group = groupChange.forReadingData();
            if (rel.isFirstInSecondChain()) {
                group = groupChange.forChangingData();
                dir.setNextRel(group, rel.getSecondNextRel());
                if (groupIsEmpty(group)) {
                    deleteGroup(endNodeChange, group, recordChanges.getRelGroupRecords());
                }
            }
        }
        // Else this is a loop-rel and the group was deleted when dealing with the start node
        if (!loop) {
            decrementTotalRelationshipCount(endNode.getId(), rel, dir.getNextRel(groupChange.forChangingData()), recordChanges.getRelRecords(), locks);
        }
    }
}
Also used : NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) DirectionWrapper(org.neo4j.kernel.impl.util.DirectionWrapper) RelationshipGroupRecord(org.neo4j.kernel.impl.store.record.RelationshipGroupRecord)

Aggregations

RelationshipGroupRecord (org.neo4j.kernel.impl.store.record.RelationshipGroupRecord)2 DirectionWrapper (org.neo4j.kernel.impl.util.DirectionWrapper)2 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)1