Class Updates

java.lang.Object
org.basex.query.up.Updates

public final class Updates extends Object

Implementation of the W3C XQUERY UPDATE FACILITY 1.0.

Holds all update operations and primitives a snapshot contains, checks constraints and finally executes the updates.

Fragment updates are treated like database updates. An artificial data instance is created for each fragment. Ultimately the updating process for a fragment is the same as for a database node.

The complete updating process is custom-tailored to the sequential table encoding of BaseX. As a general rule, all updates are collected and applied for each database from bottom to top, regarding the PRE values of the corresponding target nodes. Updates on the highest PRE values are applied first.

Updates work like the following:

  1. Each call of an updating expression creates an NodeUpdate.
  2. All update primitives for a snapshot/query are collected here.
  3. Primitives are kept separately for each database that is addressed. This way we can operate on PRE values instead of node IDs, skip mapping overhead and further optimize the process. DataUpdates
  4. Primitives are further kept separately for each database node - each individual target PRE value. There's a specific container for this: NodeUpdates
  5. Transform expressions are executed in an 'isolated' updating environment, see TransformModifier. All the other updates are executed by a DatabaseModifier.
  6. After the query has been parsed and all update primitives have been added to the list, constraints, which cannot be taken care of on the fly, are checked. If no problems occur, updates are TO BE carried out.
  7. Before applying the updates the NodeUpdateComparator helps to order NodeUpdate for execution. Each primitive then creates a sequence of BasicUpdate which are passed to the Data layer via an AtomicUpdateCache. This list takes care of optimization and also text node merging.
Author:
BaseX Team 2005-21, BSD License, Lukas Kircher
  • Field Details

    • mod

      public final org.basex.query.up.ContextModifier mod
      Current context modifier.
    • putPaths

      public final TokenSet putPaths
      All file paths that are targeted during a snapshot by an fn:put expression.
  • Constructor Details

    • Updates

      public Updates(boolean transform)
      Constructor.
      Parameters:
      transform - transform flag
  • Method Details

    • addData

      public void addData(Data data)
      Adds a data reference to list which keeps track of the nodes copied within a transform expression.
      Parameters:
      data - reference
    • add

      public void add(Update up, QueryContext qc) throws QueryException
      Adds an update primitive to the current context modifier.
      Parameters:
      up - update primitive
      qc - query context
      Throws:
      QueryException - query exception
    • addOutput

      public void addOutput(Value value, QueryContext qc)
      Adds output.
      Parameters:
      value - value to be added
      qc - query context
    • output

      public Value output(boolean reset)
      Returns value to be output.
      Parameters:
      reset - reset cache
      Returns:
      value
    • determineDataRef

      public DBNode determineDataRef(ANode target, QueryContext qc)
      Determines the data reference and pre value for an update primitive which has a fragment as a target node. If an ancestor of the given target node has already been added to the pending update list, the corresponding data reference and the pre value of the given target node within this database table are calculated. Otherwise a new data instance is created. This function is called during query evaluation.
      Parameters:
      target - target fragment
      qc - query context
      Returns:
      database node created from input fragment
    • prepare

      public HashSet<Data> prepare(QueryContext qc) throws QueryException
      Prepares update operations. Called after query evaluation.
      Parameters:
      qc - query context
      Returns:
      updated data references
      Throws:
      QueryException - query exception
    • apply

      public void apply(QueryContext qc) throws QueryException
      Executes all updates. Called after query evaluation.
      Parameters:
      qc - query context
      Throws:
      QueryException - query exception
    • databases

      public StringList databases()
      Returns the names of all databases that will be updated. Called after query evaluation.
      Returns:
      databases
    • size

      public int size()
      Number of updates on the pending update list.
      Returns:
      #updates