Search in sources :

Example 11 with RelIdArray

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

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

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

the class NodeImpl method commitRelationshipMaps.

protected void commitRelationshipMaps(ArrayMap<String, RelIdArray> cowRelationshipAddMap, ArrayMap<String, Collection<Long>> cowRelationshipRemoveMap) {
    if (relationships == null) {
        // we will load full in some other tx
        return;
    }
    synchronized (this) {
        if (cowRelationshipAddMap != null) {
            for (String type : cowRelationshipAddMap.keySet()) {
                RelIdArray add = cowRelationshipAddMap.get(type);
                Collection<Long> remove = null;
                if (cowRelationshipRemoveMap != null) {
                    remove = cowRelationshipRemoveMap.get(type);
                }
                RelIdArray src = getRelIdArray(type);
                putRelIdArray(RelIdArray.from(src, add, remove));
            }
        }
        if (cowRelationshipRemoveMap != null) {
            for (String type : cowRelationshipRemoveMap.keySet()) {
                if (cowRelationshipAddMap != null && cowRelationshipAddMap.get(type) != null) {
                    continue;
                }
                RelIdArray src = getRelIdArray(type);
                if (src != null) {
                    Collection<Long> remove = cowRelationshipRemoveMap.get(type);
                    putRelIdArray(RelIdArray.from(src, null, remove));
                }
            }
        }
    }
}
Also used : RelIdArray(org.neo4j.kernel.impl.util.RelIdArray)

Example 14 with RelIdArray

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

the class LockReleaser method getCowRelationshipAddMap.

public RelIdArray getCowRelationshipAddMap(NodeImpl node, String type, boolean create) {
    PrimitiveElement primitiveElement = getAndSetupPrimitiveElement();
    ArrayMap<Long, CowNodeElement> cowElements = primitiveElement.nodes;
    CowNodeElement element = cowElements.get(node.getId());
    if (element == null) {
        element = new CowNodeElement();
        cowElements.put(node.getId(), element);
    }
    if (element.relationshipAddMap == null) {
        element.relationshipAddMap = new ArrayMap<String, RelIdArray>();
    }
    RelIdArray set = element.relationshipAddMap.get(type);
    if (set == null) {
        set = new RelIdArrayWithLoops(type);
        element.relationshipAddMap.put(type, set);
    }
    return set;
}
Also used : RelIdArrayWithLoops(org.neo4j.kernel.impl.util.RelIdArrayWithLoops) RelIdArray(org.neo4j.kernel.impl.util.RelIdArray)

Example 15 with RelIdArray

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

the class NodeImpl method addRelationship.

// caller is responsible for acquiring lock
// this method is only called when a relationship is created or
// a relationship delete is undone or when the full node is loaded
void addRelationship(NodeManager nodeManager, RelationshipType type, long relId, DirectionWrapper dir) {
    RelIdArray relationshipSet = nodeManager.getCowRelationshipAddMap(this, type.name(), true);
    relationshipSet.add(relId, dir);
}
Also used : RelIdArray(org.neo4j.kernel.impl.util.RelIdArray)

Aggregations

RelIdArray (org.neo4j.kernel.impl.util.RelIdArray)26 ArrayMap (org.neo4j.kernel.impl.util.ArrayMap)5 LinkedList (java.util.LinkedList)4 Map (java.util.Map)4 RelationshipType (org.neo4j.graphdb.RelationshipType)4 Test (org.junit.Test)3 RelIdIterator (org.neo4j.kernel.impl.util.RelIdArray.RelIdIterator)3 RelIdIterator (org.neo4j.kernel.impl.util.RelIdIterator)3 PropertyData (org.neo4j.kernel.impl.nioneo.store.PropertyData)2 CombinedRelIdIterator (org.neo4j.kernel.impl.util.CombinedRelIdIterator)2 RelIdArrayWithLoops (org.neo4j.kernel.impl.util.RelIdArrayWithLoops)2 HashMap (java.util.HashMap)1 RelationshipChainPosition (org.neo4j.kernel.impl.nioneo.store.RelationshipChainPosition)1 RelationshipData (org.neo4j.kernel.impl.nioneo.store.RelationshipData)1 RelationshipRecord (org.neo4j.kernel.impl.nioneo.store.RelationshipRecord)1