From: Wolfgang M. M. <wol...@us...> - 2004-05-03 12:58:22
|
Update of /cvsroot/exist/eXist-1.0/src/org/exist/xmldb In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16328/src/org/exist/xmldb Modified Files: LocalXUpdateQueryService.java LocalCollection.java LocalUserManagementService.java LocalXMLResource.java LocalXPathQueryService.java DatabaseImpl.java LocalIndexQueryService.java LocalResourceSet.java Log Message: org.exist.xmldb.LocalCollection should not hold a direct reference to the actual database collection object. Keeping the reference conflicts with the database internal collection caching. Index: DatabaseImpl.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/xmldb/DatabaseImpl.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** DatabaseImpl.java 24 Apr 2004 13:45:54 -0000 1.13 --- DatabaseImpl.java 3 May 2004 12:58:11 -0000 1.14 *************** *** 177,181 **** try { current = new LocalCollection( u, pool, c.substring( 2 ) ); ! return ( current != null && ( (LocalCollection) current ).isValid() ) ? current : null; } catch ( XMLDBException e ) { --- 177,181 ---- try { current = new LocalCollection( u, pool, c.substring( 2 ) ); ! return ( current != null ) ? current : null; } catch ( XMLDBException e ) { Index: LocalXUpdateQueryService.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/xmldb/LocalXUpdateQueryService.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** LocalXUpdateQueryService.java 29 Jan 2004 15:06:43 -0000 1.11 --- LocalXUpdateQueryService.java 3 May 2004 12:58:11 -0000 1.12 *************** *** 57,71 **** DocumentSet docs = new DocumentSet(); DBBroker broker = null; try { broker = pool.get(user); if (resource == null) { ! docs = parent.collection.allDocs(broker, docs, true); } else { String id = parent.getName() + '/' + resource; ! DocumentImpl doc = parent.collection.getDocument(id); LOG.debug("updating resource " + doc.getFileName()); docs.add(doc); } - //LOG.debug(xupdate); XUpdateProcessor processor = new XUpdateProcessor(broker, docs); Modification modifications[] = --- 57,71 ---- DocumentSet docs = new DocumentSet(); DBBroker broker = null; + org.exist.collections.Collection c = parent.getCollection(); try { broker = pool.get(user); if (resource == null) { ! docs = c.allDocs(broker, docs, true); } else { String id = parent.getName() + '/' + resource; ! DocumentImpl doc = c.getDocument(id); LOG.debug("updating resource " + doc.getFileName()); docs.add(doc); } XUpdateProcessor processor = new XUpdateProcessor(broker, docs); Modification modifications[] = Index: LocalIndexQueryService.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/xmldb/LocalIndexQueryService.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** LocalIndexQueryService.java 16 Feb 2004 13:02:16 -0000 1.4 --- LocalIndexQueryService.java 3 May 2004 12:58:11 -0000 1.5 *************** *** 1,7 **** - /* - * LocalIndexQueryService.java - Mar 5, 2003 - * - * @author wolf - */ package org.exist.xmldb; --- 1,2 ---- *************** *** 16,25 **** import org.xmldb.api.base.XMLDBException; - /** - * @author wolf - * - * To change this generated comment go to - * Window>Preferences>Java>Code Generation>Code and Comments - */ public class LocalIndexQueryService implements IndexQueryService { --- 11,14 ---- *************** *** 45,49 **** try { broker = pool.get(user); ! return broker.scanIndexedElements(parent.collection, inclusive); } catch (EXistException e) { throw new XMLDBException( --- 34,38 ---- try { broker = pool.get(user); ! return broker.scanIndexedElements(parent.getCollection(), inclusive); } catch (EXistException e) { throw new XMLDBException( *************** *** 108,112 **** try { broker = pool.get(user); ! return broker.getTextEngine().scanIndexTerms(user, parent.collection, start, end, inclusive); } catch (PermissionDeniedException e) { --- 97,101 ---- try { broker = pool.get(user); ! return broker.getTextEngine().scanIndexTerms(user, parent.getCollection(), start, end, inclusive); } catch (PermissionDeniedException e) { Index: LocalUserManagementService.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/xmldb/LocalUserManagementService.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** LocalUserManagementService.java 9 Feb 2004 08:56:20 -0000 1.14 --- LocalUserManagementService.java 3 May 2004 12:58:11 -0000 1.15 *************** *** 419,432 **** public Permission[] listResourcePermissions() throws XMLDBException { ! if (!collection ! .collection ! .getPermissions() .validate(user, Permission.READ)) return new Permission[0]; Permission perms[] = ! new Permission[collection.collection.getDocumentCount()]; int j = 0; DocumentImpl doc; ! for (Iterator i = collection.collection.iterator(); i.hasNext(); j++) { doc = (DocumentImpl) i.next(); perms[j] = doc.getPermissions(); --- 419,431 ---- public Permission[] listResourcePermissions() throws XMLDBException { ! org.exist.collections.Collection c = collection.getCollection(); ! if (!c .getPermissions() .validate(user, Permission.READ)) return new Permission[0]; Permission perms[] = ! new Permission[c.getDocumentCount()]; int j = 0; DocumentImpl doc; ! for (Iterator i = c.iterator(); i.hasNext(); j++) { doc = (DocumentImpl) i.next(); perms[j] = doc.getPermissions(); *************** *** 436,446 **** public Permission[] listCollectionPermissions() throws XMLDBException { ! if (!collection ! .collection ! .getPermissions() .validate(user, Permission.READ)) return new Permission[0]; Permission perms[] = ! new Permission[collection.collection.getChildCollectionCount()]; DBBroker broker = null; try { --- 435,444 ---- public Permission[] listCollectionPermissions() throws XMLDBException { ! org.exist.collections.Collection c = collection.getCollection(); ! if (!c.getPermissions() .validate(user, Permission.READ)) return new Permission[0]; Permission perms[] = ! new Permission[c.getChildCollectionCount()]; DBBroker broker = null; try { *************** *** 449,453 **** org.exist.collections.Collection childColl; int j = 0; ! for (Iterator i = collection.collection.collectionIterator(); i.hasNext(); j++) { --- 447,451 ---- org.exist.collections.Collection childColl; int j = 0; ! for (Iterator i = c.collectionIterator(); i.hasNext(); j++) { Index: LocalXPathQueryService.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/xmldb/LocalXPathQueryService.java,v retrieving revision 1.37 retrieving revision 1.38 diff -C2 -d -r1.37 -r1.38 *** LocalXPathQueryService.java 16 Apr 2004 14:44:22 -0000 1.37 --- LocalXPathQueryService.java 3 May 2004 12:58:11 -0000 1.38 *************** *** 111,115 **** try { broker = brokerPool.get(user); ! docs = collection.collection.allDocs(broker, new DocumentSet(), true); } catch (EXistException e) { throw new XMLDBException( --- 111,115 ---- try { broker = brokerPool.get(user); ! docs = collection.getCollection().allDocs(broker, new DocumentSet(), true); } catch (EXistException e) { throw new XMLDBException( *************** *** 152,158 **** try { broker = brokerPool.get(user); ! if(docs == null) ! docs = collection.collection.allDocs(broker, new DocumentSet(), true); ! expression.reset(); XQueryContext context = ((PathExpr)expression).getContext(); --- 152,159 ---- try { broker = brokerPool.get(user); ! if(docs == null) { ! docs = collection.getCollection().allDocs(broker, new DocumentSet(), true); ! } ! expression.reset(); XQueryContext context = ((PathExpr)expression).getContext(); *************** *** 160,164 **** context.setBackwardsCompatibility(xpathCompatible); context.setStaticallyKnownDocuments(docs); ! Map.Entry entry; // declare namespace/prefix mappings --- 161,165 ---- context.setBackwardsCompatibility(xpathCompatible); context.setStaticallyKnownDocuments(docs); ! LOG.debug("docs: " + docs.getLength()); Map.Entry entry; // declare namespace/prefix mappings Index: LocalCollection.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/xmldb/LocalCollection.java,v retrieving revision 1.30 retrieving revision 1.31 diff -C2 -d -r1.30 -r1.31 *** LocalCollection.java 23 Apr 2004 13:07:43 -0000 1.30 --- LocalCollection.java 3 May 2004 12:58:11 -0000 1.31 *************** *** 25,29 **** import java.net.URI; - import java.net.URLEncoder; import java.util.ArrayList; import java.util.Date; --- 25,28 ---- *************** *** 38,41 **** --- 37,41 ---- import org.apache.log4j.Category; import org.exist.EXistException; + import org.exist.collections.Collection; import org.exist.collections.triggers.TriggerException; import org.exist.dom.BinaryDocument; *************** *** 49,53 **** import org.exist.util.LockException; import org.xml.sax.InputSource; - import org.xmldb.api.base.Collection; import org.xmldb.api.base.ErrorCodes; import org.xmldb.api.base.Resource; --- 49,52 ---- *************** *** 65,69 **** * *@author wolf - *@created April 2, 2002 */ public class LocalCollection extends Observable implements CollectionImpl { --- 64,67 ---- *************** *** 79,84 **** } protected BrokerPool brokerPool = null; - protected org.exist.collections.Collection collection = null; protected Properties properties = new Properties(defaultProperties); protected LocalCollection parent = null; --- 77,82 ---- } + protected String path = null; protected BrokerPool brokerPool = null; protected Properties properties = new Properties(defaultProperties); protected LocalCollection parent = null; *************** *** 101,123 **** /** - * Create a collection using the supplied internal collection. - * - * @param user - * @param brokerPool - * @param parent - * @param collection - */ - public LocalCollection( - User user, - BrokerPool brokerPool, - LocalCollection parent, - org.exist.collections.Collection collection) { - this.user = user; - this.brokerPool = brokerPool; - this.parent = parent; - this.collection = collection; - } - - /** * Create a collection identified by its name. Load the collection from the database. * --- 99,102 ---- *************** *** 139,156 **** this.parent = parent; this.brokerPool = brokerPool; ! load(name); } ! private void load(String name) throws XMLDBException { DBBroker broker = null; try { broker = brokerPool.get(user); ! if (name == null) ! name = "/db"; ! collection = broker.getCollection(name); if (collection == null) throw new XMLDBException( ! ErrorCodes.NO_SUCH_RESOURCE, "collection not found"); } catch (EXistException e) { throw new XMLDBException(ErrorCodes.VENDOR_ERROR, e.getMessage(), e); --- 118,137 ---- this.parent = parent; this.brokerPool = brokerPool; ! this.path = name; ! if (path == null) ! path = "/db"; ! getCollection(); } ! protected Collection getCollection() throws XMLDBException { DBBroker broker = null; try { broker = brokerPool.get(user); ! org.exist.collections.Collection collection = broker.getCollection(path); if (collection == null) throw new XMLDBException( ! ErrorCodes.NO_SUCH_COLLECTION, "collection not found"); + return collection; } catch (EXistException e) { throw new XMLDBException(ErrorCodes.VENDOR_ERROR, e.getMessage(), e); *************** *** 160,169 **** } ! protected boolean checkOwner(User user) { ! return user.getName().equals(collection.getPermissions().getOwner()); } ! protected boolean checkPermissions(int perm) { ! return collection.getPermissions().validate(user, perm); } --- 141,150 ---- } ! protected boolean checkOwner(User user) throws XMLDBException { ! return user.getName().equals(getCollection().getPermissions().getOwner()); } ! protected boolean checkPermissions(int perm) throws XMLDBException { ! return getCollection().getPermissions().validate(user, perm); } *************** *** 194,201 **** id = Integer.toHexString(rand.nextInt()) + ".xml"; // check if this id does already exist ! if (collection.hasDocument(id)) ok = false; ! if (collection.hasSubcollection(id)) ok = false; --- 175,182 ---- id = Integer.toHexString(rand.nextInt()) + ".xml"; // check if this id does already exist ! if (getCollection().hasDocument(id)) ok = false; ! if (getCollection().hasSubcollection(id)) ok = false; *************** *** 220,224 **** } ! public Collection getChildCollection(String name) throws XMLDBException { if (!checkPermissions(Permission.READ)) throw new XMLDBException( --- 201,205 ---- } ! public org.xmldb.api.base.Collection getChildCollection(String name) throws XMLDBException { if (!checkPermissions(Permission.READ)) throw new XMLDBException( *************** *** 226,235 **** "you are not allowed to access this collection"); String cname; ! for (Iterator i = collection.collectionIterator(); i.hasNext();) { cname = (String) i.next(); if (cname.equals(name)) { cname = getPath() + '/' + cname; ! Collection temp = new LocalCollection(user, brokerPool, this, cname); ! return temp; } } --- 207,215 ---- "you are not allowed to access this collection"); String cname; ! for (Iterator i = getCollection().collectionIterator(); i.hasNext();) { cname = (String) i.next(); if (cname.equals(name)) { cname = getPath() + '/' + cname; ! return new LocalCollection(user, brokerPool, this, cname); } } *************** *** 238,241 **** --- 218,222 ---- public int getChildCollectionCount() throws XMLDBException { + Collection collection = getCollection(); if (collection.getPermissions().validate(user, Permission.READ)) return collection.getChildCollectionCount(); *************** *** 244,258 **** } - protected org.exist.collections.Collection getCollection() { - return collection; - } - public String getName() throws XMLDBException { ! return collection.getName(); } ! public Collection getParentCollection() throws XMLDBException { if (getName().equals("/db")) return null; if (parent == null && collection != null) { DBBroker broker = null; --- 225,236 ---- } public String getName() throws XMLDBException { ! return getCollection().getName(); } ! public org.xmldb.api.base.Collection getParentCollection() throws XMLDBException { if (getName().equals("/db")) return null; + Collection collection = getCollection(); if (parent == null && collection != null) { DBBroker broker = null; *************** *** 260,264 **** broker = brokerPool.get(user); org.exist.collections.Collection c = collection.getParent(broker); ! parent = new LocalCollection(user, brokerPool, null, c); } catch (EXistException e) { throw new XMLDBException( --- 238,242 ---- broker = brokerPool.get(user); org.exist.collections.Collection c = collection.getParent(broker); ! parent = new LocalCollection(user, brokerPool, null, c.getName()); } catch (EXistException e) { throw new XMLDBException( *************** *** 274,281 **** public String getPath() throws XMLDBException { ! //if (parent == null) ! return collection.getName(); ! //return (parent.getName().equals("/") ? '/' + collection.getName() : ! // parent.getPath() + '/' + collection.getName()); } --- 252,256 ---- public String getPath() throws XMLDBException { ! return path; } *************** *** 285,288 **** --- 260,264 ---- public Resource getResource(String id) throws XMLDBException { + Collection collection = getCollection(); if (!collection.getPermissions().validate(user, Permission.READ)) throw new XMLDBException( *************** *** 306,309 **** --- 282,286 ---- public int getResourceCount() throws XMLDBException { + Collection collection = getCollection(); if (!collection.getPermissions().validate(user, Permission.READ)) return 0; *************** *** 349,365 **** } - protected boolean hasChildCollection(String name) { - return collection.hasSubcollection(name); - } - public boolean isOpen() throws XMLDBException { return true; } - public boolean isValid() { - return collection != null; - } - public String[] listChildCollections() throws XMLDBException { if (!checkPermissions(Permission.READ)) return new String[0]; --- 326,335 ---- } public boolean isOpen() throws XMLDBException { return true; } public String[] listChildCollections() throws XMLDBException { + Collection collection = getCollection(); if (!checkPermissions(Permission.READ)) return new String[0]; *************** *** 376,379 **** --- 346,350 ---- public String[] listResources() throws XMLDBException { + Collection collection = getCollection(); if (!collection.getPermissions().validate(user, Permission.READ)) return new String[0]; *************** *** 403,406 **** --- 374,378 ---- if (res == null) return; + Collection collection = getCollection(); String name = res.getId(); LOG.debug("removing " + name); *************** *** 431,435 **** } needsSync = true; - load(getPath()); } --- 403,406 ---- *************** *** 453,456 **** --- 424,428 ---- private void storeBinaryResource(LocalBinaryResource res) throws XMLDBException { + Collection collection = getCollection(); DBBroker broker = null; try { *************** *** 473,476 **** --- 445,449 ---- private void storeXMLResource(LocalXMLResource res) throws XMLDBException { + Collection collection = getCollection(); DBBroker broker = null; String name = res.getDocumentId(); *************** *** 506,511 **** } ! public Date getCreationTime() { ! return new Date(collection.getCreationTime()); } --- 479,484 ---- } ! public Date getCreationTime() throws XMLDBException { ! return new Date(getCollection().getCreationTime()); } Index: LocalXMLResource.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/xmldb/LocalXMLResource.java,v retrieving revision 1.30 retrieving revision 1.31 diff -C2 -d -r1.30 -r1.31 *** LocalXMLResource.java 3 Feb 2004 08:33:51 -0000 1.30 --- LocalXMLResource.java 3 May 2004 12:58:11 -0000 1.31 *************** *** 208,211 **** --- 208,212 ---- public void getContentAsSAX(ContentHandler handler) throws XMLDBException { DBBroker broker = null; + // case 1: content is an external DOM node if (root != null && !(root instanceof NodeValue)) { try { *************** *** 221,224 **** --- 222,227 ---- .getMessage(), e); } + + // case 2: content is an atomic value } else if (value != null) { try { *************** *** 234,237 **** --- 237,242 ---- brokerPool.release(broker); } + + // case 3: content is an internal node or a document } else { try { Index: LocalResourceSet.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/xmldb/LocalResourceSet.java,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** LocalResourceSet.java 8 Mar 2004 11:21:22 -0000 1.17 --- LocalResourceSet.java 3 May 2004 12:58:11 -0000 1.18 *************** *** 157,162 **** if (coll == null || p.doc.getCollection() == null ! || coll.collection.getId() != p.doc.getCollection().getId()) { ! coll = new LocalCollection(user, brokerPool, null, p.doc.getCollection()); } res = new LocalXMLResource(user, brokerPool, coll, p); --- 157,162 ---- if (coll == null || p.doc.getCollection() == null ! || coll.getCollection().getId() != p.doc.getCollection().getId()) { ! coll = new LocalCollection(user, brokerPool, null, p.doc.getCollection().getName()); } res = new LocalXMLResource(user, brokerPool, coll, p); |