Search in sources :

Example 1 with RelationshipData

use of org.neo4j.kernel.impl.nioneo.store.RelationshipData in project graphdb by neo4j-attic.

the class ReadTransaction method getMoreRelationships.

public Iterable<RelationshipData> getMoreRelationships(long nodeId, RelationshipChainPosition position) {
    long nextRel = position.getNextRecord();
    List<RelationshipData> rels = new ArrayList<RelationshipData>();
    for (int i = 0; i < getRelGrabSize() && nextRel != Record.NO_NEXT_RELATIONSHIP.intValue(); i++) {
        RelationshipRecord relRecord = getRelationshipStore().getChainRecord(nextRel);
        if (relRecord == null) {
            // return what we got so far
            position.setNextRecord(Record.NO_NEXT_RELATIONSHIP.intValue());
            return rels;
        }
        long firstNode = relRecord.getFirstNode();
        long secondNode = relRecord.getSecondNode();
        if (relRecord.inUse()) {
            rels.add(new RelationshipData(relRecord.getId(), firstNode, secondNode, relRecord.getType()));
        } else {
            i--;
        }
        if (firstNode == nodeId) {
            nextRel = relRecord.getFirstNextRel();
        } else if (secondNode == nodeId) {
            nextRel = relRecord.getSecondNextRel();
        } else {
            System.out.println(relRecord);
            throw new InvalidRecordException("Node[" + nodeId + "] is neither firstNode[" + firstNode + "] nor secondNode[" + secondNode + "] for Relationship[" + relRecord.getId() + "]");
        }
    }
    position.setNextRecord(nextRel);
    return rels;
}
Also used : RelationshipData(org.neo4j.kernel.impl.nioneo.store.RelationshipData) ArrayList(java.util.ArrayList) RelationshipRecord(org.neo4j.kernel.impl.nioneo.store.RelationshipRecord) InvalidRecordException(org.neo4j.kernel.impl.nioneo.store.InvalidRecordException)

Example 2 with RelationshipData

use of org.neo4j.kernel.impl.nioneo.store.RelationshipData in project graphdb by neo4j-attic.

the class WriteTransaction method relationshipLoad.

public RelationshipData relationshipLoad(long id) {
    RelationshipRecord relRecord = getRelationshipRecord(id);
    if (relRecord != null) {
        //            }
        return new RelationshipData(id, relRecord.getFirstNode(), relRecord.getSecondNode(), relRecord.getType());
    }
    relRecord = getRelationshipStore().getLightRel(id);
    if (relRecord != null) {
        return new RelationshipData(id, relRecord.getFirstNode(), relRecord.getSecondNode(), relRecord.getType());
    }
    return null;
}
Also used : RelationshipData(org.neo4j.kernel.impl.nioneo.store.RelationshipData) RelationshipRecord(org.neo4j.kernel.impl.nioneo.store.RelationshipRecord)

Example 3 with RelationshipData

use of org.neo4j.kernel.impl.nioneo.store.RelationshipData in project graphdb by neo4j-attic.

the class NodeManager method getRelForProxy.

RelationshipImpl getRelForProxy(long relId) {
    RelationshipImpl relationship = relCache.get(relId);
    if (relationship != null) {
        return relationship;
    }
    ReentrantLock loadLock = lockId(relId);
    try {
        relationship = relCache.get(relId);
        if (relationship != null) {
            return relationship;
        }
        RelationshipData data = persistenceManager.loadLightRelationship(relId);
        if (data == null) {
            throw new NotFoundException("Relationship[" + relId + "] not found.");
        }
        int typeId = data.relationshipType();
        RelationshipType type = getRelationshipTypeById(typeId);
        if (type == null) {
            throw new NotFoundException("Relationship[" + data.getId() + "] exist but relationship type[" + typeId + "] not found.");
        }
        relationship = new RelationshipImpl(relId, data.firstNode(), data.secondNode(), type, false);
        relCache.put(relId, relationship);
        return relationship;
    } finally {
        loadLock.unlock();
    }
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) RelationshipData(org.neo4j.kernel.impl.nioneo.store.RelationshipData) RelationshipType(org.neo4j.graphdb.RelationshipType) NotFoundException(org.neo4j.graphdb.NotFoundException)

Example 4 with RelationshipData

use of org.neo4j.kernel.impl.nioneo.store.RelationshipData in project graphdb by neo4j-attic.

the class WriteTransaction method getMoreRelationships.

public Iterable<RelationshipData> getMoreRelationships(long nodeId, RelationshipChainPosition position) {
    long nextRel = position.getNextRecord();
    List<RelationshipData> rels = new ArrayList<RelationshipData>();
    for (int i = 0; i < getRelGrabSize() && nextRel != Record.NO_NEXT_RELATIONSHIP.intValue(); i++) {
        RelationshipRecord relRecord = getRelationshipStore().getChainRecord(nextRel);
        if (relRecord == null) {
            // return what we got so far
            position.setNextRecord(Record.NO_NEXT_RELATIONSHIP.intValue());
            return rels;
        }
        long firstNode = relRecord.getFirstNode();
        long secondNode = relRecord.getSecondNode();
        if (// && !relRecord.isCreated() )
        relRecord.inUse()) {
            rels.add(new RelationshipData(relRecord.getId(), firstNode, secondNode, relRecord.getType()));
        } else {
            i--;
        }
        if (firstNode == nodeId) {
            nextRel = relRecord.getFirstNextRel();
        } else if (secondNode == nodeId) {
            nextRel = relRecord.getSecondNextRel();
        } else {
            throw new InvalidRecordException("Node[" + nodeId + "] is neither firstNode[" + firstNode + "] nor secondNode[" + secondNode + "] for Relationship[" + relRecord.getId() + "]");
        }
    }
    position.setNextRecord(nextRel);
    return rels;
}
Also used : RelationshipData(org.neo4j.kernel.impl.nioneo.store.RelationshipData) ArrayList(java.util.ArrayList) RelationshipRecord(org.neo4j.kernel.impl.nioneo.store.RelationshipRecord) InvalidRecordException(org.neo4j.kernel.impl.nioneo.store.InvalidRecordException)

Example 5 with RelationshipData

use of org.neo4j.kernel.impl.nioneo.store.RelationshipData in project graphdb by neo4j-attic.

the class NodeManager method getMoreRelationships.

Pair<ArrayMap<String, RelIdArray>, Map<Long, RelationshipImpl>> getMoreRelationships(NodeImpl node) {
    long nodeId = node.getId();
    RelationshipChainPosition position = node.getRelChainPosition();
    Iterable<RelationshipData> rels = persistenceManager.getMoreRelationships(nodeId, position);
    ArrayMap<String, RelIdArray> newRelationshipMap = new ArrayMap<String, RelIdArray>();
    Map<Long, RelationshipImpl> relsMap = new HashMap<Long, RelationshipImpl>(150);
    for (RelationshipData rel : rels) {
        long relId = rel.getId();
        RelationshipImpl relImpl = relCache.get(relId);
        RelationshipType type = null;
        if (relImpl == null) {
            type = getRelationshipTypeById(rel.relationshipType());
            assert type != null;
            relImpl = new RelationshipImpl(relId, rel.firstNode(), rel.secondNode(), type, false);
            relsMap.put(relId, relImpl);
        // relCache.put( relId, relImpl );
        } else {
            type = relImpl.getType();
        }
        RelIdArray relationshipSet = newRelationshipMap.get(type.name());
        if (relationshipSet == null) {
            relationshipSet = new RelIdArray();
            newRelationshipMap.put(type.name(), relationshipSet);
        }
        relationshipSet.add(relId);
    }
    // relCache.putAll( relsMap );
    return Pair.of(newRelationshipMap, relsMap);
}
Also used : RelationshipChainPosition(org.neo4j.kernel.impl.nioneo.store.RelationshipChainPosition) HashMap(java.util.HashMap) RelationshipType(org.neo4j.graphdb.RelationshipType) ArrayMap(org.neo4j.kernel.impl.util.ArrayMap) RelationshipData(org.neo4j.kernel.impl.nioneo.store.RelationshipData) RelIdArray(org.neo4j.kernel.impl.util.RelIdArray)

Aggregations

RelationshipData (org.neo4j.kernel.impl.nioneo.store.RelationshipData)6 RelationshipType (org.neo4j.graphdb.RelationshipType)3 RelationshipRecord (org.neo4j.kernel.impl.nioneo.store.RelationshipRecord)3 ArrayList (java.util.ArrayList)2 ReentrantLock (java.util.concurrent.locks.ReentrantLock)2 NotFoundException (org.neo4j.graphdb.NotFoundException)2 InvalidRecordException (org.neo4j.kernel.impl.nioneo.store.InvalidRecordException)2 HashMap (java.util.HashMap)1 RelationshipChainPosition (org.neo4j.kernel.impl.nioneo.store.RelationshipChainPosition)1 ArrayMap (org.neo4j.kernel.impl.util.ArrayMap)1 RelIdArray (org.neo4j.kernel.impl.util.RelIdArray)1