org.basex.data.atomic
Class AtomicUpdateList

java.lang.Object
  extended by org.basex.data.atomic.AtomicUpdateList

public final class AtomicUpdateList
extends java.lang.Object

A container/list for atomic updates. Updates are then carried out in the same order that they have been added. No reordering takes place. The user is responsible to add them in the correct order.

Updates must be strictly ordered from the highest to the lowest PRE value, otherwise an exception is returned.

If a collection of updates is carried out via this container there are several benefits:

  1. Caching distance updates of the table due to structural changes and carrying them out in an efficient manner.
  2. Tree-Aware Updates: identification of superfluous updates (like updating the descendants of a deleted node).
  3. Merging of adjacent text nodes which are not allowed (see XDM).

Mind that two delete atomics on a list targeting the same PRE value location result in two nodes A and B being deleted, due to PRE value shifts after the first delete, where pre(B) = pre(A) + 1. If a list of atomic updates is prepared for execution it should be ordered from the highest to the lowest PRE value.

To avoid ambiguity it is not allowed to add:

Author:
BaseX Team 2005-12, BSD License, Lukas Kircher

Field Summary
 Data data
          Target data reference.
 
Constructor Summary
AtomicUpdateList(Data d)
          Constructor.
 
Method Summary
 void addDelete(int pre)
          Adds a delete atomic to the list.
 void addInsert(int pre, int par, DataClip clip, boolean attr)
          Adds an insert atomic to the list.
 void addRename(int pre, int k, byte[] n, byte[] u)
          Adds a rename atomic to the list.
 void addReplace(int pre, DataClip clip)
          Adds a replace atomic to the list.
 void addUpdateValue(int pre, int k, byte[] v)
          Adds an updateValue atomic to the list.
 void applyStructuralUpdates()
          Carries out structural updates.
 void applyValueUpdates()
          Carries out value updates.
 int calculatePreValue(int pre, boolean beforeUpdates)
          Calculates the PRE value of a given node before/after updates.
 void check()
          Checks the list of updates for violations.
 void clear()
          Resets the list.
 void execute(boolean mergeTexts)
          Executes the updates.
 void optimize()
          Removes superfluous update operations.
 int structuralUpdatesSize()
          Returns the number of structural updates.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

data

public final Data data
Target data reference.

Constructor Detail

AtomicUpdateList

public AtomicUpdateList(Data d)
Constructor.

Parameters:
d - target data reference
Method Detail

addDelete

public void addDelete(int pre)
Adds a delete atomic to the list.

Parameters:
pre - PRE value of the target node/update location

addInsert

public void addInsert(int pre,
                      int par,
                      DataClip clip,
                      boolean attr)
Adds an insert atomic to the list.

Parameters:
pre - PRE value of the target node/update location
par - new parent of the inserted nodes
clip - insertion sequence data clip
attr - insert attribute if true or a node of any other kind if false

addReplace

public void addReplace(int pre,
                       DataClip clip)
Adds a replace atomic to the list.

Parameters:
pre - PRE value of the target node/update location
clip - insertion sequence data clip

addRename

public void addRename(int pre,
                      int k,
                      byte[] n,
                      byte[] u)
Adds a rename atomic to the list.

Parameters:
pre - PRE value of the target node/update location
k - kind of the target node
n - new name for the target node
u - new uri for the target node

addUpdateValue

public void addUpdateValue(int pre,
                           int k,
                           byte[] v)
Adds an updateValue atomic to the list.

Parameters:
pre - PRE value of the target node/update location
k - kind of the target node
v - new value for the target node

structuralUpdatesSize

public int structuralUpdatesSize()
Returns the number of structural updates.

Returns:
number of structural updates

clear

public void clear()
Resets the list.


check

public void check()
Checks the list of updates for violations. Updates must be ordered strictly from the highest to the lowest PRE value. A single node must not be affected by more than one Rename, UpdateValue operation. A single node must not be affected by more than one destructive operation. These operations include Replace, Delete.


optimize

public void optimize()
Removes superfluous update operations. If a node T is deleted or replaced, all updates on the descendant axis of T can be left out as they won't affect the database after all. Superfluous updates can have a minimum PRE value of pre(T)+1 and a maximum PRE value of pre(T)+size(T). An update with location pre(T)+size(T) can only be removed if the update is an atomic insert and the inserted node is then part of the subtree of T.


execute

public void execute(boolean mergeTexts)
Executes the updates. Resolving text node adjacency can be skipped if adjacent text nodes are not to be expected.

Parameters:
mergeTexts - adjacent text nodes are to be expected and must be merged

applyStructuralUpdates

public void applyStructuralUpdates()
Carries out structural updates.


applyValueUpdates

public void applyValueUpdates()
Carries out value updates.


calculatePreValue

public int calculatePreValue(int pre,
                             boolean beforeUpdates)
Calculates the PRE value of a given node before/after updates. Finds all updates that affect the given node N. The result is than calculated based on N and the accumulated PRE value shifts introduced by these updates. If a node has been inserted at position X and this method is used to calculate the PRE value of X before updates, X is the result. As the node at position X has not existed before the insertion, its PRE value is unchanged. If in contrast the PRE value is calculated after updates, the result is X+1, as the node with the original position X has been shifted by the insertion at position X. Make sure accumulated shifts have been calculated before calling this method!

Parameters:
pre - PRE value
beforeUpdates - calculate PRE value before shifts/updates have been applied
Returns:
index of update, or -1