Search in sources :

Example 16 with RelationshipRecord

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

the class WriteTransaction method relDelete.

ArrayMap<Integer, PropertyData> relDelete(long id) {
    RelationshipRecord record = getRelationshipRecord(id);
    if (record == null) {
        record = getRelationshipStore().getRecord(id);
        addRelationshipRecord(record);
    }
    if (!record.inUse()) {
        throw new IllegalStateException("Unable to delete relationship[" + id + "] since it is already deleted.");
    }
    ArrayMap<Integer, PropertyData> propertyMap = new ArrayMap<Integer, PropertyData>(9, false, true);
    long nextProp = record.getNextProp();
    while (nextProp != Record.NO_NEXT_PROPERTY.intValue()) {
        PropertyRecord propRecord = getPropertyRecord(nextProp);
        if (propRecord == null) {
            propRecord = getPropertyStore().getRecord(nextProp);
            addPropertyRecord(propRecord);
        }
        if (propRecord.isLight()) {
            getPropertyStore().makeHeavy(propRecord);
        }
        if (!propRecord.isCreated()) {
            if (!propRecord.isChanged()) {
                propertyMap.put(propRecord.getKeyIndexId(), new PropertyData(propRecord.getId(), propertyGetValueOrNull(propRecord)));
            } else {
                // we have to re-read committed value since property has 
                // changed and old value is erased in memory
                PropertyRecord diskValue = getPropertyStore().getRecord(propRecord.getId());
                getPropertyStore().makeHeavy(diskValue);
                propertyMap.put(diskValue.getKeyIndexId(), new PropertyData(diskValue.getId(), propertyGetValueOrNull(diskValue)));
            }
        }
        nextProp = propRecord.getNextProp();
        propRecord.setInUse(false);
        // TODO: update count on property index record
        for (DynamicRecord valueRecord : propRecord.getValueRecords()) {
            valueRecord.setInUse(false);
        }
    }
    disconnectRelationship(record);
    updateNodes(record);
    record.setInUse(false);
    return propertyMap;
}
Also used : DynamicRecord(org.neo4j.kernel.impl.nioneo.store.DynamicRecord) PropertyData(org.neo4j.kernel.impl.nioneo.store.PropertyData) PropertyRecord(org.neo4j.kernel.impl.nioneo.store.PropertyRecord) RelationshipRecord(org.neo4j.kernel.impl.nioneo.store.RelationshipRecord) ArrayMap(org.neo4j.kernel.impl.util.ArrayMap)

Example 17 with RelationshipRecord

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

the class WriteTransaction method relationshipCreate.

void relationshipCreate(long id, long firstNodeId, long secondNodeId, int type) {
    NodeRecord firstNode = getNodeRecord(firstNodeId);
    if (firstNode == null) {
        firstNode = getNodeStore().getRecord(firstNodeId);
        addNodeRecord(firstNode);
    }
    if (!firstNode.inUse()) {
        throw new IllegalStateException("First node[" + firstNodeId + "] is deleted and cannot be used to create a relationship");
    }
    NodeRecord secondNode = getNodeRecord(secondNodeId);
    if (secondNode == null) {
        secondNode = getNodeStore().getRecord(secondNodeId);
        addNodeRecord(secondNode);
    }
    if (!secondNode.inUse()) {
        throw new IllegalStateException("Second node[" + secondNodeId + "] is deleted and cannot be used to create a relationship");
    }
    RelationshipRecord record = new RelationshipRecord(id, firstNodeId, secondNodeId, type);
    record.setInUse(true);
    record.setCreated();
    addRelationshipRecord(record);
    connectRelationship(firstNode, secondNode, record);
}
Also used : NodeRecord(org.neo4j.kernel.impl.nioneo.store.NodeRecord) RelationshipRecord(org.neo4j.kernel.impl.nioneo.store.RelationshipRecord)

Example 18 with RelationshipRecord

use of org.neo4j.kernel.impl.nioneo.store.RelationshipRecord 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 19 with RelationshipRecord

use of org.neo4j.kernel.impl.nioneo.store.RelationshipRecord in project neo4j-mobile-android by neo4j-contrib.

the class ReadTransaction method getMoreRelationships.

static Pair<Map<DirectionWrapper, Iterable<RelationshipRecord>>, Long> getMoreRelationships(long nodeId, long position, int grabSize, RelationshipStore relStore) {
    // initialCapacity=grabSize saves the lists the trouble of resizing
    List<RelationshipRecord> out = new ArrayList<RelationshipRecord>();
    List<RelationshipRecord> in = new ArrayList<RelationshipRecord>();
    List<RelationshipRecord> loop = null;
    Map<DirectionWrapper, Iterable<RelationshipRecord>> result = new EnumMap<DirectionWrapper, Iterable<RelationshipRecord>>(DirectionWrapper.class);
    result.put(DirectionWrapper.OUTGOING, out);
    result.put(DirectionWrapper.INCOMING, in);
    for (int i = 0; i < grabSize && position != Record.NO_NEXT_RELATIONSHIP.intValue(); i++) {
        RelationshipRecord relRecord = relStore.getChainRecord(position);
        if (relRecord == null) {
            // return what we got so far
            return Pair.of(result, position);
        }
        long firstNode = relRecord.getFirstNode();
        long secondNode = relRecord.getSecondNode();
        if (relRecord.inUse()) {
            if (firstNode == secondNode) {
                if (loop == null) {
                    // This is done lazily because loops are probably quite
                    // rarely encountered
                    loop = new ArrayList<RelationshipRecord>();
                    result.put(DirectionWrapper.BOTH, loop);
                }
                loop.add(relRecord);
            } else if (firstNode == nodeId) {
                out.add(relRecord);
            } else if (secondNode == nodeId) {
                in.add(relRecord);
            }
        } else {
            i--;
        }
        if (firstNode == nodeId) {
            position = relRecord.getFirstNextRel();
        } else if (secondNode == nodeId) {
            position = relRecord.getSecondNextRel();
        } else {
            throw new InvalidRecordException("Node[" + nodeId + "] is neither firstNode[" + firstNode + "] nor secondNode[" + secondNode + "] for Relationship[" + relRecord.getId() + "]");
        }
    }
    return Pair.of(result, position);
}
Also used : DirectionWrapper(org.neo4j.kernel.impl.util.RelIdArray.DirectionWrapper) ArrayList(java.util.ArrayList) RelationshipRecord(org.neo4j.kernel.impl.nioneo.store.RelationshipRecord) EnumMap(java.util.EnumMap) InvalidRecordException(org.neo4j.kernel.impl.nioneo.store.InvalidRecordException)

Example 20 with RelationshipRecord

use of org.neo4j.kernel.impl.nioneo.store.RelationshipRecord in project neo4j-mobile-android by neo4j-contrib.

the class WriteTransaction method relLoadProperties.

@Override
public ArrayMap<Integer, PropertyData> relLoadProperties(long relId, boolean light) {
    RelationshipRecord relRecord = getRelationshipRecord(relId);
    if (relRecord != null && relRecord.isCreated()) {
        return null;
    }
    if (relRecord != null) {
        if (!relRecord.inUse() && !light) {
            throw new IllegalStateException("Relationship[" + relId + "] has been deleted in this tx");
        }
    }
    relRecord = getRelationshipStore().getRecord(relId);
    if (!relRecord.inUse()) {
        throw new InvalidRecordException("Relationship[" + relId + "] not in use");
    }
    return ReadTransaction.loadProperties(getPropertyStore(), relRecord.getNextProp());
}
Also used : RelationshipRecord(org.neo4j.kernel.impl.nioneo.store.RelationshipRecord) InvalidRecordException(org.neo4j.kernel.impl.nioneo.store.InvalidRecordException)

Aggregations

RelationshipRecord (org.neo4j.kernel.impl.nioneo.store.RelationshipRecord)42 InvalidRecordException (org.neo4j.kernel.impl.nioneo.store.InvalidRecordException)20 NodeRecord (org.neo4j.kernel.impl.nioneo.store.NodeRecord)12 PropertyRecord (org.neo4j.kernel.impl.nioneo.store.PropertyRecord)12 ArrayList (java.util.ArrayList)7 RelationshipType (org.neo4j.graphdb.RelationshipType)7 DynamicRecord (org.neo4j.kernel.impl.nioneo.store.DynamicRecord)6 XAException (javax.transaction.xa.XAException)4 Relationship (org.neo4j.graphdb.Relationship)4 PropertyData (org.neo4j.kernel.impl.nioneo.store.PropertyData)4 PropertyIndexRecord (org.neo4j.kernel.impl.nioneo.store.PropertyIndexRecord)4 RelationshipTypeRecord (org.neo4j.kernel.impl.nioneo.store.RelationshipTypeRecord)4 PropertyBlock (org.neo4j.kernel.impl.nioneo.store.PropertyBlock)3 RelationshipData (org.neo4j.kernel.impl.nioneo.store.RelationshipData)3 XaCommand (org.neo4j.kernel.impl.transaction.xaframework.XaCommand)3 ArrayMap (org.neo4j.kernel.impl.util.ArrayMap)3 IOException (java.io.IOException)2 ReentrantLock (java.util.concurrent.locks.ReentrantLock)2 NotFoundException (org.neo4j.graphdb.NotFoundException)2 PropertyCommand (org.neo4j.kernel.impl.nioneo.xa.Command.PropertyCommand)2