/** * Executes a transaction on the current data of this model. This method is * called if an operation is to be executed on the model's root node or a * tracked node which is not yet detached. * * @param txInit the {@code TransactionInitializer} * @param selector an optional {@code NodeSelector} defining the target node * @param currentData the current data of the model * @param resolver the {@code NodeKeyResolver} * @return a flag whether the operation has been completed successfully */ private boolean executeTransactionOnCurrentStructure( final TransactionInitializer txInit, final NodeSelector selector, final TreeData currentData, final NodeKeyResolver<ImmutableNode> resolver) { boolean done; final ModelTransaction tx = new ModelTransaction(currentData, selector, resolver); if (!txInit.initTransaction(tx)) { done = true; } else { final TreeData newData = tx.execute(); done = structure.compareAndSet(tx.getCurrentData(), newData); } return done; }
/** * Adds an operation for clearing the value of a target node. * * @param target the target node */ public void addClearNodeValueOperation(final ImmutableNode target) { addChangeNodeValueOperation(target, null); }
@Override public boolean initTransaction(final ModelTransaction tx) final TreeData current = tx.getCurrentData(); final String newRootName = determineRootName(current.getRootNode(), node, rootName); if (newRootName != null) tx.addChangeNodeNameOperation(current.getRootNode(), newRootName); tx.addAddNodesOperation(current.getRootNode(), node.getChildren()); tx.addAttributesOperation(current.getRootNode(), node.getAttributes()); if (node.getValue() != null) tx.addChangeNodeValueOperation(current.getRootNode(), node.getValue()); tx.addNewReferences(references); tx.addNewReference(current.getRootNode(), rootRef);
resolver.resolveKey(tx.getQueryRoot(), key, tx.getCurrentData()); if (results.size() == 1) tx.addAddNodesOperation(results.get(0).getNode(), nodes); resolver.resolveAddKey(tx.getQueryRoot(), key, tx.getCurrentData()); if (addData.isAttribute())
final ModelTransaction tx = new ModelTransaction(current, null, resolver); tx.addAddNodeOperation(parent, child); newData = updateDataWithNewTrackedNode(tx.execute(), child, resolver, refSelector);
/** * Initializes a transaction to change the values of some query results * based on the passed in map. * * @param tx the transaction to be initialized * @param changedValues the map defining the elements to be changed * @return a flag whether there are elements to be updated */ private static boolean initializeUpdateTransaction(final ModelTransaction tx, final Map<QueryResult<ImmutableNode>, Object> changedValues) { for (final Map.Entry<QueryResult<ImmutableNode>, Object> e : changedValues .entrySet()) { if (e.getKey().isAttributeResult()) { tx.addAttributeOperation(e.getKey().getNode(), e.getKey() .getAttributeName(), e.getValue()); } else { tx.addChangeNodeValueOperation(e.getKey().getNode(), e.getValue()); } } return !changedValues.isEmpty(); }
/** * Initializes a transaction to add a collection of nodes as described by a * {@code NodeAddData} object. If necessary, new path nodes are created. * Eventually, the new nodes are added as children to the specified target * node. * * @param tx the transaction * @param addData the {@code NodeAddData} * @param newNodes the collection of new child nodes */ private static void addNodesByAddData(final ModelTransaction tx, final NodeAddData<ImmutableNode> addData, final Collection<ImmutableNode> newNodes) { if (addData.getPathNodes().isEmpty()) { tx.addAddNodesOperation(addData.getParent(), newNodes); } else { final ImmutableNode newChild = createNodeToAddWithPath(addData, newNodes); tx.addAddNodeOperation(addData.getParent(), newChild); } }
/** * Initializes a transaction to clear the values of a property based on the * passed in collection of affected results. * * @param tx the transaction to be initialized * @param results a collection with results pointing to the nodes to be * cleared * @return a flag whether there are elements to be cleared */ private static boolean initializeClearTransaction(final ModelTransaction tx, final Collection<QueryResult<ImmutableNode>> results) { for (final QueryResult<ImmutableNode> result : results) { if (result.isAttributeResult()) { tx.addRemoveAttributeOperation(result.getNode(), result.getAttributeName()); } else { tx.addClearNodeValueOperation(result.getNode()); } } return !results.isEmpty(); }
tx.addAttributeOperation(addData.getParent(), addData.getNewNodeName(), values.iterator().next()); Collections.singleton(childWithAttribute)) : childWithAttribute; tx.addAddNodeOperation(addData.getParent(), newChild);