public class NodeUpdateComparator extends Object implements Comparator<NodeUpdate>
Comparator for NodeUpdate
.
In general, a list of updates is applied from the highest to the lowest PRE value in
BaseX. The higher the actual location of an update the sooner it is applied, hence
the 'greater' NodeUpdate
is applied first. The order further relies on
the definition of UpdateType
.
NodeUpdate
s are identified by their target node's PRE values (T).
Depending on the UpdateType
of the update, a specific PRE value on the
table is affected (L). Hence it is not sufficient to order primitives based on T
(see case 2,3 below). It is also not sufficient to order them based on L (see case
2,3 below).
The first NodeUpdate
is referred to as P1, the target node of P1 is
referred to as T1, the (optional) insertion sequence for P1 is S1, the actually
affected PRE value on disk is L1. For the second P2, T2, S2, L2.
The result of the comparison depends on several things:
<DOC><N1/><N2/></DOC>
. If P1 is a DeleteNode
on N1
and P2 is a DeleteNode
on N2, it follows that T2>T1. P2 wins the comparison
and is therefore executed first.<DOC><N1><N2/></N1></DOC>
. If P1 is an InsertInto
on
N1 and P2 is an InsertInto
on N2, it follows that T2>T1. Yet, executing P2
first would lead to the following problem:InsertInto
or
InsertAfter
and T1+size(T1) is equal T2+size(T2), hence T1 and T2 have the
same following node. The correct order is realized by executing the update first, that
is on the ancestor axis of the other. In this case P1>P2.InsertIntoAsFirst
on an element
T1 and P2 is i.e. a ReplaceNode
on an attribute T2 of T1. To get the desired
order of insertion sequences (S2,S1) P1 must be executed first, hence P1>P2.UpdateType
of P1, P2.
Consider D the document <DOC><N1/></DOC>
with T=N1. P1 is an InsertBefore
on T and P2 is an InsertIntoAsFirst
on the same target T. As they both operate
on the same target, both have not to be re-located because of their type (see case 2),
hence only differ in their UpdateType
, it follows that P2>P1 as nodes
S2 are to be inserted on the following axis of S1.DeleteNode
on T and P1 an InsertBefore
on T. As
L2=L1, P2, the execution sequence must be (P2,P1). for(P1,P2) S1 would be deleted by
P2. The correct order is also determined by the order of UpdateType
. Here
we see that ordering updates simply by the actually affected PRE value L is not
sufficient.Constructor and Description |
---|
NodeUpdateComparator() |
Modifier and Type | Method and Description |
---|---|
int |
compare(NodeUpdate a,
NodeUpdate b) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
equals
public int compare(NodeUpdate a, NodeUpdate b)
compare
in interface Comparator<NodeUpdate>
Copyright © 2005–2015 BaseX Team. All rights reserved.