Search in sources :

Example 1 with InvalidRecordException

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

the class BatchInserterImpl method getRelationships.

public Iterable<SimpleRelationship> getRelationships(long nodeId) {
    NodeRecord nodeRecord = getNodeRecord(nodeId);
    long nextRel = nodeRecord.getNextRel();
    List<SimpleRelationship> rels = new ArrayList<SimpleRelationship>();
    while (nextRel != Record.NO_NEXT_RELATIONSHIP.intValue()) {
        RelationshipRecord relRecord = getRelationshipRecord(nextRel);
        RelationshipType type = new RelationshipTypeImpl(typeHolder.getName(relRecord.getType()));
        rels.add(new SimpleRelationship(relRecord.getId(), relRecord.getFirstNode(), relRecord.getSecondNode(), type));
        long firstNode = relRecord.getFirstNode();
        long secondNode = relRecord.getSecondNode();
        if (firstNode == nodeId) {
            nextRel = relRecord.getFirstNextRel();
        } else if (secondNode == nodeId) {
            nextRel = relRecord.getSecondNextRel();
        } else {
            throw new InvalidRecordException("Node[" + nodeId + "] not part of firstNode[" + firstNode + "] or secondNode[" + secondNode + "]");
        }
    }
    return rels;
}
Also used : NodeRecord(org.neo4j.kernel.impl.nioneo.store.NodeRecord) ArrayList(java.util.ArrayList) RelationshipType(org.neo4j.graphdb.RelationshipType) RelationshipRecord(org.neo4j.kernel.impl.nioneo.store.RelationshipRecord) InvalidRecordException(org.neo4j.kernel.impl.nioneo.store.InvalidRecordException)

Example 2 with InvalidRecordException

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

the class BatchInserterImpl method connectRelationship.

private void connectRelationship(NodeRecord firstNode, NodeRecord secondNode, RelationshipRecord rel) {
    rel.setFirstNextRel(firstNode.getNextRel());
    rel.setSecondNextRel(secondNode.getNextRel());
    if (firstNode.getNextRel() != Record.NO_NEXT_RELATIONSHIP.intValue()) {
        RelationshipRecord nextRel = getRelationshipStore().getRecord(firstNode.getNextRel());
        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);
        }
        getRelationshipStore().updateRecord(nextRel);
    }
    if (secondNode.getNextRel() != Record.NO_NEXT_RELATIONSHIP.intValue()) {
        RelationshipRecord nextRel = getRelationshipStore().getRecord(secondNode.getNextRel());
        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);
        }
        getRelationshipStore().updateRecord(nextRel);
    }
    firstNode.setNextRel(rel.getId());
    secondNode.setNextRel(rel.getId());
}
Also used : RelationshipRecord(org.neo4j.kernel.impl.nioneo.store.RelationshipRecord) InvalidRecordException(org.neo4j.kernel.impl.nioneo.store.InvalidRecordException)

Example 3 with InvalidRecordException

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

the class BatchInserterImpl method getRelationshipIds.

public Iterable<Long> getRelationshipIds(long nodeId) {
    NodeRecord nodeRecord = getNodeRecord(nodeId);
    long nextRel = nodeRecord.getNextRel();
    List<Long> ids = new ArrayList<Long>();
    while (nextRel != Record.NO_NEXT_RELATIONSHIP.intValue()) {
        RelationshipRecord relRecord = getRelationshipRecord(nextRel);
        ids.add(relRecord.getId());
        long firstNode = relRecord.getFirstNode();
        long secondNode = relRecord.getSecondNode();
        if (firstNode == nodeId) {
            nextRel = relRecord.getFirstNextRel();
        } else if (secondNode == nodeId) {
            nextRel = relRecord.getSecondNextRel();
        } else {
            throw new InvalidRecordException("Node[" + nodeId + "] not part of firstNode[" + firstNode + "] or secondNode[" + secondNode + "]");
        }
    }
    return ids;
}
Also used : NodeRecord(org.neo4j.kernel.impl.nioneo.store.NodeRecord) ArrayList(java.util.ArrayList) RelationshipRecord(org.neo4j.kernel.impl.nioneo.store.RelationshipRecord) InvalidRecordException(org.neo4j.kernel.impl.nioneo.store.InvalidRecordException)

Example 4 with InvalidRecordException

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

the class BatchInserterImpl method getRelationships.

public Iterable<SimpleRelationship> getRelationships(long nodeId) {
    NodeRecord nodeRecord = getNodeRecord(nodeId);
    long nextRel = nodeRecord.getNextRel();
    List<SimpleRelationship> rels = new ArrayList<SimpleRelationship>();
    while (nextRel != Record.NO_NEXT_RELATIONSHIP.intValue()) {
        RelationshipRecord relRecord = getRelationshipRecord(nextRel);
        RelationshipType type = new RelationshipTypeImpl(typeHolder.getName(relRecord.getType()));
        rels.add(new SimpleRelationship(relRecord.getId(), relRecord.getFirstNode(), relRecord.getSecondNode(), type));
        long firstNode = relRecord.getFirstNode();
        long secondNode = relRecord.getSecondNode();
        if (firstNode == nodeId) {
            nextRel = relRecord.getFirstNextRel();
        } else if (secondNode == nodeId) {
            nextRel = relRecord.getSecondNextRel();
        } else {
            throw new InvalidRecordException("Node[" + nodeId + "] not part of firstNode[" + firstNode + "] or secondNode[" + secondNode + "]");
        }
    }
    return rels;
}
Also used : NodeRecord(org.neo4j.kernel.impl.nioneo.store.NodeRecord) ArrayList(java.util.ArrayList) RelationshipType(org.neo4j.graphdb.RelationshipType) RelationshipRecord(org.neo4j.kernel.impl.nioneo.store.RelationshipRecord) InvalidRecordException(org.neo4j.kernel.impl.nioneo.store.InvalidRecordException)

Example 5 with InvalidRecordException

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

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