org.basex.query.up
Class Updates

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

public final class Updates
extends java.lang.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 UpdatePrimitive.
  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. DatabaseUpdates
  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 UpdatePrimitiveComparator helps to order UpdatePrimitive for execution. Each primitive then creates a sequence of BasicUpdate which are passed to the Data layer via an AtomicUpdateList. This list takes care of optimization and also text node merging.

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

Field Summary
 ContextModifier mod
          Current context modifier.
 TokenSet putPaths
          All file paths that are targeted during a snapshot by an fn:put expression.
 
Constructor Summary
Updates()
           
 
Method Summary
 void add(Operation up, QueryContext ctx)
          Adds an update primitive to the current context modifier.
 void apply()
          Executes all updates.
 StringList databases()
          Adds all databases to be updated to the specified list.
 DBNode determineDataRef(ANode target, QueryContext ctx)
          Determines the data reference and pre value for an update primitive which has a fragment as a target node.
 int size()
          Number of updates on the pending update list.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mod

public 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 Detail

Updates

public Updates()
Method Detail

add

public void add(Operation up,
                QueryContext ctx)
         throws QueryException
Adds an update primitive to the current context modifier.

Parameters:
up - update primitive
ctx - query context
Throws:
QueryException - query exception

determineDataRef

public DBNode determineDataRef(ANode target,
                               QueryContext ctx)
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.

Parameters:
target - target fragment
ctx - query context
Returns:
database node created from input fragment

apply

public void apply()
           throws QueryException
Executes all updates.

Throws:
QueryException - query exception

databases

public StringList databases()
Adds all databases to be updated to the specified list.

Returns:
databases

size

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

Returns:
#updates