Search in sources :

Example 21 with PropertyData

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

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 = getPropertyForIndex(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 (PropertyData aProperty : properties) {
                    int keyId = aProperty.getIndex();
                    if (!nodeManager.hasIndexFor(keyId)) {
                        PropertyIndex indexToCheck = nodeManager.getIndexFor(keyId);
                        if (indexToCheck.getKey().equals(key)) {
                            if (skipMap != null) {
                                skipMap.remove(indexToCheck.getKeyId());
                            }
                            index = indexToCheck;
                            property = getPropertyForIndex(indexToCheck.getKeyId());
                            if (property != null) {
                                break;
                            }
                        }
                    }
                }
            }
        }
        if (index == null) {
            index = nodeManager.createPropertyIndex(key);
        }
        if (property != null && !foundInSkipMap) {
            property = changeProperty(nodeManager, property, value);
        } else {
            property = addProperty(nodeManager, index, 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)

Example 22 with PropertyData

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

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 (PropertyData property : properties) {
        Integer index = property.getIndex();
        if (skipMap != null && skipMap.get(index) != null) {
            continue;
        }
        if (addMap != null && addMap.get(index) != null) {
            continue;
        }
        values.add(property.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 23 with PropertyData

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

the class Primitive method getPropertyKeys.

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

Example 24 with PropertyData

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

the class WriteTransaction method getAndDeletePropertyChain.

private ArrayMap<Integer, PropertyData> getAndDeletePropertyChain(long startingAt) {
    ArrayMap<Integer, PropertyData> result = new ArrayMap<Integer, PropertyData>(9, false, true);
    long nextProp = startingAt;
    while (nextProp != Record.NO_NEXT_PROPERTY.intValue()) {
        PropertyRecord propRecord = getPropertyRecord(nextProp, false, true);
        if (!propRecord.isCreated() && propRecord.isChanged()) {
            // Being here means a new value could be on disk. Re-read
            propRecord = getPropertyStore().getRecord(propRecord.getId());
        }
        for (PropertyBlock block : propRecord.getPropertyBlocks()) {
            if (block.isLight()) {
                getPropertyStore().makeHeavy(block);
            }
            if (!block.isCreated() && !propRecord.isChanged()) {
                result.put(block.getKeyIndexId(), block.newPropertyData(propRecord, propertyGetValueOrNull(block)));
            }
            // TODO: update count on property index record
            for (DynamicRecord valueRecord : block.getValueRecords()) {
                assert valueRecord.inUse();
                valueRecord.setInUse(false);
                propRecord.addDeletedRecord(valueRecord);
            }
        }
        nextProp = propRecord.getNextProp();
        propRecord.setInUse(false);
        propRecord.setChanged();
        // We do not remove them individually, but all together here
        propRecord.getPropertyBlocks().clear();
    }
    return result;
}
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) PropertyBlock(org.neo4j.kernel.impl.nioneo.store.PropertyBlock) ArrayMap(org.neo4j.kernel.impl.util.ArrayMap)

Example 25 with PropertyData

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

the class WriteTransaction method relDelete.

@Override
public 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.");
    }
    long nextProp = record.getNextProp();
    ArrayMap<Integer, PropertyData> propertyMap = getAndDeletePropertyChain(nextProp);
    disconnectRelationship(record);
    updateNodes(record);
    record.setInUse(false);
    return propertyMap;
}
Also used : PropertyData(org.neo4j.kernel.impl.nioneo.store.PropertyData) RelationshipRecord(org.neo4j.kernel.impl.nioneo.store.RelationshipRecord)

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