Search in sources :

Example 6 with InvalidRecordException

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

the class WriteTransaction method disconnectRelationship.

private void disconnectRelationship(RelationshipRecord rel) {
    // update first node prev
    if (rel.getFirstPrevRel() != Record.NO_NEXT_RELATIONSHIP.intValue()) {
        Relationship lockableRel = new LockableRelationship(rel.getFirstPrevRel());
        getWriteLock(lockableRel);
        RelationshipRecord prevRel = getRelationshipRecord(rel.getFirstPrevRel());
        if (prevRel == null) {
            prevRel = getRelationshipStore().getRecord(rel.getFirstPrevRel());
            addRelationshipRecord(prevRel);
        }
        if (prevRel.getFirstNode() == rel.getFirstNode()) {
            prevRel.setFirstNextRel(rel.getFirstNextRel());
        } else if (prevRel.getSecondNode() == rel.getFirstNode()) {
            prevRel.setSecondNextRel(rel.getFirstNextRel());
        } else {
            throw new InvalidRecordException(prevRel + " don't match " + rel);
        }
    }
    // update first node next
    if (rel.getFirstNextRel() != Record.NO_NEXT_RELATIONSHIP.intValue()) {
        Relationship lockableRel = new LockableRelationship(rel.getFirstNextRel());
        getWriteLock(lockableRel);
        RelationshipRecord nextRel = getRelationshipRecord(rel.getFirstNextRel());
        if (nextRel == null) {
            nextRel = getRelationshipStore().getRecord(rel.getFirstNextRel());
            addRelationshipRecord(nextRel);
        }
        if (nextRel.getFirstNode() == rel.getFirstNode()) {
            nextRel.setFirstPrevRel(rel.getFirstPrevRel());
        } else if (nextRel.getSecondNode() == rel.getFirstNode()) {
            nextRel.setSecondPrevRel(rel.getFirstPrevRel());
        } else {
            throw new InvalidRecordException(nextRel + " don't match " + rel);
        }
    }
    // update second node prev
    if (rel.getSecondPrevRel() != Record.NO_NEXT_RELATIONSHIP.intValue()) {
        Relationship lockableRel = new LockableRelationship(rel.getSecondPrevRel());
        getWriteLock(lockableRel);
        RelationshipRecord prevRel = getRelationshipRecord(rel.getSecondPrevRel());
        if (prevRel == null) {
            prevRel = getRelationshipStore().getRecord(rel.getSecondPrevRel());
            addRelationshipRecord(prevRel);
        }
        if (prevRel.getFirstNode() == rel.getSecondNode()) {
            prevRel.setFirstNextRel(rel.getSecondNextRel());
        } else if (prevRel.getSecondNode() == rel.getSecondNode()) {
            prevRel.setSecondNextRel(rel.getSecondNextRel());
        } else {
            throw new InvalidRecordException(prevRel + " don't match " + rel);
        }
    }
    // update second node next
    if (rel.getSecondNextRel() != Record.NO_NEXT_RELATIONSHIP.intValue()) {
        Relationship lockableRel = new LockableRelationship(rel.getSecondNextRel());
        getWriteLock(lockableRel);
        RelationshipRecord nextRel = getRelationshipRecord(rel.getSecondNextRel());
        if (nextRel == null) {
            nextRel = getRelationshipStore().getRecord(rel.getSecondNextRel());
            addRelationshipRecord(nextRel);
        }
        if (nextRel.getFirstNode() == rel.getSecondNode()) {
            nextRel.setFirstPrevRel(rel.getSecondPrevRel());
        } else if (nextRel.getSecondNode() == rel.getSecondNode()) {
            nextRel.setSecondPrevRel(rel.getSecondPrevRel());
        } else {
            throw new InvalidRecordException(nextRel + " don't match " + rel);
        }
    }
}
Also used : Relationship(org.neo4j.graphdb.Relationship) RelationshipRecord(org.neo4j.kernel.impl.nioneo.store.RelationshipRecord) InvalidRecordException(org.neo4j.kernel.impl.nioneo.store.InvalidRecordException)

Example 7 with InvalidRecordException

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

the class WriteTransaction method connectRelationship.

private void connectRelationship(NodeRecord firstNode, NodeRecord secondNode, RelationshipRecord rel) {
    assert firstNode.getNextRel() != rel.getId();
    assert secondNode.getNextRel() != rel.getId();
    rel.setFirstNextRel(firstNode.getNextRel());
    rel.setSecondNextRel(secondNode.getNextRel());
    if (firstNode.getNextRel() != Record.NO_NEXT_RELATIONSHIP.intValue()) {
        Relationship lockableRel = new LockableRelationship(firstNode.getNextRel());
        getWriteLock(lockableRel);
        RelationshipRecord nextRel = getRelationshipRecord(firstNode.getNextRel());
        if (nextRel == null) {
            nextRel = getRelationshipStore().getRecord(firstNode.getNextRel());
            addRelationshipRecord(nextRel);
        }
        if (nextRel.getFirstNode() == firstNode.getId()) {
            nextRel.setFirstPrevRel(rel.getId());
        } else if (nextRel.getSecondNode() == firstNode.getId()) {
            nextRel.setSecondPrevRel(rel.getId());
        } else {
            throw new InvalidRecordException(firstNode + " dont match " + nextRel);
        }
    }
    if (secondNode.getNextRel() != Record.NO_NEXT_RELATIONSHIP.intValue()) {
        Relationship lockableRel = new LockableRelationship(secondNode.getNextRel());
        getWriteLock(lockableRel);
        RelationshipRecord nextRel = getRelationshipRecord(secondNode.getNextRel());
        if (nextRel == null) {
            nextRel = getRelationshipStore().getRecord(secondNode.getNextRel());
            addRelationshipRecord(nextRel);
        }
        if (nextRel.getFirstNode() == secondNode.getId()) {
            nextRel.setFirstPrevRel(rel.getId());
        } else if (nextRel.getSecondNode() == secondNode.getId()) {
            nextRel.setSecondPrevRel(rel.getId());
        } else {
            throw new InvalidRecordException(secondNode + " dont match " + nextRel);
        }
    }
    firstNode.setNextRel(rel.getId());
    secondNode.setNextRel(rel.getId());
}
Also used : Relationship(org.neo4j.graphdb.Relationship) RelationshipRecord(org.neo4j.kernel.impl.nioneo.store.RelationshipRecord) InvalidRecordException(org.neo4j.kernel.impl.nioneo.store.InvalidRecordException)

Example 8 with InvalidRecordException

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

the class WriteTransaction method nodeGetProperties.

ArrayMap<Integer, PropertyData> nodeGetProperties(long nodeId, boolean light) {
    ArrayMap<Integer, PropertyData> propertyMap = new ArrayMap<Integer, PropertyData>(9, false, true);
    NodeRecord nodeRecord = getNodeRecord(nodeId);
    if (nodeRecord != null && nodeRecord.isCreated()) {
        return propertyMap;
    }
    if (nodeRecord != null) {
        if (!nodeRecord.inUse() && !light) {
            throw new IllegalStateException("Node[" + nodeId + "] has been deleted in this tx");
        }
    }
    nodeRecord = getNodeStore().getRecord(nodeId);
    if (!nodeRecord.inUse()) {
        throw new InvalidRecordException("Node[" + nodeId + "] not in use");
    }
    long nextProp = nodeRecord.getNextProp();
    while (nextProp != Record.NO_NEXT_PROPERTY.intValue()) {
        PropertyRecord propRecord = getPropertyStore().getLightRecord(nextProp);
        propertyMap.put(propRecord.getKeyIndexId(), new PropertyData(propRecord.getId(), propertyGetValueOrNull(propRecord)));
        nextProp = propRecord.getNextProp();
    }
    return propertyMap;
}
Also used : NodeRecord(org.neo4j.kernel.impl.nioneo.store.NodeRecord) PropertyData(org.neo4j.kernel.impl.nioneo.store.PropertyData) PropertyRecord(org.neo4j.kernel.impl.nioneo.store.PropertyRecord) ArrayMap(org.neo4j.kernel.impl.util.ArrayMap) InvalidRecordException(org.neo4j.kernel.impl.nioneo.store.InvalidRecordException)

Example 9 with InvalidRecordException

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

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

InvalidRecordException (org.neo4j.kernel.impl.nioneo.store.InvalidRecordException)29 RelationshipRecord (org.neo4j.kernel.impl.nioneo.store.RelationshipRecord)20 NodeRecord (org.neo4j.kernel.impl.nioneo.store.NodeRecord)10 ArrayList (java.util.ArrayList)7 PropertyRecord (org.neo4j.kernel.impl.nioneo.store.PropertyRecord)7 XAException (javax.transaction.xa.XAException)4 NotFoundException (org.neo4j.graphdb.NotFoundException)4 Relationship (org.neo4j.graphdb.Relationship)4 PropertyIndexRecord (org.neo4j.kernel.impl.nioneo.store.PropertyIndexRecord)4 RelationshipTypeRecord (org.neo4j.kernel.impl.nioneo.store.RelationshipTypeRecord)4 ByteBuffer (java.nio.ByteBuffer)3 PropertyData (org.neo4j.kernel.impl.nioneo.store.PropertyData)3 ArrayMap (org.neo4j.kernel.impl.util.ArrayMap)3 RelationshipType (org.neo4j.graphdb.RelationshipType)2 DynamicRecord (org.neo4j.kernel.impl.nioneo.store.DynamicRecord)2 RelationshipData (org.neo4j.kernel.impl.nioneo.store.RelationshipData)2 PropertyCommand (org.neo4j.kernel.impl.nioneo.xa.Command.PropertyCommand)2 XaCommand (org.neo4j.kernel.impl.transaction.xaframework.XaCommand)2 EnumMap (java.util.EnumMap)1 HashMap (java.util.HashMap)1