Search in sources :

Example 31 with PropertyData

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

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);
        ArrayMap<Integer, PropertyData> removeMap = nodeManager.getCowPropertyRemoveMap(this, true);
        for (PropertyIndex cachedIndex : nodeManager.index(key)) {
            if (addMap != null) {
                property = addMap.remove(cachedIndex.getKeyId());
                if (property != null) {
                    removeMap.put(cachedIndex.getKeyId(), property);
                    break;
                }
            }
            if (removeMap.get(cachedIndex.getKeyId()) != null) {
                success = true;
                return null;
            }
            property = propertyMap.get(cachedIndex.getKeyId());
            if (property != null) {
                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.put(indexToCheck.getKeyId(), property);
                                break;
                            }
                        }
                    }
                }
                if (property == null) {
                    for (int keyId : propertyMap.keySet()) {
                        if (!nodeManager.hasIndexFor(keyId)) {
                            PropertyIndex indexToCheck = nodeManager.getIndexFor(keyId);
                            if (indexToCheck.getKey().equals(key)) {
                                property = propertyMap.get(indexToCheck.getKeyId());
                                if (property != null) {
                                    removeMap.put(indexToCheck.getKeyId(), property);
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
        if (property == null) {
            success = true;
            return null;
        }
        removeProperty(nodeManager, property.getId());
        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)

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