public StoredNode getReindexRoot(StoredNode node, NodePath path, boolean includeSelf) { if (node.getNodeType() == Node.ATTRIBUTE_NODE) return null; IndexSpec indexConf = node.getDocument().getCollection().getIndexConfiguration(node.getDocument().getBroker()); if (indexConf != null) { FulltextIndexSpec config = indexConf.getFulltextIndexSpec(); if (config == null) return null; boolean reindexRequired = false; int len = node.getNodeType() == Node.ELEMENT_NODE && !includeSelf ? path.length() - 1 : path.length(); for (int i = 0; i < len; i++) { QName qn = path.getComponent(i); if (config.hasQNameIndex(qn)) { reindexRequired = true; break; } } if (reindexRequired) { StoredNode topMost = null; StoredNode currentNode = node; while (currentNode != null) { if (config.hasQNameIndex(currentNode.getQName())) topMost = currentNode; currentNode = (StoredNode) currentNode.getParentNode(); } return topMost; } } return null; }
/* * (non-Javadoc) * * @see org.exist.xupdate.Modification#process(org.exist.dom.DocumentSet) */ public long process(Txn transaction) throws PermissionDeniedException, LockException, EXistException, XPathException { NodeList children = content; if (children.getLength() == 0) return 0; int modifications = children.getLength(); try { StoredNode ql[] = selectAndLock(transaction); IndexListener listener = new IndexListener(ql); NotificationService notifier = broker.getBrokerPool().getNotificationService(); Node temp; TextImpl text; AttrImpl attribute; ElementImpl parent; for (int i = 0; i < ql.length; i++) { StoredNode node = ql[i]; if (node == null) { LOG.warn("select " + selectStmt + " returned empty node"); continue; } DocumentImpl doc = (DocumentImpl) node.getOwnerDocument(); doc.getMetadata().setIndexListener(listener); if (!doc.getPermissions().validate(broker.getUser(), Permission.UPDATE)) throw new PermissionDeniedException("permission to update document denied"); switch (node.getNodeType()) { case Node.ELEMENT_NODE: if (modifications == 0) modifications = 1; ((ElementImpl) node).update(transaction, children); break; case Node.TEXT_NODE: parent = (ElementImpl) node.getParentNode(); temp = children.item(0); text = new TextImpl(temp.getNodeValue()); modifications = 1; text.setOwnerDocument(doc); parent.updateChild(transaction, node, text); break; case Node.ATTRIBUTE_NODE: parent = (ElementImpl) node.getParentNode(); if (parent == null) { LOG.warn("parent node not found for " + node.getNodeId()); break; } AttrImpl attr = (AttrImpl) node; temp = children.item(0); attribute = new AttrImpl(attr.getQName(), temp.getNodeValue()); attribute.setOwnerDocument(doc); parent.updateChild(transaction, node, attribute); break; default: throw new EXistException("unsupported node-type"); } doc.getMetadata().clearIndexListener(); doc.getMetadata().setLastModified(System.currentTimeMillis()); modifiedDocuments.add(doc); broker.storeXMLResource(transaction, doc); notifier.notifyUpdate(doc, UpdateListener.UPDATE); } checkFragmentation(transaction, modifiedDocuments); } finally { unlockDocuments(transaction); } return modifications; }