Search in sources :

Example 11 with ArrayMap

use of org.neo4j.kernel.impl.util.ArrayMap 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 12 with ArrayMap

use of org.neo4j.kernel.impl.util.ArrayMap 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 13 with ArrayMap

use of org.neo4j.kernel.impl.util.ArrayMap 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 14 with ArrayMap

use of org.neo4j.kernel.impl.util.ArrayMap in project graphdb by neo4j-attic.

the class NodeImpl method getMoreRelationships.

private Map<Long, RelationshipImpl> getMoreRelationships(NodeManager nodeManager, ArrayMap<String, RelIdArray> tmpRelMap) {
    if (!relChainPosition.hasMore()) {
        return null;
    }
    Pair<ArrayMap<String, RelIdArray>, Map<Long, RelationshipImpl>> pair = nodeManager.getMoreRelationships(this);
    ArrayMap<String, RelIdArray> addMap = pair.first();
    if (addMap.size() == 0) {
        return null;
    }
    for (String type : addMap.keySet()) {
        RelIdArray addRels = addMap.get(type);
        RelIdArray srcRels = tmpRelMap.get(type);
        if (srcRels == null) {
            tmpRelMap.put(type, addRels);
        } else {
            srcRels.addAll(addRels);
        }
    }
    return pair.other();
// nodeManager.putAllInRelCache( pair.other() );
}
Also used : ArrayMap(org.neo4j.kernel.impl.util.ArrayMap) RelIdArray(org.neo4j.kernel.impl.util.RelIdArray) Map(java.util.Map) ArrayMap(org.neo4j.kernel.impl.util.ArrayMap)

Example 15 with ArrayMap

use of org.neo4j.kernel.impl.util.ArrayMap in project graphdb by neo4j-attic.

the class NodeManager method getMoreRelationships.

Pair<ArrayMap<String, RelIdArray>, Map<Long, RelationshipImpl>> getMoreRelationships(NodeImpl node) {
    long nodeId = node.getId();
    RelationshipChainPosition position = node.getRelChainPosition();
    Iterable<RelationshipData> rels = persistenceManager.getMoreRelationships(nodeId, position);
    ArrayMap<String, RelIdArray> newRelationshipMap = new ArrayMap<String, RelIdArray>();
    Map<Long, RelationshipImpl> relsMap = new HashMap<Long, RelationshipImpl>(150);
    for (RelationshipData rel : rels) {
        long relId = rel.getId();
        RelationshipImpl relImpl = relCache.get(relId);
        RelationshipType type = null;
        if (relImpl == null) {
            type = getRelationshipTypeById(rel.relationshipType());
            assert type != null;
            relImpl = new RelationshipImpl(relId, rel.firstNode(), rel.secondNode(), type, false);
            relsMap.put(relId, relImpl);
        // relCache.put( relId, relImpl );
        } else {
            type = relImpl.getType();
        }
        RelIdArray relationshipSet = newRelationshipMap.get(type.name());
        if (relationshipSet == null) {
            relationshipSet = new RelIdArray();
            newRelationshipMap.put(type.name(), relationshipSet);
        }
        relationshipSet.add(relId);
    }
    // relCache.putAll( relsMap );
    return Pair.of(newRelationshipMap, relsMap);
}
Also used : RelationshipChainPosition(org.neo4j.kernel.impl.nioneo.store.RelationshipChainPosition) HashMap(java.util.HashMap) RelationshipType(org.neo4j.graphdb.RelationshipType) ArrayMap(org.neo4j.kernel.impl.util.ArrayMap) RelationshipData(org.neo4j.kernel.impl.nioneo.store.RelationshipData) RelIdArray(org.neo4j.kernel.impl.util.RelIdArray)

Aggregations

ArrayMap (org.neo4j.kernel.impl.util.ArrayMap)20 IOException (java.io.IOException)8 InterruptedIOException (java.io.InterruptedIOException)8 Pair (org.neo4j.helpers.collection.Pair)8 DefinedProperty (org.neo4j.kernel.api.properties.DefinedProperty)8 PropertyBlock (org.neo4j.kernel.impl.store.record.PropertyBlock)8 PropertyRecord (org.neo4j.kernel.impl.store.record.PropertyRecord)8 PropertyData (org.neo4j.kernel.impl.nioneo.store.PropertyData)7 PropertyRecord (org.neo4j.kernel.impl.nioneo.store.PropertyRecord)7 RelIdArray (org.neo4j.kernel.impl.util.RelIdArray)5 Map (java.util.Map)4 DynamicRecord (org.neo4j.kernel.impl.nioneo.store.DynamicRecord)3 InvalidRecordException (org.neo4j.kernel.impl.nioneo.store.InvalidRecordException)3 NodeRecord (org.neo4j.kernel.impl.nioneo.store.NodeRecord)3 RelationshipRecord (org.neo4j.kernel.impl.nioneo.store.RelationshipRecord)3 HashMap (java.util.HashMap)1 RelationshipType (org.neo4j.graphdb.RelationshipType)1 KernelStatement (org.neo4j.kernel.impl.api.KernelStatement)1 PropertyBlock (org.neo4j.kernel.impl.nioneo.store.PropertyBlock)1 RelationshipChainPosition (org.neo4j.kernel.impl.nioneo.store.RelationshipChainPosition)1