Search in sources :

Example 1 with PropertyData

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

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.getId());
                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.getId());
                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 2 with PropertyData

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

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 = getPropertyForIndex(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)

Example 3 with PropertyData

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

the class LockReleaser method populateNodeRelEvent.

private void populateNodeRelEvent(PrimitiveElement element, TransactionDataImpl result) {
    for (long nodeId : element.nodes.keySet()) {
        CowNodeElement nodeElement = element.nodes.get(nodeId);
        NodeProxy node = new NodeProxy(nodeId, nodeManager);
        NodeImpl nodeImpl = nodeManager.getNodeForProxy(nodeId);
        if (nodeElement.deleted) {
            if (nodeManager.nodeCreated(nodeId)) {
                continue;
            }
            result.deleted(node);
        }
        if (nodeElement.relationshipAddMap != null && !nodeElement.deleted) {
            for (String type : nodeElement.relationshipAddMap.keySet()) {
                RelIdArray createdRels = nodeElement.relationshipAddMap.get(type);
                populateNodeRelEvent(element, result, nodeId, createdRels);
            }
        }
        if (nodeElement.relationshipRemoveMap != null) {
            for (String type : nodeElement.relationshipRemoveMap.keySet()) {
                Collection<Long> deletedRels = nodeElement.relationshipRemoveMap.get(type);
                for (long relId : deletedRels) {
                    if (nodeManager.relCreated(relId)) {
                        continue;
                    }
                    RelationshipProxy rel = new RelationshipProxy(relId, nodeManager);
                    if (rel.getStartNode().getId() == nodeId) {
                        result.deleted(new RelationshipProxy(relId, nodeManager));
                    }
                }
            }
        }
        if (nodeElement.propertyAddMap != null && !nodeElement.deleted) {
            for (PropertyData data : nodeElement.propertyAddMap.values()) {
                String key = nodeManager.getKeyForProperty(data);
                Object oldValue = nodeImpl.getCommittedPropertyValue(nodeManager, key);
                Object newValue = data.getValue();
                result.assignedProperty(node, key, newValue, oldValue);
            }
        }
        if (nodeElement.propertyRemoveMap != null) {
            for (PropertyData data : nodeElement.propertyRemoveMap.values()) {
                String key = nodeManager.getKeyForProperty(data);
                Object oldValue = data.getValue();
                if (oldValue == null && !nodeElement.deleted) {
                    nodeImpl.getCommittedPropertyValue(nodeManager, key);
                }
                result.removedProperty(node, key, oldValue);
            }
        }
    }
}
Also used : PropertyData(org.neo4j.kernel.impl.nioneo.store.PropertyData) RelIdArray(org.neo4j.kernel.impl.util.RelIdArray)

Example 4 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) throws NotFoundException {
    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) {
            throw newPropertyNotFoundException(key);
        }
        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);
    }
    throw newPropertyNotFoundException(key);
}
Also used : PropertyData(org.neo4j.kernel.impl.nioneo.store.PropertyData)

Example 5 with PropertyData

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

the class Primitive method setProperty.

public void setProperty(NodeManager nodeManager, String key, Object value) {
    if (key == null || value == null) {
        throw new IllegalArgumentException("Null parameter, " + "key=" + key + ", " + "value=" + value);
    }
    nodeManager.acquireLock(this, LockType.WRITE);
    boolean success = false;
    try {
        ensureFullProperties(nodeManager);
        ArrayMap<Integer, PropertyData> addMap = nodeManager.getCowPropertyAddMap(this, true);
        ArrayMap<Integer, PropertyData> skipMap = nodeManager.getCowPropertyRemoveMap(this);
        PropertyIndex index = null;
        PropertyData property = null;
        boolean foundInSkipMap = false;
        for (PropertyIndex cachedIndex : nodeManager.index(key)) {
            if (skipMap != null) {
                if (skipMap.remove(cachedIndex.getKeyId()) != null) {
                    foundInSkipMap = true;
                }
            }
            index = cachedIndex;
            property = addMap.get(cachedIndex.getKeyId());
            if (property != null) {
                break;
            }
            property = propertyMap.get(cachedIndex.getKeyId());
            if (property != null) {
                break;
            }
        }
        if (property == null && !nodeManager.hasAllPropertyIndexes()) {
            for (int keyId : addMap.keySet()) {
                if (!nodeManager.hasIndexFor(keyId)) {
                    PropertyIndex indexToCheck = nodeManager.getIndexFor(keyId);
                    if (indexToCheck.getKey().equals(key)) {
                        if (skipMap != null) {
                            skipMap.remove(indexToCheck.getKeyId());
                        }
                        index = indexToCheck;
                        property = addMap.get(indexToCheck.getKeyId());
                        if (property != null) {
                            break;
                        }
                    }
                }
            }
            if (property == null) {
                for (int keyId : propertyMap.keySet()) {
                    if (!nodeManager.hasIndexFor(keyId)) {
                        PropertyIndex indexToCheck = nodeManager.getIndexFor(keyId);
                        if (indexToCheck.getKey().equals(key)) {
                            if (skipMap != null) {
                                skipMap.remove(indexToCheck.getKeyId());
                            }
                            index = indexToCheck;
                            property = propertyMap.get(indexToCheck.getKeyId());
                            if (property != null) {
                                break;
                            }
                        }
                    }
                }
            }
        }
        if (index == null) {
            index = nodeManager.createPropertyIndex(key);
        }
        if (property != null && !foundInSkipMap) {
            long propertyId = property.getId();
            changeProperty(nodeManager, propertyId, value);
            property = new PropertyData(propertyId, value);
        } else {
            long propertyId = addProperty(nodeManager, index, value);
            property = new PropertyData(propertyId, value);
        }
        addMap.put(index.getKeyId(), property);
        success = true;
    } 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