protected void commitRelationshipMaps( ArrayMap<String, IntArray> cowRelationshipAddMap, ArrayMap<String, IntArray> cowRelationshipRemoveMap) { if (relationshipMap == null) { // we will load full in some other tx return; } if (cowRelationshipAddMap != null) { for (String type : cowRelationshipAddMap.keySet()) { IntArray add = cowRelationshipAddMap.get(type); IntArray remove = null; if (cowRelationshipRemoveMap != null) { remove = cowRelationshipRemoveMap.get(type); } IntArray src = relationshipMap.get(type); relationshipMap.put(type, IntArray.composeNew(src, add, remove)); } } if (cowRelationshipRemoveMap != null) { for (String type : cowRelationshipRemoveMap.keySet()) { if (cowRelationshipAddMap != null && cowRelationshipAddMap.get(type) != null) { continue; } IntArray src = relationshipMap.get(type); IntArray remove = cowRelationshipRemoveMap.get(type); relationshipMap.put(type, IntArray.composeNew(src, null, remove)); } } }
boolean getMoreRelationships(NodeManager nodeManager) { // ArrayMap<String, IntArray> tmpRelMap = relationshipMap; Pair<ArrayMap<String, IntArray>, Map<Integer, RelationshipImpl>> pair; synchronized (this) { if (!relChainPosition.hasMore()) { return false; } pair = nodeManager.getMoreRelationships(this); ArrayMap<String, IntArray> addMap = pair.first(); if (addMap.size() == 0) { return false; } for (String type : addMap.keySet()) { IntArray addRels = addMap.get(type); // IntArray srcRels = tmpRelMap.get( type ); IntArray srcRels = relationshipMap.get(type); if (srcRels == null) { relationshipMap.put(type, addRels); } else { srcRels.addAll(addRels); } } } nodeManager.putAllInRelCache(pair.other()); return true; }
ArrayMap<String, IntArray> getMoreRelationships(NodeImpl node) { int nodeId = (int) node.getId(); RelationshipChainPosition position = node.getRelChainPosition(); Iterable<RelationshipData> rels = persistenceManager.getMoreRelationships(nodeId, position); ArrayMap<String, IntArray> newRelationshipMap = new ArrayMap<String, IntArray>(); for (RelationshipData rel : rels) { int 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, this); relCache.put(relId, relImpl); } else { type = relImpl.getType(); } IntArray relationshipSet = newRelationshipMap.get(type.name()); if (relationshipSet == null) { relationshipSet = new IntArray(); newRelationshipMap.put(type.name(), relationshipSet); } relationshipSet.add(relId); } return newRelationshipMap; }
private Map<Integer, RelationshipImpl> getMoreRelationships( NodeManager nodeManager, ArrayMap<String, IntArray> tmpRelMap) { if (!relChainPosition.hasMore()) { return null; } Pair<ArrayMap<String, IntArray>, Map<Integer, RelationshipImpl>> pair = nodeManager.getMoreRelationships(this); ArrayMap<String, IntArray> addMap = pair.first(); if (addMap.size() == 0) { return null; } for (String type : addMap.keySet()) { IntArray addRels = addMap.get(type); IntArray srcRels = tmpRelMap.get(type); if (srcRels == null) { tmpRelMap.put(type, addRels); } else { srcRels.addAll(addRels); } } return pair.other(); // nodeManager.putAllInRelCache( pair.other() ); }
// caller is responsible for acquiring lock // this method is only called when a undo create relationship or // a relationship delete is invoked. void removeRelationship(NodeManager nodeManager, RelationshipType type, int relId) { IntArray relationshipSet = nodeManager.getCowRelationshipRemoveMap(this, type.name(), true); relationshipSet.add(relId); }