Search in sources :

Example 1 with RelIdArray

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

the class LockReleaser method populateCreatedNodes.

private void populateCreatedNodes(PrimitiveElement element, TransactionDataImpl result) {
    RelIdArray createdNodes = nodeManager.getCreatedNodes();
    for (RelIdIterator iterator = createdNodes.iterator(); iterator.hasNext(); ) {
        long nodeId = iterator.next();
        if (element != null && element.nodes != null) {
            CowNodeElement nodeElement = element.nodes.get(nodeId);
            if (nodeElement != null && nodeElement.deleted) {
                continue;
            }
        }
        result.created(new NodeProxy(nodeId, nodeManager));
    }
}
Also used : RelIdArray(org.neo4j.kernel.impl.util.RelIdArray) RelIdIterator(org.neo4j.kernel.impl.util.RelIdArray.RelIdIterator)

Example 2 with RelIdArray

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

the class LockReleaser method getCowRelationshipAddMap.

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

Example 3 with RelIdArray

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

the class NodeImpl method getAllRelationshipsOfType.

List<RelIdIterator> getAllRelationshipsOfType(NodeManager nodeManager, DirectionWrapper direction, RelationshipType... types) {
    ensureRelationshipMapNotNull(nodeManager);
    List<RelIdIterator> relTypeList = new LinkedList<RelIdIterator>();
    boolean hasModifications = nodeManager.getLockReleaser().hasRelationshipModifications(this);
    for (RelationshipType type : types) {
        String typeName = type.name();
        RelIdArray src = getRelIdArray(typeName);
        Collection<Long> remove = null;
        RelIdArray add = null;
        RelIdIterator iterator = null;
        if (hasModifications) {
            remove = nodeManager.getCowRelationshipRemoveMap(this, typeName);
            add = nodeManager.getCowRelationshipAddMap(this, typeName);
            iterator = new CombinedRelIdIterator(typeName, direction, src, add, remove);
        } else {
            iterator = src != null ? src.iterator(direction) : empty(typeName).iterator(direction);
        }
        relTypeList.add(iterator);
    }
    return relTypeList;
}
Also used : RelationshipType(org.neo4j.graphdb.RelationshipType) RelIdArray(org.neo4j.kernel.impl.util.RelIdArray) LinkedList(java.util.LinkedList) CombinedRelIdIterator(org.neo4j.kernel.impl.util.CombinedRelIdIterator) RelIdIterator(org.neo4j.kernel.impl.util.RelIdIterator) CombinedRelIdIterator(org.neo4j.kernel.impl.util.CombinedRelIdIterator)

Example 4 with RelIdArray

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

the class NodeManager method receiveRelationships.

private void receiveRelationships(Iterable<RelationshipRecord> rels, ArrayMap<String, RelIdArray> newRelationshipMap, Map<Long, RelationshipImpl> relsMap, DirectionWrapper dir, boolean hasLoops) {
    for (RelationshipRecord rel : rels) {
        long relId = rel.getId();
        RelationshipImpl relImpl = relCache.get(relId);
        RelationshipType type = null;
        if (relImpl == null) {
            type = getRelationshipTypeById(rel.getType());
            assert type != null;
            relImpl = newRelationshipImpl(relId, rel.getFirstNode(), rel.getSecondNode(), type, rel.getType(), false);
            relsMap.put(relId, relImpl);
        // relCache.put( relId, relImpl );
        } else {
            type = relImpl.getType(this);
        }
        RelIdArray relationshipSet = newRelationshipMap.get(type.name());
        if (relationshipSet == null) {
            relationshipSet = hasLoops ? new RelIdArrayWithLoops(type.name()) : new RelIdArray(type.name());
            newRelationshipMap.put(type.name(), relationshipSet);
        }
        relationshipSet.add(relId, dir);
    }
}
Also used : RelIdArrayWithLoops(org.neo4j.kernel.impl.util.RelIdArrayWithLoops) RelationshipType(org.neo4j.graphdb.RelationshipType) RelationshipRecord(org.neo4j.kernel.impl.nioneo.store.RelationshipRecord) RelIdArray(org.neo4j.kernel.impl.util.RelIdArray)

Example 5 with RelIdArray

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

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);
                populateNodeRelEvent(element, result, nodeId, createdRels);
            }
        }
        if (nodeElement.relationshipRemoveMap != null) {
            for (String type : nodeElement.relationshipRemoveMap.keySet()) {
                Collection<Long> deletedRels = nodeElement.relationshipRemoveMap.get(type);
                for (long relId : deletedRels) {
                    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);
                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);
                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)

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