From: Wolfgang M. M. <wol...@us...> - 2004-06-23 12:43:14
|
Update of /cvsroot/exist/eXist-1.0/src/org/exist/xupdate In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22261/src/org/exist/xupdate Modified Files: Append.java Insert.java Rename.java Remove.java Modification.java Update.java Log Message: Added an automatic defragmentation method to the XUpdate implementation. Index: Update.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/xupdate/Update.java,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** Update.java 16 Jun 2004 13:36:53 -0000 1.15 --- Update.java 23 Jun 2004 12:43:05 -0000 1.16 *************** *** 79,82 **** --- 79,83 ---- DocumentImpl doc = null; Collection collection = null, prevCollection = null; + DocumentSet modifiedDocs = new DocumentSet(); for (int i = 0; i < ql.length; i++) { node = ql[i]; *************** *** 87,90 **** --- 88,92 ---- doc = (DocumentImpl) node.getOwnerDocument(); doc.setIndexListener(listener); + modifiedDocs.add(doc); collection = doc.getCollection(); if (!doc.getPermissions().validate(broker.getUser(), *************** *** 137,140 **** --- 139,143 ---- } if (doc != null) doc.getBroker().saveCollection(collection); + checkFragmentation(modifiedDocs); } finally { unlockDocuments(); Index: Rename.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/xupdate/Rename.java,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** Rename.java 16 Jun 2004 13:36:53 -0000 1.15 --- Rename.java 23 Jun 2004 12:43:05 -0000 1.16 *************** *** 70,73 **** --- 70,74 ---- DocumentImpl doc = null; Collection collection = null, prevCollection = null; + DocumentSet modifiedDocs = new DocumentSet(); NodeImpl node; NodeImpl parent; *************** *** 90,93 **** --- 91,95 ---- "permission denied to update document"); doc.setIndexListener(listener); + modifiedDocs.add(doc); parent = (NodeImpl) node.getParentNode(); switch (node.getNodeType()) { *************** *** 113,116 **** --- 115,119 ---- } if (doc != null) doc.getBroker().saveCollection(collection); + checkFragmentation(modifiedDocs); } finally { unlockDocuments(); Index: Insert.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/xupdate/Insert.java,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** Insert.java 16 Jun 2004 13:36:53 -0000 1.15 --- Insert.java 23 Jun 2004 12:43:05 -0000 1.16 *************** *** 80,83 **** --- 80,84 ---- DocumentImpl doc = null; Collection collection = null, prevCollection = null; + DocumentSet modifiedDocs = new DocumentSet(); int len = children.getLength(); LOG.debug("found " + len + " nodes to insert"); *************** *** 93,96 **** --- 94,98 ---- throw new PermissionDeniedException( "permission to remove document denied"); + modifiedDocs.add(doc); parent = (NodeImpl) node.getParentNode(); switch (mode) { *************** *** 107,110 **** --- 109,113 ---- } if (doc != null) doc.getBroker().saveCollection(collection); + checkFragmentation(modifiedDocs); return ql.length; } finally { Index: Modification.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/xupdate/Modification.java,v retrieving revision 1.28 retrieving revision 1.29 diff -C2 -d -r1.28 -r1.29 *** Modification.java 17 Jun 2004 13:19:31 -0000 1.28 --- Modification.java 23 Jun 2004 12:43:05 -0000 1.29 *************** *** 36,40 **** import org.exist.dom.NodeIndexListener; import org.exist.dom.NodeSet; - import org.exist.dom.XMLUtil; import org.exist.security.PermissionDeniedException; import org.exist.storage.DBBroker; --- 36,39 ---- *************** *** 50,54 **** import org.exist.xquery.value.Sequence; import org.exist.xquery.value.Type; - import org.w3c.dom.DocumentFragment; import org.w3c.dom.NodeList; --- 49,52 ---- *************** *** 202,205 **** --- 200,219 ---- } + /** + * Check if any of the modified documents needs defragmentation. + * + * Defragmentation will take place if the number of split pages in the + * document exceeds the limit defined in the configuration file. + * + * @param docs + */ + protected void checkFragmentation(DocumentSet docs) { + for(Iterator i = docs.iterator(); i.hasNext(); ) { + DocumentImpl next = (DocumentImpl) i.next(); + if(next.getSplitCount() > broker.getFragmentationLimit()) + broker.defrag(next); + } + } + public String toString() { StringBuffer buf = new StringBuffer(); Index: Append.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/xupdate/Append.java,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** Append.java 16 Jun 2004 13:36:53 -0000 1.17 --- Append.java 23 Jun 2004 12:43:05 -0000 1.18 *************** *** 72,76 **** IndexListener listener = new IndexListener(ql); Collection collection = null, prevCollection = null; ! DocumentImpl doc = null, prevDoc = null; NodeImpl node; for(int i = 0; i < ql.length; i++) { --- 72,77 ---- IndexListener listener = new IndexListener(ql); Collection collection = null, prevCollection = null; ! DocumentImpl doc = null; ! DocumentSet modifiedDocs = new DocumentSet(); NodeImpl node; for(int i = 0; i < ql.length; i++) { *************** *** 78,84 **** doc = (DocumentImpl) node.getOwnerDocument(); doc.setIndexListener(listener); collection = doc.getCollection(); ! if (prevCollection != null && collection != prevCollection) ! doc.getBroker().saveCollection(prevCollection); if (!doc.getPermissions().validate(broker.getUser(), Permission.UPDATE)) throw new PermissionDeniedException("permission to update document denied"); --- 79,87 ---- doc = (DocumentImpl) node.getOwnerDocument(); doc.setIndexListener(listener); + modifiedDocs.add(doc); collection = doc.getCollection(); ! if (prevCollection != null && collection != prevCollection) { ! broker.saveCollection(prevCollection); ! } if (!doc.getPermissions().validate(broker.getUser(), Permission.UPDATE)) throw new PermissionDeniedException("permission to update document denied"); *************** *** 89,93 **** } if (doc != null) ! doc.getBroker().saveCollection(collection); return ql.length; } finally { --- 92,97 ---- } if (doc != null) ! broker.saveCollection(collection); ! checkFragmentation(modifiedDocs); return ql.length; } finally { Index: Remove.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/xupdate/Remove.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** Remove.java 16 Jun 2004 09:21:32 -0000 1.13 --- Remove.java 23 Jun 2004 12:43:05 -0000 1.14 *************** *** 66,69 **** --- 66,70 ---- DocumentImpl doc = null; Collection collection = null, prevCollection = null; + DocumentSet modifiedDocs = new DocumentSet(); for (int i = 0; i < ql.length; i++) { node = ql[i]; *************** *** 75,80 **** collection = doc.getCollection(); if (prevCollection != null && collection != prevCollection) ! doc.getBroker().saveCollection(prevCollection); doc.setIndexListener(listener); parent = node.getParentNode(); if (parent.getNodeType() != Node.ELEMENT_NODE) { --- 76,82 ---- collection = doc.getCollection(); if (prevCollection != null && collection != prevCollection) ! broker.saveCollection(prevCollection); doc.setIndexListener(listener); + modifiedDocs.add(doc); parent = node.getParentNode(); if (parent.getNodeType() != Node.ELEMENT_NODE) { *************** *** 89,93 **** prevCollection = collection; } ! if (doc != null) doc.getBroker().saveCollection(collection); return ql.length; } finally { --- 91,96 ---- prevCollection = collection; } ! if (doc != null) broker.saveCollection(collection); ! checkFragmentation(modifiedDocs); return ql.length; } finally { |