Search in sources :

Example 26 with PropertyData

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

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);
                for (RelIdIterator iterator = createdRels.iterator(); iterator.hasNext(); ) {
                    long relId = iterator.next();
                    CowRelElement relElement = element.relationships.get(relId);
                    if (relElement != null && relElement.deleted) {
                        continue;
                    }
                    RelationshipProxy rel = new RelationshipProxy(relId, nodeManager);
                    if (rel.getStartNode().getId() == nodeId) {
                        result.created(new RelationshipProxy(relId, nodeManager));
                    }
                }
            }
        }
        if (nodeElement.relationshipRemoveMap != null) {
            for (String type : nodeElement.relationshipRemoveMap.keySet()) {
                RelIdArray deletedRels = nodeElement.relationshipRemoveMap.get(type);
                for (RelIdIterator iterator = deletedRels.iterator(); iterator.hasNext(); ) {
                    long relId = iterator.next();
                    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.getId());
                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.getId());
                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) RelIdIterator(org.neo4j.kernel.impl.util.RelIdArray.RelIdIterator)

Example 27 with PropertyData

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

the class ReadTransaction method nodeGetProperties.

ArrayMap<Integer, PropertyData> nodeGetProperties(long nodeId) {
    NodeRecord nodeRecord = getNodeStore().getRecord(nodeId);
    long nextProp = nodeRecord.getNextProp();
    ArrayMap<Integer, PropertyData> propertyMap = new ArrayMap<Integer, PropertyData>(9, false, true);
    while (nextProp != Record.NO_NEXT_PROPERTY.intValue()) {
        PropertyRecord propRecord = getPropertyStore().getLightRecord(nextProp);
        propertyMap.put(propRecord.getKeyIndexId(), new PropertyData(propRecord.getId(), propertyGetValueOrNull(propRecord)));
        nextProp = propRecord.getNextProp();
    }
    return propertyMap;
}
Also used : NodeRecord(org.neo4j.kernel.impl.nioneo.store.NodeRecord) PropertyData(org.neo4j.kernel.impl.nioneo.store.PropertyData) PropertyRecord(org.neo4j.kernel.impl.nioneo.store.PropertyRecord) ArrayMap(org.neo4j.kernel.impl.util.ArrayMap)

Example 28 with PropertyData

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

the class ReadTransaction method relGetProperties.

public ArrayMap<Integer, PropertyData> relGetProperties(long relId) {
    RelationshipRecord relRecord = getRelationshipStore().getRecord(relId);
    if (!relRecord.inUse()) {
        throw new InvalidRecordException("Relationship[" + relId + "] not in use");
    }
    long nextProp = relRecord.getNextProp();
    ArrayMap<Integer, PropertyData> propertyMap = new ArrayMap<Integer, PropertyData>(9, false, true);
    while (nextProp != Record.NO_NEXT_PROPERTY.intValue()) {
        PropertyRecord propRecord = getPropertyStore().getLightRecord(nextProp);
        propertyMap.put(propRecord.getKeyIndexId(), new PropertyData(propRecord.getId(), propertyGetValueOrNull(propRecord)));
        nextProp = propRecord.getNextProp();
    }
    return propertyMap;
}
Also used : PropertyData(org.neo4j.kernel.impl.nioneo.store.PropertyData) PropertyRecord(org.neo4j.kernel.impl.nioneo.store.PropertyRecord) RelationshipRecord(org.neo4j.kernel.impl.nioneo.store.RelationshipRecord) ArrayMap(org.neo4j.kernel.impl.util.ArrayMap) InvalidRecordException(org.neo4j.kernel.impl.nioneo.store.InvalidRecordException)

Example 29 with PropertyData

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

the class WriteTransaction method nodeDelete.

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);
    ArrayMap<Integer, PropertyData> propertyMap = new ArrayMap<Integer, PropertyData>(9, false, true);
    long nextProp = nodeRecord.getNextProp();
    while (nextProp != Record.NO_NEXT_PROPERTY.intValue()) {
        PropertyRecord propRecord = getPropertyRecord(nextProp);
        if (propRecord == null) {
            propRecord = getPropertyStore().getRecord(nextProp);
            addPropertyRecord(propRecord);
        }
        if (propRecord.isLight()) {
            getPropertyStore().makeHeavy(propRecord);
        }
        if (!propRecord.isCreated()) {
            if (!propRecord.isChanged()) {
                propertyMap.put(propRecord.getKeyIndexId(), new PropertyData(propRecord.getId(), propertyGetValueOrNull(propRecord)));
            } else {
                // we have to re-read committed value since property has 
                // changed and old value is erased in memory
                PropertyRecord diskValue = getPropertyStore().getRecord(propRecord.getId());
                getPropertyStore().makeHeavy(diskValue);
                propertyMap.put(diskValue.getKeyIndexId(), new PropertyData(diskValue.getId(), propertyGetValueOrNull(diskValue)));
            }
        }
        nextProp = propRecord.getNextProp();
        propRecord.setInUse(false);
        // TODO: update count on property index record
        for (DynamicRecord valueRecord : propRecord.getValueRecords()) {
            valueRecord.setInUse(false);
        }
    }
    return propertyMap;
}
Also used : DynamicRecord(org.neo4j.kernel.impl.nioneo.store.DynamicRecord) NodeRecord(org.neo4j.kernel.impl.nioneo.store.NodeRecord) PropertyData(org.neo4j.kernel.impl.nioneo.store.PropertyData) PropertyRecord(org.neo4j.kernel.impl.nioneo.store.PropertyRecord) ArrayMap(org.neo4j.kernel.impl.util.ArrayMap)

Example 30 with PropertyData

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

the class WriteTransaction method relGetProperties.

public ArrayMap<Integer, PropertyData> relGetProperties(long relId, boolean light) {
    ArrayMap<Integer, PropertyData> propertyMap = new ArrayMap<Integer, PropertyData>(9, false, true);
    RelationshipRecord relRecord = getRelationshipRecord(relId);
    if (relRecord != null && relRecord.isCreated()) {
        return propertyMap;
    }
    if (relRecord != null) {
        if (!relRecord.inUse() && !light) {
            throw new IllegalStateException("Relationship[" + relId + "] has been deleted in this tx");
        }
    }
    relRecord = getRelationshipStore().getRecord(relId);
    if (!relRecord.inUse()) {
        throw new InvalidRecordException("Relationship[" + relId + "] not in use");
    }
    long nextProp = relRecord.getNextProp();
    while (nextProp != Record.NO_NEXT_PROPERTY.intValue()) {
        PropertyRecord propRecord = getPropertyStore().getLightRecord(nextProp);
        propertyMap.put(propRecord.getKeyIndexId(), new PropertyData(propRecord.getId(), propertyGetValueOrNull(propRecord)));
        nextProp = propRecord.getNextProp();
    }
    return propertyMap;
}
Also used : PropertyData(org.neo4j.kernel.impl.nioneo.store.PropertyData) PropertyRecord(org.neo4j.kernel.impl.nioneo.store.PropertyRecord) ArrayMap(org.neo4j.kernel.impl.util.ArrayMap) RelationshipRecord(org.neo4j.kernel.impl.nioneo.store.RelationshipRecord) InvalidRecordException(org.neo4j.kernel.impl.nioneo.store.InvalidRecordException)

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