Exemplo n.º 1
0
 List<RelTypeElementIterator> getAllRelationships(NodeManager nodeManager) {
   ensureRelationshipMapNotNull(nodeManager);
   List<RelTypeElementIterator> relTypeList = new LinkedList<RelTypeElementIterator>();
   boolean hasModifications = nodeManager.getLockReleaser().hasRelationshipModifications(this);
   ArrayMap<String, RelIdArray> addMap = null;
   if (hasModifications) {
     addMap = nodeManager.getCowRelationshipAddMap(this);
   }
   for (String type : relationshipMap.keySet()) {
     RelIdArray src = relationshipMap.get(type);
     RelIdArray remove = null;
     RelIdArray add = null;
     if (hasModifications) {
       remove = nodeManager.getCowRelationshipRemoveMap(this, type);
       if (addMap != null) {
         add = addMap.get(type);
       }
     }
     //            if ( src != null || add != null )
     //            {
     relTypeList.add(RelTypeElement.create(type, this, src, add, remove));
     //            }
   }
   if (addMap != null) {
     for (String type : addMap.keySet()) {
       if (relationshipMap.get(type) == null) {
         RelIdArray remove = nodeManager.getCowRelationshipRemoveMap(this, type);
         RelIdArray add = addMap.get(type);
         relTypeList.add(RelTypeElement.create(type, this, null, add, remove));
       }
     }
   }
   return relTypeList;
 }
 List<RelTypeElementIterator> getAllRelationships(NodeManager nodeManager) {
   ensureRelationshipMapNotNull(nodeManager);
   List<RelTypeElementIterator> relTypeList = new LinkedList<RelTypeElementIterator>();
   ArrayMap<String, IntArray> addMap = nodeManager.getCowRelationshipAddMap(this);
   for (String type : relationshipMap.keySet()) {
     IntArray src = relationshipMap.get(type);
     IntArray remove = nodeManager.getCowRelationshipRemoveMap(this, type);
     IntArray add = null;
     if (addMap != null) {
       add = addMap.get(type);
     }
     if (src != null || add != null) {
       relTypeList.add(RelTypeElement.create(type, this, src, add, remove));
     }
   }
   if (addMap != null) {
     for (String type : addMap.keySet()) {
       if (relationshipMap.get(type) == null) {
         IntArray remove = nodeManager.getCowRelationshipRemoveMap(this, type);
         IntArray add = addMap.get(type);
         relTypeList.add(RelTypeElement.create(type, this, null, add, remove));
       }
     }
   }
   return relTypeList;
 }
Exemplo n.º 3
0
 protected void commitRelationshipMaps(
     ArrayMap<String, RelIdArray> cowRelationshipAddMap,
     ArrayMap<String, RelIdArray> cowRelationshipRemoveMap) {
   if (relationshipMap == null) {
     // we will load full in some other tx
     return;
   }
   if (cowRelationshipAddMap != null) {
     for (String type : cowRelationshipAddMap.keySet()) {
       RelIdArray add = cowRelationshipAddMap.get(type);
       RelIdArray remove = null;
       if (cowRelationshipRemoveMap != null) {
         remove = cowRelationshipRemoveMap.get(type);
       }
       RelIdArray src = relationshipMap.get(type);
       relationshipMap.put(type, RelIdArray.from(src, add, remove));
     }
   }
   if (cowRelationshipRemoveMap != null) {
     for (String type : cowRelationshipRemoveMap.keySet()) {
       if (cowRelationshipAddMap != null && cowRelationshipAddMap.get(type) != null) {
         continue;
       }
       RelIdArray src = relationshipMap.get(type);
       RelIdArray remove = cowRelationshipRemoveMap.get(type);
       relationshipMap.put(type, RelIdArray.from(src, null, remove));
     }
   }
 }
Exemplo n.º 4
0
  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;
  }
Exemplo n.º 5
0
 public void delete(NodeManager nodeManager) {
   nodeManager.acquireLock(this, LockType.WRITE);
   boolean success = false;
   try {
     ArrayMap<Integer, PropertyData> skipMap = nodeManager.getCowPropertyRemoveMap(this, true);
     ArrayMap<Integer, PropertyData> removedProps = nodeManager.deleteNode(this);
     if (removedProps.size() > 0) {
       for (int index : removedProps.keySet()) {
         skipMap.put(index, removedProps.get(index));
       }
     }
     success = true;
   } finally {
     nodeManager.releaseLock(this, LockType.WRITE);
     if (!success) {
       nodeManager.setRollbackOnly();
     }
   }
 }
Exemplo n.º 6
0
 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() );
 }
 synchronized void dumpStack() {
   System.out.print("Waiting list: ");
   Iterator<Transaction> transactions = waitingTxMap.keySet().iterator();
   if (!transactions.hasNext()) {
     System.out.println("No transactions waiting on resources");
   } else {
     System.out.println();
   }
   while (transactions.hasNext()) {
     Transaction tx = transactions.next();
     System.out.println("" + tx + "->" + waitingTxMap.get(tx));
   }
   System.out.print("Resource lock list: ");
   Iterator<?> resources = resourceMap.keySet().iterator();
   if (!resources.hasNext()) {
     System.out.println("No locked resources found");
   } else {
     System.out.println();
   }
   while (resources.hasNext()) {
     Object resource = resources.next();
     System.out.print("" + resource + "->");
     Iterator<Transaction> itr = resourceMap.get(resource).iterator();
     if (!itr.hasNext()) {
       System.out.println(" Error empty list found");
     }
     while (itr.hasNext()) {
       System.out.print("" + itr.next());
       if (itr.hasNext()) {
         System.out.print(",");
       } else {
         System.out.println();
       }
     }
   }
 }
  public void delete() {
    NodeImpl startNode = null;
    NodeImpl endNode = null;
    boolean startNodeLocked = false;
    boolean endNodeLocked = false;
    nodeManager.acquireLock(this, LockType.WRITE);
    boolean success = false;
    try {
      startNode = nodeManager.getLightNode(startNodeId);
      if (startNode != null) {
        nodeManager.acquireLock(startNode, LockType.WRITE);
        startNodeLocked = true;
      }
      endNode = nodeManager.getLightNode(endNodeId);
      if (endNode != null) {
        nodeManager.acquireLock(endNode, LockType.WRITE);
        endNodeLocked = true;
      }
      // no need to load full relationship, all properties will be
      // deleted when relationship is deleted

      ArrayMap<Integer, PropertyData> skipMap = nodeManager.getCowPropertyRemoveMap(this, true);
      ArrayMap<Integer, PropertyData> removedProps = nodeManager.deleteRelationship(this);
      if (removedProps.size() > 0) {
        for (int index : removedProps.keySet()) {
          skipMap.put(index, removedProps.get(index));
        }
      }
      success = true;
      if (startNode != null) {
        startNode.removeRelationship(type, id);
      }
      if (endNode != null) {
        endNode.removeRelationship(type, id);
      }
      success = true;
    } finally {
      boolean releaseFailed = false;
      try {
        if (startNodeLocked) {
          nodeManager.releaseLock(startNode, LockType.WRITE);
        }
      } catch (Exception e) {
        releaseFailed = true;
        e.printStackTrace();
      }
      try {
        if (endNodeLocked) {
          nodeManager.releaseLock(endNode, LockType.WRITE);
        }
      } catch (Exception e) {
        releaseFailed = true;
        e.printStackTrace();
      }
      nodeManager.releaseLock(this, LockType.WRITE);
      if (!success) {
        setRollbackOnly();
      }
      if (releaseFailed) {
        throw new LockException(
            "Unable to release locks ["
                + startNode
                + ","
                + endNode
                + "] in relationship delete->"
                + this);
      }
    }
  }