Search in sources :

Example 31 with NodeRecord

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

the class WriteTransaction method relationshipCreate.

@Override
public void relationshipCreate(long id, int type, long firstNodeId, long secondNodeId) {
    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 32 with NodeRecord

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

the class WriteTransaction method nodeCreate.

@Override
public void nodeCreate(long nodeId) {
    NodeRecord nodeRecord = new NodeRecord(nodeId);
    nodeRecord.setInUse(true);
    nodeRecord.setCreated();
    addNodeRecord(nodeRecord);
}
Also used : NodeRecord(org.neo4j.kernel.impl.nioneo.store.NodeRecord)

Example 33 with NodeRecord

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

the class WriteTransaction method nodeLoadProperties.

@Override
public ArrayMap<Integer, PropertyData> nodeLoadProperties(long nodeId, boolean light) {
    NodeRecord nodeRecord = getNodeRecord(nodeId);
    if (nodeRecord != null && nodeRecord.isCreated()) {
        return null;
    }
    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");
    }
    return ReadTransaction.loadProperties(getPropertyStore(), nodeRecord.getNextProp());
}
Also used : NodeRecord(org.neo4j.kernel.impl.nioneo.store.NodeRecord) InvalidRecordException(org.neo4j.kernel.impl.nioneo.store.InvalidRecordException)

Example 34 with NodeRecord

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

the class WriteTransaction method doRollback.

@Override
public void doRollback() throws XAException {
    if (committed) {
        throw new XAException("Cannot rollback partialy commited " + "transaction[" + getIdentifier() + "]. Recover and " + "commit");
    }
    try {
        for (RelationshipTypeRecord record : relTypeRecords.values()) {
            if (record.isCreated()) {
                getRelationshipTypeStore().freeId(record.getId());
                for (DynamicRecord dynamicRecord : record.getTypeRecords()) {
                    if (dynamicRecord.isCreated()) {
                        getRelationshipTypeStore().freeBlockId((int) dynamicRecord.getId());
                    }
                }
            }
            removeRelationshipTypeFromCache(record.getId());
        }
        for (NodeRecord record : nodeRecords.values()) {
            if (record.isCreated()) {
                getNodeStore().freeId(record.getId());
            }
            removeNodeFromCache(record.getId());
        }
        for (RelationshipRecord record : relRecords.values()) {
            if (record.isCreated()) {
                getRelationshipStore().freeId(record.getId());
            }
            removeRelationshipFromCache(record.getId());
        }
        for (PropertyIndexRecord record : propIndexRecords.values()) {
            if (record.isCreated()) {
                getPropertyStore().getIndexStore().freeId(record.getId());
                for (DynamicRecord dynamicRecord : record.getKeyRecords()) {
                    if (dynamicRecord.isCreated()) {
                        getPropertyStore().getIndexStore().freeBlockId((int) dynamicRecord.getId());
                    }
                }
            }
        }
        for (PropertyRecord record : propertyRecords.values()) {
            if (record.getNodeId() != -1) {
                removeNodeFromCache(record.getNodeId());
            } else if (record.getRelId() != -1) {
                removeRelationshipFromCache(record.getRelId());
            }
            if (record.isCreated()) {
                getPropertyStore().freeId(record.getId());
                for (PropertyBlock block : record.getPropertyBlocks()) {
                    for (DynamicRecord dynamicRecord : block.getValueRecords()) {
                        if (dynamicRecord.isCreated()) {
                            if (dynamicRecord.getType() == PropertyType.STRING.intValue()) {
                                getPropertyStore().freeStringBlockId(dynamicRecord.getId());
                            } else if (dynamicRecord.getType() == PropertyType.ARRAY.intValue()) {
                                getPropertyStore().freeArrayBlockId(dynamicRecord.getId());
                            } else {
                                throw new InvalidRecordException("Unknown type on " + dynamicRecord);
                            }
                        }
                    }
                }
            }
        }
    } finally {
        nodeRecords.clear();
        propertyRecords.clear();
        relRecords.clear();
        relTypeRecords.clear();
        propIndexRecords.clear();
        nodeCommands.clear();
        propCommands.clear();
        propIndexCommands.clear();
        relCommands.clear();
        relTypeCommands.clear();
    }
}
Also used : DynamicRecord(org.neo4j.kernel.impl.nioneo.store.DynamicRecord) NodeRecord(org.neo4j.kernel.impl.nioneo.store.NodeRecord) XAException(javax.transaction.xa.XAException) PropertyRecord(org.neo4j.kernel.impl.nioneo.store.PropertyRecord) PropertyBlock(org.neo4j.kernel.impl.nioneo.store.PropertyBlock) RelationshipRecord(org.neo4j.kernel.impl.nioneo.store.RelationshipRecord) PropertyIndexRecord(org.neo4j.kernel.impl.nioneo.store.PropertyIndexRecord) RelationshipTypeRecord(org.neo4j.kernel.impl.nioneo.store.RelationshipTypeRecord) InvalidRecordException(org.neo4j.kernel.impl.nioneo.store.InvalidRecordException)

Example 35 with NodeRecord

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

the class WriteTransaction method nodeRemoveProperty.

@Override
public void nodeRemoveProperty(long nodeId, PropertyData propertyData) {
    long propertyId = propertyData.getId();
    NodeRecord nodeRecord = getNodeRecord(nodeId);
    if (nodeRecord == null) {
        nodeRecord = getNodeStore().getRecord(nodeId);
        addNodeRecord(nodeRecord);
    }
    if (!nodeRecord.inUse()) {
        throw new IllegalStateException("Property remove on node[" + nodeId + "] illegal since it has been deleted.");
    }
    assert assertPropertyChain(nodeRecord);
    PropertyRecord propRecord = getPropertyRecord(propertyId, false, true);
    if (!propRecord.inUse()) {
        throw new IllegalStateException("Unable to delete property[" + propertyId + "] since it is already deleted.");
    }
    propRecord.setNodeId(nodeId);
    PropertyBlock block = propRecord.removePropertyBlock(propertyData.getIndex());
    if (block == null) {
        throw new IllegalStateException("Property with index[" + propertyData.getIndex() + "] is not present in property[" + propertyId + "]");
    }
    if (block.isLight()) {
        getPropertyStore().makeHeavy(block);
    }
    for (DynamicRecord valueRecord : block.getValueRecords()) {
        assert valueRecord.inUse();
        valueRecord.setInUse(false, block.getType().intValue());
        propRecord.addDeletedRecord(valueRecord);
    }
    // propRecord.removeBlock( propertyData.getIndex() );
    if (propRecord.size() > 0) {
        /*
             * There are remaining blocks in the record. We do not unlink yet.
             */
        propRecord.setChanged();
        assert assertPropertyChain(nodeRecord);
        return;
    } else {
        if (unlinkPropertyRecord(propRecord, nodeRecord)) {
            addNodeRecord(nodeRecord);
        }
    }
}
Also used : DynamicRecord(org.neo4j.kernel.impl.nioneo.store.DynamicRecord) NodeRecord(org.neo4j.kernel.impl.nioneo.store.NodeRecord) PropertyRecord(org.neo4j.kernel.impl.nioneo.store.PropertyRecord) PropertyBlock(org.neo4j.kernel.impl.nioneo.store.PropertyBlock)

Aggregations

NodeRecord (org.neo4j.kernel.impl.nioneo.store.NodeRecord)36 PropertyRecord (org.neo4j.kernel.impl.nioneo.store.PropertyRecord)12 RelationshipRecord (org.neo4j.kernel.impl.nioneo.store.RelationshipRecord)12 InvalidRecordException (org.neo4j.kernel.impl.nioneo.store.InvalidRecordException)10 DynamicRecord (org.neo4j.kernel.impl.nioneo.store.DynamicRecord)6 ArrayList (java.util.ArrayList)4 XAException (javax.transaction.xa.XAException)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 XaCommand (org.neo4j.kernel.impl.transaction.xaframework.XaCommand)3 ArrayMap (org.neo4j.kernel.impl.util.ArrayMap)3 IOException (java.io.IOException)2 RelationshipType (org.neo4j.graphdb.RelationshipType)2 NodeStore (org.neo4j.kernel.impl.nioneo.store.NodeStore)2 RelationshipChainPosition (org.neo4j.kernel.impl.nioneo.store.RelationshipChainPosition)2 PropertyCommand (org.neo4j.kernel.impl.nioneo.xa.Command.PropertyCommand)2 ByteBuffer (java.nio.ByteBuffer)1 PrefetchingIterator (org.neo4j.helpers.collection.PrefetchingIterator)1