Search in sources :

Example 21 with RelationshipRecord

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

the class WriteTransaction method connect.

private void connect(NodeRecord node, RelationshipRecord rel) {
    if (node.getNextRel() != Record.NO_NEXT_RELATIONSHIP.intValue()) {
        Relationship lockableRel = new LockableRelationship(node.getNextRel());
        getWriteLock(lockableRel);
        RelationshipRecord nextRel = getRelationshipRecord(node.getNextRel());
        if (nextRel == null) {
            nextRel = getRelationshipStore().getRecord(node.getNextRel());
            addRelationshipRecord(nextRel);
        }
        boolean changed = false;
        if (nextRel.getFirstNode() == node.getId()) {
            nextRel.setFirstPrevRel(rel.getId());
            changed = true;
        }
        if (nextRel.getSecondNode() == node.getId()) {
            nextRel.setSecondPrevRel(rel.getId());
            changed = true;
        }
        if (!changed) {
            throw new InvalidRecordException(node + " dont match " + nextRel);
        }
    }
}
Also used : Relationship(org.neo4j.graphdb.Relationship) RelationshipRecord(org.neo4j.kernel.impl.nioneo.store.RelationshipRecord) InvalidRecordException(org.neo4j.kernel.impl.nioneo.store.InvalidRecordException)

Example 22 with RelationshipRecord

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

the class WriteTransaction method doPrepare.

@Override
protected void doPrepare() throws XAException {
    if (committed) {
        throw new XAException("Cannot prepare committed transaction[" + getIdentifier() + "]");
    }
    if (prepared) {
        throw new XAException("Cannot prepare prepared transaction[" + getIdentifier() + "]");
    }
    // generate records then write to logical log via addCommand method
    prepared = true;
    for (RelationshipTypeRecord record : relTypeRecords.values()) {
        Command.RelationshipTypeCommand command = new Command.RelationshipTypeCommand(neoStore.getRelationshipTypeStore(), record);
        relTypeCommands.add(command);
        addCommand(command);
    }
    for (NodeRecord record : nodeRecords.values()) {
        if (!record.inUse() && record.getNextRel() != Record.NO_NEXT_RELATIONSHIP.intValue()) {
            throw new InvalidRecordException("Node record " + record + " still has relationships");
        }
        Command.NodeCommand command = new Command.NodeCommand(neoStore.getNodeStore(), record);
        nodeCommands.add(command);
        if (!record.inUse()) {
            removeNodeFromCache(record.getId());
        }
        addCommand(command);
    }
    for (RelationshipRecord record : relRecords.values()) {
        Command.RelationshipCommand command = new Command.RelationshipCommand(neoStore.getRelationshipStore(), record);
        relCommands.add(command);
        if (!record.inUse()) {
            removeRelationshipFromCache(record.getId());
        }
        addCommand(command);
    }
    for (PropertyIndexRecord record : propIndexRecords.values()) {
        Command.PropertyIndexCommand command = new Command.PropertyIndexCommand(neoStore.getPropertyStore().getIndexStore(), record);
        propIndexCommands.add(command);
        addCommand(command);
    }
    for (PropertyRecord record : propertyRecords.values()) {
        Command.PropertyCommand command = new Command.PropertyCommand(neoStore.getPropertyStore(), record);
        propCommands.add(command);
        addCommand(command);
    }
}
Also used : XAException(javax.transaction.xa.XAException) RelationshipRecord(org.neo4j.kernel.impl.nioneo.store.RelationshipRecord) PropertyIndexRecord(org.neo4j.kernel.impl.nioneo.store.PropertyIndexRecord) RelationshipTypeRecord(org.neo4j.kernel.impl.nioneo.store.RelationshipTypeRecord) PropertyCommand(org.neo4j.kernel.impl.nioneo.xa.Command.PropertyCommand) NodeRecord(org.neo4j.kernel.impl.nioneo.store.NodeRecord) PropertyRecord(org.neo4j.kernel.impl.nioneo.store.PropertyRecord) PropertyCommand(org.neo4j.kernel.impl.nioneo.xa.Command.PropertyCommand) XaCommand(org.neo4j.kernel.impl.transaction.xaframework.XaCommand) PropertyCommand(org.neo4j.kernel.impl.nioneo.xa.Command.PropertyCommand) InvalidRecordException(org.neo4j.kernel.impl.nioneo.store.InvalidRecordException)

Example 23 with RelationshipRecord

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

the class WriteTransaction method relLoadLight.

@Override
public RelationshipRecord relLoadLight(long id) {
    RelationshipRecord relRecord = getRelationshipRecord(id);
    if (relRecord != null) {
        //            }
        return relRecord;
    }
    relRecord = getRelationshipStore().getLightRel(id);
    if (relRecord != null) {
        return relRecord;
    }
    return null;
}
Also used : RelationshipRecord(org.neo4j.kernel.impl.nioneo.store.RelationshipRecord)

Example 24 with RelationshipRecord

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

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 25 with RelationshipRecord

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

the class BatchInserterImpl method createRelationship.

public long createRelationship(long node1, long node2, RelationshipType type, Map<String, Object> properties) {
    NodeRecord firstNode = getNodeRecord(node1);
    NodeRecord secondNode = getNodeRecord(node2);
    int typeId = typeHolder.getTypeId(type.name());
    if (typeId == -1) {
        typeId = createNewRelationshipType(type.name());
    }
    long id = getRelationshipStore().nextId();
    RelationshipRecord record = new RelationshipRecord(id, node1, node2, typeId);
    record.setInUse(true);
    record.setCreated();
    connectRelationship(firstNode, secondNode, record);
    getNodeStore().updateRecord(firstNode);
    getNodeStore().updateRecord(secondNode);
    record.setNextProp(createPropertyChain(properties));
    getRelationshipStore().updateRecord(record);
    return id;
}
Also used : NodeRecord(org.neo4j.kernel.impl.nioneo.store.NodeRecord) RelationshipRecord(org.neo4j.kernel.impl.nioneo.store.RelationshipRecord)

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