Search in sources :

Example 26 with PropertyRecord

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

the class BatchInserterImpl method createPropertyChain.

private long createPropertyChain(Map<String, Object> properties) {
    if (properties == null) {
        return Record.NO_NEXT_PROPERTY.intValue();
    }
    PropertyStore propStore = getPropertyStore();
    List<PropertyRecord> propRecords = new ArrayList<PropertyRecord>();
    PropertyRecord prevRecord = null;
    for (Entry<String, Object> entry : properties.entrySet()) {
        int keyId = indexHolder.getKeyId(entry.getKey());
        if (keyId == -1) {
            keyId = createNewPropertyIndex(entry.getKey());
        }
        long propertyId = propStore.nextId();
        PropertyRecord propertyRecord = new PropertyRecord(propertyId);
        propertyRecord.setInUse(true);
        propertyRecord.setCreated();
        propertyRecord.setKeyIndexId(keyId);
        propStore.encodeValue(propertyRecord, entry.getValue());
        if (prevRecord != null) {
            prevRecord.setPrevProp(propertyId);
            propertyRecord.setNextProp(prevRecord.getId());
        }
        propRecords.add(propertyRecord);
        prevRecord = propertyRecord;
    }
    // reverse order results in forward update to store
    for (int i = propRecords.size() - 1; i >= 0; i--) {
        propStore.updateRecord(propRecords.get(i));
    }
    if (prevRecord != null) {
        return prevRecord.getId();
    }
    return Record.NO_NEXT_PROPERTY.intValue();
}
Also used : PropertyRecord(org.neo4j.kernel.impl.nioneo.store.PropertyRecord) ArrayList(java.util.ArrayList) PropertyStore(org.neo4j.kernel.impl.nioneo.store.PropertyStore)

Example 27 with PropertyRecord

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

the class BatchInserterImpl method getPropertyChain.

private Map<String, Object> getPropertyChain(long propertyId) {
    PropertyStore propStore = getPropertyStore();
    PropertyRecord propertyRecord = propStore.getRecord(propertyId);
    long nextProperty = -1;
    Map<String, Object> properties = new HashMap<String, Object>();
    do {
        nextProperty = propertyRecord.getNextProp();
        propStore.makeHeavy(propertyRecord);
        String key = indexHolder.getStringKey(propertyRecord.getKeyIndexId());
        Object value = propStore.getValue(propertyRecord);
        properties.put(key, value);
        if (nextProperty != Record.NO_NEXT_PROPERTY.intValue()) {
            propertyRecord = propStore.getRecord(propertyRecord.getNextProp());
        }
    } while (nextProperty != Record.NO_NEXT_PROPERTY.intValue());
    return properties;
}
Also used : PropertyRecord(org.neo4j.kernel.impl.nioneo.store.PropertyRecord) HashMap(java.util.HashMap) PropertyStore(org.neo4j.kernel.impl.nioneo.store.PropertyStore)

Example 28 with PropertyRecord

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

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

the class ReadTransaction method relGetProperties.

public ArrayMap<Integer, PropertyData> relGetProperties(long relId) {
    RelationshipRecord relRecord = getRelationshipStore().getRecord(relId);
    if (!relRecord.inUse()) {
        throw new InvalidRecordException("Relationship[" + relId + "] not in use");
    }
    long nextProp = relRecord.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 : PropertyData(org.neo4j.kernel.impl.nioneo.store.PropertyData) PropertyRecord(org.neo4j.kernel.impl.nioneo.store.PropertyRecord) RelationshipRecord(org.neo4j.kernel.impl.nioneo.store.RelationshipRecord) ArrayMap(org.neo4j.kernel.impl.util.ArrayMap) InvalidRecordException(org.neo4j.kernel.impl.nioneo.store.InvalidRecordException)

Example 30 with PropertyRecord

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

PropertyRecord (org.neo4j.kernel.impl.nioneo.store.PropertyRecord)36 DynamicRecord (org.neo4j.kernel.impl.nioneo.store.DynamicRecord)15 PropertyBlock (org.neo4j.kernel.impl.nioneo.store.PropertyBlock)13 NodeRecord (org.neo4j.kernel.impl.nioneo.store.NodeRecord)12 RelationshipRecord (org.neo4j.kernel.impl.nioneo.store.RelationshipRecord)12 PropertyData (org.neo4j.kernel.impl.nioneo.store.PropertyData)8 InvalidRecordException (org.neo4j.kernel.impl.nioneo.store.InvalidRecordException)7 ArrayMap (org.neo4j.kernel.impl.util.ArrayMap)7 PropertyStore (org.neo4j.kernel.impl.nioneo.store.PropertyStore)6 XAException (javax.transaction.xa.XAException)4 PropertyIndexRecord (org.neo4j.kernel.impl.nioneo.store.PropertyIndexRecord)4 RelationshipTypeRecord (org.neo4j.kernel.impl.nioneo.store.RelationshipTypeRecord)4 ArrayList (java.util.ArrayList)3 XaCommand (org.neo4j.kernel.impl.transaction.xaframework.XaCommand)3 HashMap (java.util.HashMap)2 LinkedList (java.util.LinkedList)2 PropertyStore.encodeString (org.neo4j.kernel.impl.nioneo.store.PropertyStore.encodeString)2 PropertyCommand (org.neo4j.kernel.impl.nioneo.xa.Command.PropertyCommand)2 PropertyType (org.neo4j.kernel.impl.nioneo.store.PropertyType)1