Search in sources :

Example 16 with DynamicRecord

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

the class BatchInserterImpl method createNewPropertyIndex.

private int createNewPropertyIndex(String stringKey) {
    PropertyIndexStore idxStore = getPropertyIndexStore();
    int keyId = (int) idxStore.nextId();
    PropertyIndexRecord record = new PropertyIndexRecord(keyId);
    record.setInUse(true);
    record.setCreated();
    int keyBlockId = idxStore.nextKeyBlockId();
    record.setKeyBlockId(keyBlockId);
    Collection<DynamicRecord> keyRecords = idxStore.allocateKeyRecords(keyBlockId, encodeString(stringKey));
    for (DynamicRecord keyRecord : keyRecords) {
        record.addKeyRecord(keyRecord);
    }
    idxStore.updateRecord(record);
    indexHolder.addPropertyIndex(stringKey, keyId);
    return keyId;
}
Also used : DynamicRecord(org.neo4j.kernel.impl.nioneo.store.DynamicRecord) PropertyIndexRecord(org.neo4j.kernel.impl.nioneo.store.PropertyIndexRecord) PropertyIndexStore(org.neo4j.kernel.impl.nioneo.store.PropertyIndexStore)

Example 17 with DynamicRecord

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

the class BatchInserterImpl method createNewPropertyIndex.

private int createNewPropertyIndex(String stringKey) {
    PropertyIndexStore idxStore = getPropertyIndexStore();
    int keyId = (int) idxStore.nextId();
    PropertyIndexRecord record = new PropertyIndexRecord(keyId);
    record.setInUse(true);
    record.setCreated();
    int keyBlockId = idxStore.nextKeyBlockId();
    record.setKeyBlockId(keyBlockId);
    int length = stringKey.length();
    char[] chars = new char[length];
    stringKey.getChars(0, length, chars, 0);
    Collection<DynamicRecord> keyRecords = idxStore.allocateKeyRecords(keyBlockId, chars);
    for (DynamicRecord keyRecord : keyRecords) {
        record.addKeyRecord(keyRecord);
    }
    idxStore.updateRecord(record);
    indexHolder.addPropertyIndex(stringKey, keyId);
    return keyId;
}
Also used : DynamicRecord(org.neo4j.kernel.impl.nioneo.store.DynamicRecord) PropertyIndexRecord(org.neo4j.kernel.impl.nioneo.store.PropertyIndexRecord) PropertyIndexStore(org.neo4j.kernel.impl.nioneo.store.PropertyIndexStore)

Example 18 with DynamicRecord

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

Example 19 with DynamicRecord

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

the class WriteTransaction method nodeRemoveProperty.

void nodeRemoveProperty(long nodeId, long propertyId) {
    NodeRecord nodeRecord = getNodeRecord(nodeId);
    if (nodeRecord == null) {
        nodeRecord = getNodeStore().getRecord(nodeId);
    }
    if (!nodeRecord.inUse()) {
        throw new IllegalStateException("Property remove on node[" + nodeId + "] illegal since it has been deleted.");
    }
    PropertyRecord propRecord = getPropertyRecord(propertyId);
    if (propRecord == null) {
        propRecord = getPropertyStore().getRecord(propertyId);
        addPropertyRecord(propRecord);
    }
    if (!propRecord.inUse()) {
        throw new IllegalStateException("Unable to delete property[" + propertyId + "] since it is already deleted.");
    }
    propRecord.setNodeId(nodeId);
    if (propRecord.isLight()) {
        getPropertyStore().makeHeavy(propRecord);
    }
    propRecord.setInUse(false);
    // TODO: update count on property index record
    for (DynamicRecord valueRecord : propRecord.getValueRecords()) {
        if (valueRecord.inUse()) {
            valueRecord.setInUse(false, propRecord.getType().intValue());
        }
    }
    long prevProp = propRecord.getPrevProp();
    long nextProp = propRecord.getNextProp();
    if (nodeRecord.getNextProp() == propertyId) {
        nodeRecord.setNextProp(nextProp);
        // re-adding not a problem
        addNodeRecord(nodeRecord);
    }
    if (prevProp != Record.NO_PREVIOUS_PROPERTY.intValue()) {
        PropertyRecord prevPropRecord = getPropertyRecord(prevProp);
        if (prevPropRecord == null) {
            prevPropRecord = getPropertyStore().getLightRecord(prevProp);
            addPropertyRecord(prevPropRecord);
        }
        assert prevPropRecord.inUse();
        prevPropRecord.setNextProp(nextProp);
    }
    if (nextProp != Record.NO_NEXT_PROPERTY.intValue()) {
        PropertyRecord nextPropRecord = getPropertyRecord(nextProp);
        if (nextPropRecord == null) {
            nextPropRecord = getPropertyStore().getLightRecord(nextProp);
            addPropertyRecord(nextPropRecord);
        }
        assert nextPropRecord.inUse();
        nextPropRecord.setPrevProp(prevProp);
    }
}
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)

Example 20 with DynamicRecord

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

the class WriteTransaction method nodeChangeProperty.

void nodeChangeProperty(long nodeId, long propertyId, Object value) {
    NodeRecord nodeRecord = getNodeRecord(nodeId);
    if (nodeRecord == null) {
        nodeRecord = getNodeStore().getRecord(nodeId);
    }
    if (!nodeRecord.inUse()) {
        throw new IllegalStateException("Property change on node[" + nodeId + "] illegal since it has been deleted.");
    }
    PropertyRecord propertyRecord = getPropertyRecord(propertyId);
    if (propertyRecord == null) {
        propertyRecord = getPropertyStore().getRecord(propertyId);
        addPropertyRecord(propertyRecord);
    }
    if (!propertyRecord.inUse()) {
        throw new IllegalStateException("Unable to change property[" + propertyId + "] since it is deleted.");
    }
    propertyRecord.setNodeId(nodeId);
    if (propertyRecord.isLight()) {
        getPropertyStore().makeHeavy(propertyRecord);
    }
    propertyRecord.setChanged();
    if (propertyRecord.getType() == PropertyType.STRING) {
        for (DynamicRecord record : propertyRecord.getValueRecords()) {
            if (record.inUse()) {
                record.setInUse(false, PropertyType.STRING.intValue());
            }
        }
    } else if (propertyRecord.getType() == PropertyType.ARRAY) {
        for (DynamicRecord record : propertyRecord.getValueRecords()) {
            if (record.inUse()) {
                record.setInUse(false, PropertyType.ARRAY.intValue());
            }
        }
    }
    getPropertyStore().encodeValue(propertyRecord, value);
    addPropertyRecord(propertyRecord);
}
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)

Aggregations

DynamicRecord (org.neo4j.kernel.impl.nioneo.store.DynamicRecord)30 PropertyRecord (org.neo4j.kernel.impl.nioneo.store.PropertyRecord)15 PropertyBlock (org.neo4j.kernel.impl.nioneo.store.PropertyBlock)7 PropertyIndexRecord (org.neo4j.kernel.impl.nioneo.store.PropertyIndexRecord)7 RelationshipTypeRecord (org.neo4j.kernel.impl.nioneo.store.RelationshipTypeRecord)7 NodeRecord (org.neo4j.kernel.impl.nioneo.store.NodeRecord)6 RelationshipRecord (org.neo4j.kernel.impl.nioneo.store.RelationshipRecord)6 IOException (java.io.IOException)5 PropertyIndexStore (org.neo4j.kernel.impl.nioneo.store.PropertyIndexStore)4 PropertyData (org.neo4j.kernel.impl.nioneo.store.PropertyData)3 XaCommand (org.neo4j.kernel.impl.transaction.xaframework.XaCommand)3 ArrayMap (org.neo4j.kernel.impl.util.ArrayMap)3 XAException (javax.transaction.xa.XAException)2 InvalidRecordException (org.neo4j.kernel.impl.nioneo.store.InvalidRecordException)2 PropertyStore (org.neo4j.kernel.impl.nioneo.store.PropertyStore)2 RelationshipTypeStore (org.neo4j.kernel.impl.nioneo.store.RelationshipTypeStore)2 PropertyType (org.neo4j.kernel.impl.nioneo.store.PropertyType)1