Search in sources :

Example 6 with ArrayMap

use of org.neo4j.kernel.impl.util.ArrayMap in project neo4j-mobile-android by neo4j-contrib.

the class NodeImpl method getMoreRelationships.

boolean getMoreRelationships(NodeManager nodeManager) {
    Triplet<ArrayMap<String, RelIdArray>, Map<Long, RelationshipImpl>, Long> rels;
    if (!hasMoreRelationshipsToLoad()) {
        return false;
    }
    synchronized (this) {
        if (!hasMoreRelationshipsToLoad()) {
            return false;
        }
        rels = nodeManager.getMoreRelationships(this);
        ArrayMap<String, RelIdArray> addMap = rels.first();
        if (addMap.size() == 0) {
            return false;
        }
        for (String type : addMap.keySet()) {
            RelIdArray addRels = addMap.get(type);
            // IntArray srcRels = tmpRelMap.get( type );
            RelIdArray srcRels = getRelIdArray(type);
            if (srcRels == null) {
                putRelIdArray(addRels);
            } else {
                RelIdArray newSrcRels = srcRels.addAll(addRels);
                // This can happen if srcRels gets upgraded to a RelIdArrayWithLoops
                if (newSrcRels != srcRels) {
                    putRelIdArray(newSrcRels);
                }
            }
        }
        setRelChainPosition(rels.third());
    }
    nodeManager.putAllInRelCache(rels.second());
    return true;
}
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 7 with ArrayMap

use of org.neo4j.kernel.impl.util.ArrayMap in project neo4j-mobile-android by neo4j-contrib.

the class NodeImpl method getMoreRelationships.

private Triplet<ArrayMap<String, RelIdArray>, Map<Long, RelationshipImpl>, Long> getMoreRelationships(NodeManager nodeManager, ArrayMap<String, RelIdArray> tmpRelMap) {
    if (!hasMoreRelationshipsToLoad()) {
        return null;
    }
    Triplet<ArrayMap<String, RelIdArray>, Map<Long, RelationshipImpl>, Long> rels = nodeManager.getMoreRelationships(this);
    ArrayMap<String, RelIdArray> addMap = rels.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 {
            RelIdArray newSrcRels = srcRels.addAll(addRels);
            // This can happen if srcRels gets upgraded to a RelIdArrayWithLoops
            if (newSrcRels != srcRels) {
                tmpRelMap.put(type, newSrcRels);
            }
        }
    }
    return rels;
// 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 8 with ArrayMap

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

the class WriteTransaction method nodeGetProperties.

ArrayMap<Integer, PropertyData> nodeGetProperties(long nodeId, boolean light) {
    ArrayMap<Integer, PropertyData> propertyMap = new ArrayMap<Integer, PropertyData>(9, false, true);
    NodeRecord nodeRecord = getNodeRecord(nodeId);
    if (nodeRecord != null && nodeRecord.isCreated()) {
        return propertyMap;
    }
    if (nodeRecord != null) {
        if (!nodeRecord.inUse() && !light) {
            throw new IllegalStateException("Node[" + nodeId + "] has been deleted in this tx");
        }
    }
    nodeRecord = getNodeStore().getRecord(nodeId);
    if (!nodeRecord.inUse()) {
        throw new InvalidRecordException("Node[" + nodeId + "] not in use");
    }
    long nextProp = nodeRecord.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 : 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) InvalidRecordException(org.neo4j.kernel.impl.nioneo.store.InvalidRecordException)

Example 9 with ArrayMap

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

the class WriteTransaction method relDelete.

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.");
    }
    ArrayMap<Integer, PropertyData> propertyMap = new ArrayMap<Integer, PropertyData>(9, false, true);
    long nextProp = record.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);
        }
    }
    disconnectRelationship(record);
    updateNodes(record);
    record.setInUse(false);
    return propertyMap;
}
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) RelationshipRecord(org.neo4j.kernel.impl.nioneo.store.RelationshipRecord) ArrayMap(org.neo4j.kernel.impl.util.ArrayMap)

Example 10 with ArrayMap

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

the class NodeImpl method getMoreRelationships.

boolean getMoreRelationships(NodeManager nodeManager) {
    // ArrayMap<String, IntArray> tmpRelMap = relationshipMap;
    Pair<ArrayMap<String, RelIdArray>, Map<Long, RelationshipImpl>> pair;
    synchronized (this) {
        if (!relChainPosition.hasMore()) {
            return false;
        }
        pair = nodeManager.getMoreRelationships(this);
        ArrayMap<String, RelIdArray> addMap = pair.first();
        if (addMap.size() == 0) {
            return false;
        }
        for (String type : addMap.keySet()) {
            RelIdArray addRels = addMap.get(type);
            // IntArray srcRels = tmpRelMap.get( type );
            RelIdArray srcRels = relationshipMap.get(type);
            if (srcRels == null) {
                relationshipMap.put(type, addRels);
            } else {
                srcRels.addAll(addRels);
            }
        }
    }
    nodeManager.putAllInRelCache(pair.other());
    return true;
}
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)

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