Search in sources :

Example 6 with PropertyData

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

the class Primitive method getProperty.

public Object getProperty(NodeManager nodeManager, String key, Object defaultValue) {
    if (key == null) {
        throw new IllegalArgumentException("null key");
    }
    ArrayMap<Integer, PropertyData> skipMap = nodeManager.getCowPropertyRemoveMap(this);
    ArrayMap<Integer, PropertyData> addMap = nodeManager.getCowPropertyAddMap(this);
    ensureFullProperties(nodeManager);
    for (PropertyIndex index : nodeManager.index(key)) {
        if (skipMap != null && skipMap.get(index.getKeyId()) != null) {
            return defaultValue;
        }
        if (addMap != null) {
            PropertyData property = addMap.get(index.getKeyId());
            if (property != null) {
                return getPropertyValue(nodeManager, property);
            }
        }
        PropertyData property = propertyMap.get(index.getKeyId());
        if (property != null) {
            return getPropertyValue(nodeManager, property);
        }
    }
    PropertyData property = getSlowProperty(nodeManager, addMap, skipMap, key);
    if (property != null) {
        return getPropertyValue(nodeManager, property);
    }
    return defaultValue;
}
Also used : PropertyData(org.neo4j.kernel.impl.nioneo.store.PropertyData)

Example 7 with PropertyData

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

the class WriteTransaction method nodeGetProperties.

ArrayMap<Integer, PropertyData> nodeGetProperties(long nodeId, boolean light) {
    ArrayMap<Integer, PropertyData> propertyMap = new ArrayMap<Integer, PropertyData>(9, false, true);
    NodeRecord nodeRecord = getNodeRecord(nodeId);
    if (nodeRecord != null && nodeRecord.isCreated()) {
        return propertyMap;
    }
    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");
    }
    long nextProp = nodeRecord.getNextProp();
    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) InvalidRecordException(org.neo4j.kernel.impl.nioneo.store.InvalidRecordException)

Example 8 with PropertyData

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

the class WriteTransaction method relDelete.

ArrayMap<Integer, PropertyData> relDelete(long id) {
    RelationshipRecord record = getRelationshipRecord(id);
    if (record == null) {
        record = getRelationshipStore().getRecord(id);
        addRelationshipRecord(record);
    }
    if (!record.inUse()) {
        throw new IllegalStateException("Unable to delete relationship[" + id + "] since it is already deleted.");
    }
    ArrayMap<Integer, PropertyData> propertyMap = new ArrayMap<Integer, PropertyData>(9, false, true);
    long nextProp = record.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);
        }
    }
    disconnectRelationship(record);
    updateNodes(record);
    record.setInUse(false);
    return propertyMap;
}
Also used : DynamicRecord(org.neo4j.kernel.impl.nioneo.store.DynamicRecord) 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)

Example 9 with PropertyData

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

the class Primitive method getPropertyValues.

public Iterable<Object> getPropertyValues(NodeManager nodeManager) {
    ArrayMap<Integer, PropertyData> skipMap = nodeManager.getCowPropertyRemoveMap(this);
    ArrayMap<Integer, PropertyData> addMap = nodeManager.getCowPropertyAddMap(this);
    ensureFullProperties(nodeManager);
    List<Object> values = new ArrayList<Object>();
    for (Integer index : propertyMap.keySet()) {
        if (skipMap != null && skipMap.get(index) != null) {
            continue;
        }
        if (addMap != null && addMap.get(index) != null) {
            continue;
        }
        values.add(propertyMap.get(index).getValue());
    }
    if (addMap != null) {
        for (PropertyData property : addMap.values()) {
            values.add(property.getValue());
        }
    }
    return values;
}
Also used : PropertyData(org.neo4j.kernel.impl.nioneo.store.PropertyData) ArrayList(java.util.ArrayList)

Example 10 with PropertyData

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

the class Primitive method hasProperty.

public boolean hasProperty(NodeManager nodeManager, String key) {
    if (key == null) {
        return false;
    }
    ArrayMap<Integer, PropertyData> skipMap = nodeManager.getCowPropertyRemoveMap(this);
    ArrayMap<Integer, PropertyData> addMap = nodeManager.getCowPropertyAddMap(this);
    ensureFullProperties(nodeManager);
    for (PropertyIndex index : nodeManager.index(key)) {
        if (skipMap != null && skipMap.get(index.getKeyId()) != null) {
            return false;
        }
        if (addMap != null) {
            PropertyData property = addMap.get(index.getKeyId());
            if (property != null) {
                return true;
            }
        }
        PropertyData property = propertyMap.get(index.getKeyId());
        if (property != null) {
            return true;
        }
    }
    PropertyData property = getSlowProperty(nodeManager, addMap, skipMap, key);
    if (property != null) {
        return true;
    }
    return false;
}
Also used : PropertyData(org.neo4j.kernel.impl.nioneo.store.PropertyData)

Aggregations

PropertyData (org.neo4j.kernel.impl.nioneo.store.PropertyData)31 PropertyRecord (org.neo4j.kernel.impl.nioneo.store.PropertyRecord)8 ArrayMap (org.neo4j.kernel.impl.util.ArrayMap)7 ArrayList (java.util.ArrayList)4 NodeRecord (org.neo4j.kernel.impl.nioneo.store.NodeRecord)4 RelationshipRecord (org.neo4j.kernel.impl.nioneo.store.RelationshipRecord)4 DynamicRecord (org.neo4j.kernel.impl.nioneo.store.DynamicRecord)3 InvalidRecordException (org.neo4j.kernel.impl.nioneo.store.InvalidRecordException)3 PropertyBlock (org.neo4j.kernel.impl.nioneo.store.PropertyBlock)2 RelIdArray (org.neo4j.kernel.impl.util.RelIdArray)2 HashMap (java.util.HashMap)1 NotFoundException (org.neo4j.graphdb.NotFoundException)1 RelationshipType (org.neo4j.graphdb.RelationshipType)1 PropertyStore (org.neo4j.kernel.impl.nioneo.store.PropertyStore)1 PropertyStore.encodeString (org.neo4j.kernel.impl.nioneo.store.PropertyStore.encodeString)1 LockException (org.neo4j.kernel.impl.transaction.LockException)1 RelIdIterator (org.neo4j.kernel.impl.util.RelIdArray.RelIdIterator)1