Class AtomicUpdateCache

java.lang.Object
org.basex.query.up.atomic.AtomicUpdateCache

public final class AtomicUpdateCache extends Object
Implementation of the Atomic Update Cache (AUC).

A container/list for atomic updates. Updates must be added from the lowest to the highest PRE value (regarding the location of the update). Updates are finally applied by this container from the highest to the lowest PRE value (reverse document order) to support efficient structural bulk updates etc.

If a collection of updates is carried out via the AUC there are several benefits:

  1. Efficient distance adjustments after structural changes.
  2. Tree-Aware Updates (TAU): identification of superfluous updates (like updating the descendants of a deleted node).
  3. Resolution of text node adjacency.
  4. Merging of atomic updates to reduce number of I/Os.

To avoid ambiguity it is not allowed to add:

  • more than one destructive update like Delete or Replace operating on the same node.
  • more than one Rename or UpdateValue operating on the same node.
  • sequences like [delete X, insert N at X]: This sequence would be carried out back to front: first the insert, then the delete. This would lead to the inserted node N being deleted by the 'delete X' statement. The correct order for this sequence would be [insert N at X, delete X].
  • and so forth ... see check() function for details.

Updates are added in a streaming fashion where the most recently added update is remembered. This avoids additional traversals of the AUC during consistency checks and further optimizations.

Author:
BaseX Team 2005-21, BSD License, Lukas Kircher
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    final Data
    Target data reference.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addDelete(int pre)
    Adds a delete atomic to the list.
    void
    addInsert(int pre, int par, DataClip clip)
    Adds an insert atomic to the list.
    void
    addRename(int pre, byte[] name, byte[] uri)
    Adds a rename atomic to the list.
    void
    addReplace(int pre, DataClip clip)
    Adds a replace atomic to the list.
    void
    addUpdateValue(int pre, byte[] value)
    Adds an updateValue atomic to the list.
    void
    Carries out structural updates.
    int
    calculatePreValue(int pre, boolean beforeUpdates)
    Calculates the PRE value of a given node before/after updates.
    void
    Resets the list.
    void
    execute(boolean mergeTexts)
    Executes the updates.
    int
    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 Details

    • data

      public final Data data
      Target data reference.
  • Constructor Details

    • AtomicUpdateCache

      public AtomicUpdateCache(Data data)
      Constructor.
      Parameters:
      data - target data reference
  • Method Details

    • 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)
      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
    • 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, byte[] name, byte[] uri)
      Adds a rename atomic to the list.
      Parameters:
      pre - PRE value of the target node/update location
      name - new name for the target node
      uri - new uri for the target node
    • addUpdateValue

      public void addUpdateValue(int pre, byte[] value)
      Adds an updateValue atomic to the list.
      Parameters:
      pre - PRE value of the target node/update location
      value - new value for the target node
    • clear

      public void clear()
      Resets the list.
    • updatesSize

      public int updatesSize()
      Returns the number of structural updates.
      Returns:
      number of structural updates
    • 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
    • applyUpdates

      public void applyUpdates()
      Carries out structural 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