Search in sources :

Example 6 with RelationshipRecord

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

the class BatchInserterImpl method setRelationshipProperties.

public void setRelationshipProperties(long rel, Map<String, Object> properties) {
    RelationshipRecord record = getRelationshipRecord(rel);
    if (record.getNextProp() != Record.NO_NEXT_PROPERTY.intValue()) {
        deletePropertyChain(record.getNextProp());
        /*
             * See setNodeProperties above for an explanation of what goes on
             * here
             */
        record.setNextProp(Record.NO_NEXT_PROPERTY.intValue());
        getRelationshipStore().updateRecord(record);
    }
    record.setNextProp(createPropertyChain(properties));
    getRelationshipStore().updateRecord(record);
}
Also used : RelationshipRecord(org.neo4j.kernel.impl.nioneo.store.RelationshipRecord)

Example 7 with RelationshipRecord

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

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

the class NodeManager method receiveRelationships.

private void receiveRelationships(Iterable<RelationshipRecord> rels, ArrayMap<String, RelIdArray> newRelationshipMap, Map<Long, RelationshipImpl> relsMap, DirectionWrapper dir, boolean hasLoops) {
    for (RelationshipRecord rel : rels) {
        long relId = rel.getId();
        RelationshipImpl relImpl = relCache.get(relId);
        RelationshipType type = null;
        if (relImpl == null) {
            type = getRelationshipTypeById(rel.getType());
            assert type != null;
            relImpl = newRelationshipImpl(relId, rel.getFirstNode(), rel.getSecondNode(), type, rel.getType(), false);
            relsMap.put(relId, relImpl);
        // relCache.put( relId, relImpl );
        } else {
            type = relImpl.getType(this);
        }
        RelIdArray relationshipSet = newRelationshipMap.get(type.name());
        if (relationshipSet == null) {
            relationshipSet = hasLoops ? new RelIdArrayWithLoops(type.name()) : new RelIdArray(type.name());
            newRelationshipMap.put(type.name(), relationshipSet);
        }
        relationshipSet.add(relId, dir);
    }
}
Also used : RelIdArrayWithLoops(org.neo4j.kernel.impl.util.RelIdArrayWithLoops) RelationshipType(org.neo4j.graphdb.RelationshipType) RelationshipRecord(org.neo4j.kernel.impl.nioneo.store.RelationshipRecord) RelIdArray(org.neo4j.kernel.impl.util.RelIdArray)

Example 9 with RelationshipRecord

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

the class DumpLogicalLog method readRelationshipCommand.

static XaCommand readRelationshipCommand(ReadableByteChannel byteChannel, ByteBuffer buffer) throws IOException {
    buffer.clear();
    buffer.limit(9);
    if (byteChannel.read(buffer) != buffer.limit()) {
        return null;
    }
    buffer.flip();
    long id = buffer.getLong();
    byte inUseFlag = buffer.get();
    boolean inUse = false;
    if ((inUseFlag & Record.IN_USE.byteValue()) == Record.IN_USE.byteValue()) {
        inUse = true;
    } else if ((inUseFlag & Record.IN_USE.byteValue()) != Record.NOT_IN_USE.byteValue()) {
        throw new IOException("Illegal in use flag: " + inUseFlag);
    }
    RelationshipRecord record;
    if (inUse) {
        buffer.clear();
        buffer.limit(52);
        if (byteChannel.read(buffer) != buffer.limit()) {
            return null;
        }
        buffer.flip();
        record = new RelationshipRecord(id, buffer.getInt(), buffer.getInt(), buffer.getInt());
        record.setInUse(inUse);
        record.setFirstPrevRel(buffer.getLong());
        record.setFirstNextRel(buffer.getLong());
        record.setSecondPrevRel(buffer.getLong());
        record.setSecondNextRel(buffer.getLong());
        record.setNextProp(buffer.getLong());
    } else {
        record = new RelationshipRecord(id, -1, -1, -1);
        record.setInUse(false);
    }
    return new Command(record);
}
Also used : XaCommand(org.neo4j.kernel.impl.transaction.xaframework.XaCommand) RelationshipRecord(org.neo4j.kernel.impl.nioneo.store.RelationshipRecord) IOException(java.io.IOException)

Example 10 with RelationshipRecord

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

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