private void removeDataAndNotify(TransactionWorkspace workspace, WorkspaceNode workspaceNode, InvocationContext ctx) { if (workspaceNode == null) return; Map data = new HashMap(workspaceNode.getData()); // pre-notify notifier.notifyNodeModified(workspaceNode.getFqn(), true, REMOVE_DATA, data, ctx); workspaceNode.clearData(); workspace.addNode(workspaceNode); // post-notify notifier.notifyNodeModified(workspaceNode.getFqn(), false, REMOVE_DATA, data, ctx); }
@Override public Object visitGetKeysCommand(InvocationContext ctx, GetKeysCommand command) throws Throwable { TransactionWorkspace workspace = getTransactionWorkspace(ctx); Object result; Fqn fqn = command.getFqn(); WorkspaceNode workspaceNode = fetchWorkspaceNode(ctx, fqn, workspace, false, false); if (workspaceNode == null) { if (trace) log.trace("unable to find node " + fqn + " in workspace."); result = null; } else { notifier.notifyNodeVisited(fqn, true, ctx); Object keySet = workspaceNode.getKeys(); workspace.addNode(workspaceNode); notifier.notifyNodeVisited(fqn, false, ctx); result = keySet; } return result; }
private Object removeKeyAndNotify(Object removeKey, TransactionWorkspace workspace, WorkspaceNode workspaceNode, InvocationContext ctx) { if (workspaceNode == null) return null; if (notifier.shouldNotifyOnNodeModified())// pre-notify { notifier.notifyNodeModified(workspaceNode.getFqn(), true, REMOVE_DATA, workspaceNode.getData(), ctx); } Object old = workspaceNode.remove(removeKey); workspace.addNode(workspaceNode); if (notifier.shouldNotifyOnNodeModified()) { Map removedData = Collections.singletonMap(removeKey, old); // post-notify notifier.notifyNodeModified(workspaceNode.getFqn(), false, REMOVE_DATA, removedData, ctx); } return old; }
private Object putDataKeyValueAndNotify(Object key, Object value, TransactionWorkspace workspace, WorkspaceNode workspaceNode, InvocationContext ctx) { if (workspaceNode == null) throw new NodeNotExistsException("optimisticCreateIfNotExistsInterceptor should have created this node!"); if (notifier.shouldNotifyOnNodeModified())// pre-notify { notifier.notifyNodeModified(workspaceNode.getFqn(), true, PUT_DATA, workspaceNode.getData(), ctx); } Object old = workspaceNode.put(key, value); workspace.addNode(workspaceNode); if (notifier.shouldNotifyOnNodeModified())// post-notify { Map addedData = Collections.singletonMap(key, value); notifier.notifyNodeModified(workspaceNode.getFqn(), false, PUT_DATA, addedData, ctx); } return old; }
private void putDataMapAndNotify(Map<Object, Object> data, TransactionWorkspace workspace, WorkspaceNode workspaceNode, InvocationContext ctx) { if (workspaceNode == null) throw new NodeNotExistsException("optimisticCreateIfNotExistsInterceptor should have created this node!"); // pre-notify notifier.notifyNodeModified(workspaceNode.getFqn(), true, PUT_MAP, workspaceNode.getData(), ctx); workspaceNode.putAll(data); workspace.addNode(workspaceNode); // post-notify notifier.notifyNodeModified(workspaceNode.getFqn(), false, PUT_MAP, workspaceNode.getData(), ctx); }
@Override public Object visitGetChildrenNamesCommand(InvocationContext ctx, GetChildrenNamesCommand command) throws Throwable { TransactionWorkspace workspace = getTransactionWorkspace(ctx); Object result; WorkspaceNode workspaceNode = fetchWorkspaceNode(ctx, command.getFqn(), workspace, false, false); if (workspaceNode == null) { if (trace) log.trace("Unable to find node " + command.getFqn() + " in workspace."); result = null; } else { notifier.notifyNodeVisited(command.getFqn(), true, ctx); Object nameSet = workspaceNode.getChildrenNames(); workspace.addNode(workspaceNode); notifier.notifyNodeVisited(command.getFqn(), false, ctx); result = nameSet; } return result; }
@Override public Object visitGetNodeCommand(InvocationContext ctx, GetNodeCommand command) throws Throwable { TransactionWorkspace workspace = getTransactionWorkspace(ctx); Object result; WorkspaceNode workspaceNode = fetchWorkspaceNode(ctx, command.getFqn(), workspace, false, false); if (workspaceNode == null) { if (trace) log.trace("Unable to find node " + command.getFqn() + " in workspace."); result = null; } else if (workspaceNode.isRemoved()) { if (trace) log.trace("Attempted to retrieve node " + command.getFqn() + " but it has been deleted!"); result = null; } else { notifier.notifyNodeVisited(command.getFqn(), true, ctx); workspace.addNode(workspaceNode); notifier.notifyNodeVisited(command.getFqn(), false, ctx); result = workspaceNode.getNode(); } return result; }
@Override public Object visitGetDataMapCommand(InvocationContext ctx, GetDataMapCommand command) throws Throwable { TransactionWorkspace workspace = getTransactionWorkspace(ctx); Object result; WorkspaceNode workspaceNode = fetchWorkspaceNode(ctx, command.getFqn(), workspace, false, false); if (workspaceNode == null) { if (trace) log.trace("unable to find node " + command.getFqn() + " in workspace."); result = null; } else { notifier.notifyNodeVisited(command.getFqn(), true, ctx); Object data = workspaceNode.getData(); workspace.addNode(workspaceNode); notifier.notifyNodeVisited(command.getFqn(), false, ctx); result = data; } return result; }
@Override public Object visitGetKeyValueCommand(InvocationContext ctx, GetKeyValueCommand command) throws Throwable { TransactionWorkspace workspace = getTransactionWorkspace(ctx); Object result; WorkspaceNode workspaceNode = fetchWorkspaceNode(ctx, command.getFqn(), workspace, false, false); if (workspaceNode == null) { if (trace) log.debug("Unable to find node " + command.getFqn() + " in workspace."); result = null; } else { //add this node into the wrokspace notifier.notifyNodeVisited(command.getFqn(), true, ctx); Object val = workspaceNode.get(command.getKey()); workspace.addNode(workspaceNode); notifier.notifyNodeVisited(command.getFqn(), false, ctx); result = val; } return result; }
workspace.addNode(workspaceNode); log.debug("Created root node in workspace."); workspace.addNode(workspaceNode); if (!(workspaceNode.getVersion() instanceof DefaultDataVersion)) workspaceNode.setVersioningImplicit(false); workspace.addNode(workspaceNode); workspaceNode.markAsCreated(); workspace.addNode(workspaceNode);
workspace.addNode(workspaceNode);