use of org.exist.indexing.StreamListener in project exist by eXist-db.
the class ElementImpl method removeAppendAttributes.
public void removeAppendAttributes(final Txn transaction, final NodeList removeList, final NodeList appendList) {
try (final DBBroker broker = ownerDocument.getBrokerPool().getBroker()) {
final IndexController indexes = broker.getIndexController();
if (removeList != null) {
try {
for (int i = 0; i < removeList.getLength(); i++) {
final Node oldChild = removeList.item(i);
if (!(oldChild instanceof IStoredNode)) {
throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, "Wrong node type");
}
final IStoredNode<?> old = (IStoredNode<?>) oldChild;
if (!old.getNodeId().isChildOf(nodeId)) {
throw new DOMException(DOMException.NOT_FOUND_ERR, "node " + old.getNodeId().getParentId() + " is not a child of element " + nodeId);
}
final NodePath oldPath = old.getPath();
// remove old custom indexes
indexes.reindex(transaction, old, ReindexMode.REMOVE_SOME_NODES);
broker.removeNode(transaction, old, oldPath, null);
children--;
attributes--;
}
} finally {
broker.endRemove(transaction);
}
}
final NodePath path = getPath();
indexes.setDocument(ownerDocument, ReindexMode.STORE);
final IStoredNode reindexRoot = indexes.getReindexRoot(this, path, true, true);
final StreamListener listener = reindexRoot == null ? indexes.getStreamListener() : null;
if (children == 0) {
appendChildren(transaction, nodeId.newChild(), null, new NodeImplRef(this), path, appendList, listener);
} else {
if (attributes == 0) {
final IStoredNode<?> firstChild = (IStoredNode<?>) getFirstChild();
final NodeId newNodeId = firstChild.getNodeId().insertBefore();
appendChildren(transaction, newNodeId, firstChild.getNodeId(), new NodeImplRef(this), path, appendList, listener);
} else {
final AttribVisitor visitor = new AttribVisitor();
accept(visitor);
final NodeId firstChildId = visitor.firstChild == null ? null : visitor.firstChild.getNodeId();
final NodeId newNodeId = visitor.lastAttrib.getNodeId().insertNode(firstChildId);
appendChildren(transaction, newNodeId, firstChildId, new NodeImplRef(visitor.lastAttrib), path, appendList, listener);
}
setDirty(true);
}
attributes += appendList.getLength();
broker.updateNode(transaction, this, true);
broker.flush();
indexes.reindex(transaction, reindexRoot, ReindexMode.STORE);
} catch (final EXistException e) {
LOG.warn("Exception while inserting node: {}", e.getMessage(), e);
}
}
Aggregations