Package org.basex.query.up.atomic
Class AtomicUpdateCache
java.lang.Object
org.basex.query.up.atomic.AtomicUpdateCache
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:
- Efficient distance adjustments after structural changes.
- Tree-Aware Updates (TAU): identification of superfluous updates (like updating the descendants of a deleted node).
- Resolution of text node adjacency.
- 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
DeleteorReplaceoperating on the same node. - more than one
RenameorUpdateValueoperating 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 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddDelete(int pre) Adds a delete atomic to the list.voidAdds an insert atomic to the list.voidaddRename(int pre, byte[] name, byte[] uri) Adds a rename atomic to the list.voidaddReplace(int pre, DataClip clip) Adds a replace atomic to the list.voidaddUpdateValue(int pre, byte[] value) Adds an updateValue atomic to the list.voidCarries out structural updates.intcalculatePreValue(int pre, boolean beforeUpdates) Calculates the PRE value of a given node before/after updates.voidclear()Resets the list.voidexecute(boolean mergeTexts) Executes the updates.intReturns the number of structural updates.
-
Field Details
-
data
Target data reference.
-
-
Constructor Details
-
AtomicUpdateCache
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
Adds an insert atomic to the list.- Parameters:
pre- PRE value of the target node/update locationpar- new parent of the inserted nodesclip- insertion sequence data clip
-
addReplace
Adds a replace atomic to the list.- Parameters:
pre- PRE value of the target node/update locationclip- 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 locationname- new name for the target nodeuri- 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 locationvalue- 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 valuebeforeUpdates- calculate PRE value before shifts/updates have been applied- Returns:
- index of update, or -1
-