Search in sources :

Example 11 with PropertyData

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

the class WriteTransaction method nodeDelete.

@Override
public ArrayMap<Integer, PropertyData> nodeDelete(long nodeId) {
    NodeRecord nodeRecord = getNodeRecord(nodeId);
    if (nodeRecord == null) {
        nodeRecord = getNodeStore().getRecord(nodeId);
        addNodeRecord(nodeRecord);
    }
    if (!nodeRecord.inUse()) {
        throw new IllegalStateException("Unable to delete Node[" + nodeId + "] since it has already been deleted.");
    }
    nodeRecord.setInUse(false);
    long nextProp = nodeRecord.getNextProp();
    ArrayMap<Integer, PropertyData> propertyMap = getAndDeletePropertyChain(nextProp);
    return propertyMap;
}
Also used : NodeRecord(org.neo4j.kernel.impl.nioneo.store.NodeRecord) PropertyData(org.neo4j.kernel.impl.nioneo.store.PropertyData)

Example 12 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) 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 = getPropertyForIndex(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 13 with PropertyData

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

the class Primitive method toPropertyArray.

private PropertyData[] toPropertyArray(ArrayMap<Integer, PropertyData> loadedProperties) {
    if (loadedProperties == null || loadedProperties.size() == 0) {
        return NO_PROPERTIES;
    }
    PropertyData[] result = new PropertyData[loadedProperties.size()];
    int i = 0;
    for (PropertyData property : loadedProperties.values()) {
        result[i++] = property;
    }
    return result;
}
Also used : PropertyData(org.neo4j.kernel.impl.nioneo.store.PropertyData)

Example 14 with PropertyData

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

the class RelationshipImpl method delete.

public void delete(NodeManager nodeManager) {
    NodeImpl startNode = null;
    NodeImpl endNode = null;
    boolean startNodeLocked = false;
    boolean endNodeLocked = false;
    boolean thisLocked = false;
    boolean success = false;
    try {
        startNode = nodeManager.getLightNode(getStartNodeId());
        if (startNode != null) {
            nodeManager.acquireLock(startNode, LockType.WRITE);
            startNodeLocked = true;
        }
        endNode = nodeManager.getLightNode(getEndNodeId());
        if (endNode != null) {
            nodeManager.acquireLock(endNode, LockType.WRITE);
            endNodeLocked = true;
        }
        nodeManager.acquireLock(this, LockType.WRITE);
        thisLocked = true;
        // no need to load full relationship, all properties will be
        // deleted when relationship is deleted
        ArrayMap<Integer, PropertyData> skipMap = nodeManager.getCowPropertyRemoveMap(this, true);
        ArrayMap<Integer, PropertyData> removedProps = nodeManager.deleteRelationship(this);
        if (removedProps.size() > 0) {
            for (int index : removedProps.keySet()) {
                skipMap.put(index, removedProps.get(index));
            }
        }
        success = true;
        RelationshipType type = getType(nodeManager);
        long id = getId();
        if (startNode != null) {
            startNode.removeRelationship(nodeManager, type, id);
        }
        if (endNode != null) {
            endNode.removeRelationship(nodeManager, type, id);
        }
        success = true;
    } finally {
        boolean releaseFailed = false;
        try {
            if (thisLocked) {
                nodeManager.releaseLock(this, LockType.WRITE);
            }
        } catch (Exception e) {
            releaseFailed = true;
            e.printStackTrace();
        }
        try {
            if (startNodeLocked) {
                nodeManager.releaseLock(startNode, LockType.WRITE);
            }
        } catch (Exception e) {
            releaseFailed = true;
            e.printStackTrace();
        }
        try {
            if (endNodeLocked) {
                nodeManager.releaseLock(endNode, LockType.WRITE);
            }
        } catch (Exception e) {
            releaseFailed = true;
            e.printStackTrace();
        }
        if (!success) {
            nodeManager.setRollbackOnly();
        }
        if (releaseFailed) {
            throw new LockException("Unable to release locks [" + startNode + "," + endNode + "] in relationship delete->" + this);
        }
    }
}
Also used : PropertyData(org.neo4j.kernel.impl.nioneo.store.PropertyData) LockException(org.neo4j.kernel.impl.transaction.LockException) RelationshipType(org.neo4j.graphdb.RelationshipType) NotFoundException(org.neo4j.graphdb.NotFoundException) LockException(org.neo4j.kernel.impl.transaction.LockException)

Example 15 with PropertyData

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

the class BatchInserterImpl method getPropertyChain.

private Map<String, Object> getPropertyChain(long nextProp) {
    PropertyStore propStore = getPropertyStore();
    Map<String, Object> properties = new HashMap<String, Object>();
    while (nextProp != Record.NO_NEXT_PROPERTY.intValue()) {
        PropertyRecord propRecord = propStore.getRecord(nextProp);
        for (PropertyBlock propBlock : propRecord.getPropertyBlocks()) {
            String key = indexHolder.getStringKey(propBlock.getKeyIndexId());
            PropertyData propertyData = propBlock.newPropertyData(propRecord);
            Object value = propertyData.getValue() != null ? propertyData.getValue() : propBlock.getType().getValue(propBlock, getPropertyStore());
            properties.put(key, value);
        }
        nextProp = propRecord.getNextProp();
    }
    return properties;
}
Also used : PropertyRecord(org.neo4j.kernel.impl.nioneo.store.PropertyRecord) PropertyData(org.neo4j.kernel.impl.nioneo.store.PropertyData) HashMap(java.util.HashMap) PropertyBlock(org.neo4j.kernel.impl.nioneo.store.PropertyBlock) PropertyStore.encodeString(org.neo4j.kernel.impl.nioneo.store.PropertyStore.encodeString) PropertyStore(org.neo4j.kernel.impl.nioneo.store.PropertyStore)

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