Search in sources :

Example 26 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)

Example 27 with NodeRecord

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

the class BatchInserterImpl method createNode.

public long createNode(Map<String, Object> properties) {
    long nodeId = getNodeStore().nextId();
    NodeRecord nodeRecord = new NodeRecord(nodeId);
    nodeRecord.setInUse(true);
    nodeRecord.setCreated();
    nodeRecord.setNextProp(createPropertyChain(properties));
    getNodeStore().updateRecord(nodeRecord);
    return nodeId;
}
Also used : NodeRecord(org.neo4j.kernel.impl.nioneo.store.NodeRecord)

Example 28 with NodeRecord

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

the class ReadTransaction method nodeGetProperties.

ArrayMap<Integer, PropertyData> nodeGetProperties(long nodeId) {
    NodeRecord nodeRecord = getNodeStore().getRecord(nodeId);
    long nextProp = nodeRecord.getNextProp();
    ArrayMap<Integer, PropertyData> propertyMap = new ArrayMap<Integer, PropertyData>(9, false, true);
    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)

Example 29 with NodeRecord

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

the class ReadTransaction method getRelationshipChainPosition.

public RelationshipChainPosition getRelationshipChainPosition(long nodeId) {
    NodeRecord nodeRecord = getNodeStore().getRecord(nodeId);
    long nextRel = nodeRecord.getNextRel();
    return new RelationshipChainPosition(nextRel);
}
Also used : NodeRecord(org.neo4j.kernel.impl.nioneo.store.NodeRecord) RelationshipChainPosition(org.neo4j.kernel.impl.nioneo.store.RelationshipChainPosition)

Example 30 with NodeRecord

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

the class WriteTransaction method nodeDelete.

ArrayMap<Integer, PropertyData> nodeDelete(long nodeId) {
    NodeRecord nodeRecord = getNodeRecord(nodeId);
    if (nodeRecord == null) {
        nodeRecord = getNodeStore().getRecord(nodeId);
        addNodeRecord(nodeRecord);
    }
    if (!nodeRecord.inUse()) {
        throw new IllegalStateException("Unable to delete Node[" + nodeId + "] since it has already been deleted.");
    }
    nodeRecord.setInUse(false);
    ArrayMap<Integer, PropertyData> propertyMap = new ArrayMap<Integer, PropertyData>(9, false, true);
    long nextProp = nodeRecord.getNextProp();
    while (nextProp != Record.NO_NEXT_PROPERTY.intValue()) {
        PropertyRecord propRecord = getPropertyRecord(nextProp);
        if (propRecord == null) {
            propRecord = getPropertyStore().getRecord(nextProp);
            addPropertyRecord(propRecord);
        }
        if (propRecord.isLight()) {
            getPropertyStore().makeHeavy(propRecord);
        }
        if (!propRecord.isCreated()) {
            if (!propRecord.isChanged()) {
                propertyMap.put(propRecord.getKeyIndexId(), new PropertyData(propRecord.getId(), propertyGetValueOrNull(propRecord)));
            } else {
                // we have to re-read committed value since property has 
                // changed and old value is erased in memory
                PropertyRecord diskValue = getPropertyStore().getRecord(propRecord.getId());
                getPropertyStore().makeHeavy(diskValue);
                propertyMap.put(diskValue.getKeyIndexId(), new PropertyData(diskValue.getId(), propertyGetValueOrNull(diskValue)));
            }
        }
        nextProp = propRecord.getNextProp();
        propRecord.setInUse(false);
        // TODO: update count on property index record
        for (DynamicRecord valueRecord : propRecord.getValueRecords()) {
            valueRecord.setInUse(false);
        }
    }
    return propertyMap;
}
Also used : DynamicRecord(org.neo4j.kernel.impl.nioneo.store.DynamicRecord) 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)

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