@Override protected void recursivelyMarkAsRemoved(NodeSPI node, InvocationContext ctx) { node.markAsDeleted(true, true); }
@Override public void markAsRemoved(boolean marker, boolean recursive) { setFlag(NodeFlags.REMOVED, marker); if (recursive && children != null) { synchronized (this) { for (Object child : children.values()) { ((NodeSPI) child).markAsDeleted(marker, true); } } } if (marker) { if (childrenAdded != null) childrenAdded.clear(); if (childrenRemoved != null) childrenRemoved.clear(); } }
/** * Recursively marks a node as removed. * * @param node Node to mark * @param ctx Invocation context */ protected void recursivelyMarkAsRemoved(NodeSPI node, InvocationContext ctx) { node.markAsDeleted(true); Fqn parentFqn = node.getFqn(); // recursion has to happen like this since child nodes are in the ctx. Map<Fqn, NodeSPI> nodes = ctx.getLookedUpNodes(); for (Map.Entry<Fqn, NodeSPI> entry : nodes.entrySet()) { if (entry.getKey().isChildOf(parentFqn)) entry.getValue().markAsDeleted(true); } }
@Override public void markAsRemoved(boolean marker, boolean recursive) { setFlag(NodeFlags.REMOVED, marker); if (recursive && children != null) { synchronized (this) { for (Node<?, ?> child : children().values()) { ((NodeSPI) child).markAsDeleted(marker, true); } } } }
public void rollback() { if (targetNode != null) { Object childName = targetNode.getFqn().getLastElement(); if (trace) { log.trace("rollback(parent: " + parentFqn + ", child: " + childName + ", node=" + targetNode + ")"); } if (parentFqn == null || childName == null) { log.error("parent fqn or childName or childNode was null"); return; } NodeSPI parentNode = dataContainer.peek(parentFqn); if (parentNode == null) { log.warn("node " + parentFqn + " not found"); return; } parentNode.addChild(childName, targetNode); targetNode.markAsDeleted(false, true); targetNode.clearDataDirect(); if (originalData != null) targetNode.putAllDirect(originalData); targetNode.setValid(true, true); } } }
/** * Test if this node needs to be 'undeleted' * reverse the "remove" if the node has been previously removed in the same tx, if this operation is a put() */ public static void manageReverseRemove(InvocationContext ctx, NodeSPI childNode, boolean reverseRemoveCheck, List createdNodes, CommandsFactory commandsFactory) { if (ctx.getGlobalTransaction() != null) //if no tx then reverse remove does not make sense { Fqn fqn = childNode.getFqn(); TransactionContext transactionContext = ctx.getTransactionContext(); boolean needToReverseRemove = reverseRemoveCheck && childNode.isDeleted() && transactionContext != null && transactionContext.getRemovedNodes().contains(fqn); if (!needToReverseRemove) return; childNode.markAsDeleted(false); //if we'll rollback the tx data should be added to the node again Map oldData = new HashMap(childNode.getDataDirect()); PutDataMapCommand command = commandsFactory.buildPutDataMapCommand(ctx.getGlobalTransaction(), fqn, oldData); // txTable.get(gtx).addUndoOperation(command); --- now need to make sure this is added to the normal mods list instead transactionContext.addModification(command); //we're prepared for rollback, now reset the node childNode.clearDataDirect(); if (createdNodes != null) { createdNodes.add(childNode); } } } }
@SuppressWarnings("unchecked") private void moveRecursively(NodeSPI oldNode, NodeSPI newNode, InvocationContext ctx) { if (trace) log.trace("Moving " + oldNode.getFqn() + " to " + newNode.getFqn()); // start deep. Map<Object, InternalNode> children = oldNode.getDelegationTarget().getChildrenMap(); if (!children.isEmpty()) { for (InternalNode child : children.values()) { Fqn childFqn = child.getFqn(); Fqn newChildFqn = childFqn.replaceAncestor(oldNode.getFqn(), newNode.getFqn()); moveRecursively(ctx.lookUpNode(childFqn), ctx.lookUpNode(newChildFqn), ctx); } } // now swap the data for the current node. newNode.getDelegationTarget().putAll(oldNode.getDelegationTarget().getData()); oldNode.markAsDeleted(true); }
node.markAsDeleted(true); return true;
nodeSPI.markAsDeleted(true);
node.markAsDeleted(true); node.setDataLoaded(false); node.getDelegationTarget().clear();