Skip to content

Commit

Permalink
[bugfix] Fix DOM model for persistent ElementImpl#appendChildren. Use…
Browse files Browse the repository at this point in the history
…d by XQuery Update `update insert`.

Closes #1663
  • Loading branch information
adamretter committed Feb 13, 2018
1 parent 8d74e07 commit eaef790
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions src/org/exist/dom/persistent/ElementImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ public void appendChildren(final Txn transaction, NodeList nodes, final int chil
final IStoredNode<?> last = (IStoredNode<?>) cl.item(child - 2);
insertAfter(transaction, nodes, last);
} else {
final IStoredNode<?> last = (IStoredNode<?>) getLastChild();
final IStoredNode<?> last = (IStoredNode<?>) getLastChild(true);
appendChildren(transaction, last.getNodeId().nextSibling(), null,
new NodeImplRef(getLastNode(last)), path, nodes, listener);
}
Expand Down Expand Up @@ -1030,18 +1030,41 @@ public Node getFirstChild() {

@Override
public Node getLastChild() {
if(!hasChildNodes()) {
return getLastChild(false);
}

/**
* Get the last child.
*
* @param attributesAreChildren In the DLN model attributes have child node ids,
* however in the DOM model attributes are not child nodes. Set true for DLN
* or false for DOM.
*
* @return the last child.
*/
private Node getLastChild(final boolean attributesAreChildren) {
if ((!attributesAreChildren) && (!hasChildNodes())) {
// DOM model
return null;
} else if (!(hasChildNodes() || hasAttributes())) {
// DLN model
return null;
}

Node node = null;
if(!isDirty) {
if (!isDirty) {
final NodeId child = nodeId.getChild(children);
node = ownerDocument.getNode(new NodeProxy(ownerDocument, child));
}

if(node == null) {
final NodeList cl = getChildNodes();
if (node == null) {
final NodeList cl;
if (!attributesAreChildren) {
// DOM model
cl = getChildNodes();
} else {
// DLN model
cl = getAttrsAndChildNodes();
}
return cl.item(cl.getLength() - 1);
}
return node;
Expand Down

0 comments on commit eaef790

Please sign in to comment.