Search in sources :

Example 16 with PropertyData

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

the class LockReleaser method populateRelationshipPropertyEvents.

private void populateRelationshipPropertyEvents(PrimitiveElement element, TransactionDataImpl result) {
    for (long relId : element.relationships.keySet()) {
        CowRelElement relElement = element.relationships.get(relId);
        RelationshipProxy rel = new RelationshipProxy(relId, nodeManager);
        RelationshipImpl relImpl = nodeManager.getRelForProxy(relId);
        if (relElement.deleted) {
            if (nodeManager.relCreated(relId)) {
                continue;
            }
        // note: this is done in node populate data
        // result.deleted( rel );
        }
        if (relElement.propertyAddMap != null && !relElement.deleted) {
            for (PropertyData data : relElement.propertyAddMap.values()) {
                String key = nodeManager.getKeyForProperty(data);
                Object oldValue = relImpl.getCommittedPropertyValue(nodeManager, key);
                Object newValue = data.getValue();
                result.assignedProperty(rel, key, newValue, oldValue);
            }
        }
        if (relElement.propertyRemoveMap != null) {
            for (PropertyData data : relElement.propertyRemoveMap.values()) {
                String key = nodeManager.getKeyForProperty(data);
                Object oldValue = data.getValue();
                if (oldValue != null && !relElement.deleted) {
                    relImpl.getCommittedPropertyValue(nodeManager, key);
                }
                result.removedProperty(rel, key, oldValue);
            }
        }
    }
}
Also used : PropertyData(org.neo4j.kernel.impl.nioneo.store.PropertyData)

Example 17 with PropertyData

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

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 = getPropertyForIndex(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 18 with PropertyData

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

the class Primitive method removeProperty.

public Object removeProperty(NodeManager nodeManager, String key) {
    if (key == null) {
        throw new IllegalArgumentException("Null parameter.");
    }
    nodeManager.acquireLock(this, LockType.WRITE);
    boolean success = false;
    try {
        ensureFullProperties(nodeManager);
        PropertyData property = null;
        ArrayMap<Integer, PropertyData> addMap = nodeManager.getCowPropertyAddMap(this);
        // Don't create the map if it doesn't exist here... but instead when (and if)
        // the property is found below.
        ArrayMap<Integer, PropertyData> removeMap = nodeManager.getCowPropertyRemoveMap(this, false);
        for (PropertyIndex cachedIndex : nodeManager.index(key)) {
            if (addMap != null) {
                property = addMap.remove(cachedIndex.getKeyId());
                if (property != null) {
                    removeMap = removeMap != null ? removeMap : nodeManager.getCowPropertyRemoveMap(this, true);
                    removeMap.put(cachedIndex.getKeyId(), property);
                    break;
                }
            }
            if (removeMap != null && removeMap.get(cachedIndex.getKeyId()) != null) {
                success = true;
                return null;
            }
            property = getPropertyForIndex(cachedIndex.getKeyId());
            if (property != null) {
                removeMap = removeMap != null ? removeMap : nodeManager.getCowPropertyRemoveMap(this, true);
                removeMap.put(cachedIndex.getKeyId(), property);
                break;
            }
        }
        if (property == null && !nodeManager.hasAllPropertyIndexes()) {
            if (addMap != null) {
                for (int keyId : addMap.keySet()) {
                    if (!nodeManager.hasIndexFor(keyId)) {
                        PropertyIndex indexToCheck = nodeManager.getIndexFor(keyId);
                        if (indexToCheck.getKey().equals(key)) {
                            property = addMap.remove(indexToCheck.getKeyId());
                            if (property != null) {
                                removeMap = removeMap != null ? removeMap : nodeManager.getCowPropertyRemoveMap(this, true);
                                removeMap.put(indexToCheck.getKeyId(), property);
                                break;
                            }
                        }
                    }
                }
                if (property == null) {
                    for (PropertyData aProperty : properties) {
                        int keyId = aProperty.getIndex();
                        if (!nodeManager.hasIndexFor(keyId)) {
                            PropertyIndex indexToCheck = nodeManager.getIndexFor(keyId);
                            if (indexToCheck.getKey().equals(key)) {
                                property = getPropertyForIndex(indexToCheck.getKeyId());
                                if (property != null) {
                                    removeMap = removeMap != null ? removeMap : nodeManager.getCowPropertyRemoveMap(this, true);
                                    removeMap.put(indexToCheck.getKeyId(), property);
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
        if (property == null) {
            success = true;
            return null;
        }
        removeProperty(nodeManager, property);
        success = true;
        return getPropertyValue(nodeManager, property);
    } finally {
        nodeManager.releaseLock(this, LockType.WRITE);
        if (!success) {
            nodeManager.setRollbackOnly();
        }
    }
}
Also used : PropertyData(org.neo4j.kernel.impl.nioneo.store.PropertyData)

Example 19 with PropertyData

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

the class Primitive method getAllCommittedProperties.

protected List<PropertyEventData> getAllCommittedProperties(NodeManager nodeManager) {
    ensureFullLightProperties(nodeManager);
    if (properties == null) {
        return new ArrayList<PropertyEventData>();
    }
    List<PropertyEventData> props = new ArrayList<PropertyEventData>(properties.length);
    for (PropertyData property : properties) {
        PropertyIndex index = nodeManager.getIndexFor(property.getIndex());
        Object value = getPropertyValue(nodeManager, property);
        props.add(new PropertyEventData(index.getKey(), value));
    }
    return props;
}
Also used : PropertyData(org.neo4j.kernel.impl.nioneo.store.PropertyData) ArrayList(java.util.ArrayList)

Example 20 with PropertyData

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

the class Primitive method commitPropertyMaps.

protected void commitPropertyMaps(ArrayMap<Integer, PropertyData> cowPropertyAddMap, ArrayMap<Integer, PropertyData> cowPropertyRemoveMap) {
    if (properties == null) {
        // we will load full in some other tx
        return;
    }
    PropertyData[] newArray = properties;
    /*
         * add map will definitely be added in the properties array - all properties
         * added and later removed in the same tx are removed from there as well.
         * The remove map will not necessarily be removed, since it may hold a prop that was
         * added in this tx. So the difference in size is all the keys that are common
         * between properties and remove map subtracted by the add map size.
         */
    int extraLength = 0;
    if (cowPropertyAddMap != null) {
        extraLength += cowPropertyAddMap.size();
    }
    if (extraLength > 0) {
        newArray = new PropertyData[properties.length + extraLength];
        System.arraycopy(properties, 0, newArray, 0, properties.length);
    }
    int newArraySize = properties.length;
    if (cowPropertyRemoveMap != null) {
        for (Integer keyIndex : cowPropertyRemoveMap.keySet()) {
            for (int i = 0; i < newArraySize; i++) {
                PropertyData existingProperty = newArray[i];
                if (existingProperty.getIndex() == keyIndex) {
                    int swapWith = --newArraySize;
                    newArray[i] = newArray[swapWith];
                    newArray[swapWith] = null;
                    break;
                }
            }
        }
    }
    if (cowPropertyAddMap != null) {
        for (PropertyData addedProperty : cowPropertyAddMap.values()) {
            for (int i = 0; i < newArray.length; i++) {
                PropertyData existingProperty = newArray[i];
                if (existingProperty == null || addedProperty.getIndex() == existingProperty.getIndex()) {
                    newArray[i] = addedProperty;
                    if (existingProperty == null) {
                        newArraySize++;
                    }
                    break;
                }
            }
        }
    }
    if (newArraySize < newArray.length) {
        PropertyData[] compactedNewArray = new PropertyData[newArraySize];
        System.arraycopy(newArray, 0, compactedNewArray, 0, newArraySize);
        properties = compactedNewArray;
    } else {
        properties = newArray;
    }
}
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