From: Wolfgang M. M. <wol...@us...> - 2004-06-02 11:28:53
|
Update of /cvsroot/exist/eXist-1.0/src/org/exist/xmldb In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2591/src/org/exist/xmldb Modified Files: IndexQueryService.java RemoteIndexQueryService.java CollectionImpl.java RemoteCollectionManagementService.java LocalIndexQueryService.java LocalCollectionManagementService.java Added Files: CollectionManagementServiceImpl.java Log Message: Added support for moving collections or resources, and reindexing collections. Index: LocalCollectionManagementService.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/xmldb/LocalCollectionManagementService.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** LocalCollectionManagementService.java 5 May 2004 11:14:46 -0000 1.9 --- LocalCollectionManagementService.java 2 Jun 2004 11:28:42 -0000 1.10 *************** *** 1,16 **** ! package org.exist.xmldb; import org.exist.EXistException; import org.exist.security.PermissionDeniedException; import org.exist.security.User; import org.exist.storage.BrokerPool; import org.exist.storage.DBBroker; import org.w3c.dom.Document; ! import org.apache.log4j.Category; ! import org.xmldb.api.base.*; ! import org.xmldb.api.modules.CollectionManagementService; ! public class LocalCollectionManagementService implements CollectionManagementService { protected BrokerPool brokerPool; --- 1,40 ---- ! /* ! * eXist Open Source Native XML Database ! * ! * Copyright (C) 2001-04 Wolfgang M. Meier wol...@ex... ! * ! * This program is free software; you can redistribute it and/or modify it ! * under the terms of the GNU Lesser General Public License as published by the ! * Free Software Foundation; either version 2 of the License, or (at your ! * option) any later version. ! * ! * This program is distributed in the hope that it will be useful, but WITHOUT ! * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ! * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License ! * for more details. ! * ! * You should have received a copy of the GNU Lesser General Public License ! * along with this program; if not, write to the Free Software Foundation, ! * Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ! * ! * $Id$ ! */ package org.exist.xmldb; + import org.apache.log4j.Logger; import org.exist.EXistException; + import org.exist.dom.DocumentImpl; import org.exist.security.PermissionDeniedException; import org.exist.security.User; import org.exist.storage.BrokerPool; import org.exist.storage.DBBroker; + import org.exist.util.LockException; import org.w3c.dom.Document; ! import org.xmldb.api.base.Collection; ! import org.xmldb.api.base.ErrorCodes; ! import org.xmldb.api.base.XMLDBException; ! public class LocalCollectionManagementService implements CollectionManagementServiceImpl { ! protected BrokerPool brokerPool; *************** *** 18,23 **** protected User user; ! private static Category LOG = ! Category.getInstance( LocalCollection.class.getName() ); public LocalCollectionManagementService( User user, BrokerPool pool, --- 42,47 ---- protected User user; ! private static Logger LOG = ! Logger.getLogger( LocalCollectionManagementService.class ); public LocalCollectionManagementService( User user, BrokerPool pool, *************** *** 100,103 **** --- 124,191 ---- } + /* (non-Javadoc) + * @see org.exist.xmldb.CollectionManagementServiceImpl#move(org.xmldb.api.base.Collection, org.xmldb.api.base.Collection, java.lang.String) + */ + public void move(String collectionPath, String destinationPath, + String newName) throws XMLDBException { + if(!collectionPath.startsWith("/db")) + collectionPath = parent.getPath() + '/' + collectionPath; + if(!destinationPath.startsWith("/db")) + destinationPath = parent.getPath() + '/' + destinationPath; + DBBroker broker = null; + try { + broker = brokerPool.get(user); + org.exist.collections.Collection collection = broker.getCollection(collectionPath); + if(collection == null) + throw new XMLDBException(ErrorCodes.NO_SUCH_COLLECTION, "Collection " + collectionPath + " not found"); + org.exist.collections.Collection destination = broker.getCollection(destinationPath); + if(destination == null) + throw new XMLDBException(ErrorCodes.NO_SUCH_COLLECTION, "Collection " + destinationPath + " not found"); + broker.moveCollection(collection, destination, newName); + } catch ( EXistException e ) { + e.printStackTrace(); + throw new XMLDBException( ErrorCodes.VENDOR_ERROR, + "failed to move collection " + collectionPath, e ); + } catch ( PermissionDeniedException e ) { + throw new XMLDBException( ErrorCodes.PERMISSION_DENIED, + e.getMessage(), e ); + } catch (LockException e) { + throw new XMLDBException( ErrorCodes.PERMISSION_DENIED, + e.getMessage(), e ); + } finally { + brokerPool.release( broker ); + } + } + + public void moveResource(String resourcePath, String destinationPath, + String newName) throws XMLDBException { + if(!resourcePath.startsWith("/db")) + resourcePath = parent.getPath() + '/' + resourcePath; + if(!destinationPath.startsWith("/db")) + destinationPath = parent.getPath() + '/' + destinationPath; + DBBroker broker = null; + try { + broker = brokerPool.get(user); + DocumentImpl doc = (DocumentImpl)broker.getDocument(resourcePath); + if(doc == null) + throw new XMLDBException(ErrorCodes.NO_SUCH_RESOURCE, "Resource " + resourcePath + " not found"); + org.exist.collections.Collection destination = broker.getCollection(destinationPath); + if(destination == null) + throw new XMLDBException(ErrorCodes.NO_SUCH_COLLECTION, "Collection " + destinationPath + " not found"); + broker.moveResource(doc, destination, newName); + } catch ( EXistException e ) { + e.printStackTrace(); + throw new XMLDBException( ErrorCodes.VENDOR_ERROR, + "failed to move resource " + resourcePath, e ); + } catch ( PermissionDeniedException e ) { + throw new XMLDBException( ErrorCodes.PERMISSION_DENIED, + e.getMessage(), e ); + } catch (LockException e) { + throw new XMLDBException( ErrorCodes.PERMISSION_DENIED, + e.getMessage(), e ); + } finally { + brokerPool.release( broker ); + } + } public void setCollection( Collection parent ) throws XMLDBException { this.parent = (LocalCollection) parent; --- NEW FILE: CollectionManagementServiceImpl.java --- /* * eXist Open Source Native XML Database * Copyright (C) 2001-04 Wolfgang M. Meier * wol...@ex... * http://exist-db.org * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * $Id: CollectionManagementServiceImpl.java,v 1.5 2004/06/02 11:28:42 wolfgang_m Exp $ */ package org.exist.xmldb; import org.xmldb.api.base.XMLDBException; import org.xmldb.api.modules.CollectionManagementService; /** * Extends the {@link org.xmldb.api.modules.CollectionManagementService} * interface with extensions specific to eXist, in particular moving and copying * collections and resources. * * @author wolf */ public interface CollectionManagementServiceImpl extends CollectionManagementService { public void move(String collection, String destination, String newName) throws XMLDBException; public void moveResource(String resourcePath, String destinationPath, String newName) throws XMLDBException; } Index: IndexQueryService.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/xmldb/IndexQueryService.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** IndexQueryService.java 28 May 2004 10:54:13 -0000 1.2 --- IndexQueryService.java 2 Jun 2004 11:28:42 -0000 1.3 *************** *** 1,2 **** --- 1,23 ---- + /* + * eXist Open Source Native XML Database + * + * Copyright (C) 2001-04 Wolfgang M. Meier wol...@ex... + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * $Id$ + */ package org.exist.xmldb; *************** *** 5,12 **** --- 26,53 ---- import org.xmldb.api.base.XMLDBException; + /** + * Provides additional methods related to eXist's indexing system. + * + * @author wolf + * + */ public interface IndexQueryService extends Service { + /** + * Reindex the current collection, i.e. the collection from which + * this service has been retrieved. + * + * @throws XMLDBException + */ public void reindexCollection() throws XMLDBException; + /** + * Reindex the collection specified by its path. + * + * @param collectionPath + * @throws XMLDBException + */ + public void reindexCollection(String collectionPath) throws XMLDBException; + public Occurrences[] getIndexedElements(boolean inclusive) throws XMLDBException; Index: RemoteCollectionManagementService.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/xmldb/RemoteCollectionManagementService.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** RemoteCollectionManagementService.java 21 May 2004 08:32:14 -0000 1.3 --- RemoteCollectionManagementService.java 2 Jun 2004 11:28:42 -0000 1.4 *************** *** 3,14 **** import java.io.IOException; import java.util.Vector; - import org.apache.xmlrpc.*; - import org.w3c.dom.Document; ! import org.xmldb.api.base.*; ! import org.xmldb.api.modules.CollectionManagementService; ! public class RemoteCollectionManagementService implements CollectionManagementService { protected XmlRpcClient client; --- 3,16 ---- import java.io.IOException; import java.util.Vector; ! import org.apache.xmlrpc.XmlRpcClient; ! import org.apache.xmlrpc.XmlRpcException; ! import org.w3c.dom.Document; ! import org.xmldb.api.base.Collection; ! import org.xmldb.api.base.ErrorCodes; ! import org.xmldb.api.base.XMLDBException; ! public class RemoteCollectionManagementService implements CollectionManagementServiceImpl { protected XmlRpcClient client; *************** *** 100,103 **** --- 102,163 ---- } + /* (non-Javadoc) + * @see org.exist.xmldb.CollectionManagementServiceImpl#move(java.lang.String, java.lang.String, java.lang.String) + */ + public void move(String collectionPath, String destinationPath, String newName) throws XMLDBException { + if(!collectionPath.startsWith("/db")) + collectionPath = parent.getPath() + '/' + collectionPath; + if(!destinationPath.startsWith("/db")) + destinationPath = parent.getPath() + '/' + destinationPath; + if(newName == null) { + int p = collectionPath.lastIndexOf(('/')); + newName = collectionPath.substring(p + 1); + } + Vector params = new Vector(); + params.addElement( collectionPath ); + params.addElement( destinationPath ); + params.addElement( newName ); + try { + client.execute( "moveCollection", params ); + } catch ( XmlRpcException xre ) { + throw new XMLDBException( ErrorCodes.VENDOR_ERROR, + xre.getMessage(), + xre ); + } catch ( IOException ioe ) { + throw new XMLDBException( ErrorCodes.VENDOR_ERROR, + ioe.getMessage(), + ioe); + } + } + + /* (non-Javadoc) + * @see org.exist.xmldb.CollectionManagementServiceImpl#moveResource(java.lang.String, java.lang.String, java.lang.String) + */ + public void moveResource(String resourcePath, String destinationPath, String newName) throws XMLDBException { + if(!resourcePath.startsWith("/db")) + resourcePath = parent.getPath() + '/' + resourcePath; + if(!destinationPath.startsWith("/db")) + destinationPath = parent.getPath() + '/' + destinationPath; + if(newName == null) { + int p = resourcePath.lastIndexOf(('/')); + newName = resourcePath.substring(p + 1); + } + Vector params = new Vector(); + params.addElement( resourcePath ); + params.addElement( destinationPath ); + params.addElement( newName ); + try { + client.execute( "moveResource", params ); + } catch ( XmlRpcException xre ) { + throw new XMLDBException( ErrorCodes.VENDOR_ERROR, + xre.getMessage(), + xre ); + } catch ( IOException ioe ) { + throw new XMLDBException( ErrorCodes.VENDOR_ERROR, + ioe.getMessage(), + ioe); + } + } + } Index: LocalIndexQueryService.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/xmldb/LocalIndexQueryService.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** LocalIndexQueryService.java 28 May 2004 10:54:13 -0000 1.6 --- LocalIndexQueryService.java 2 Jun 2004 11:28:42 -0000 1.7 *************** *** 1,2 **** --- 1,23 ---- + /* + * eXist Open Source Native XML Database + * + * Copyright (C) 2001-04 Wolfgang M. Meier wol...@ex... + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * $Id$ + */ package org.exist.xmldb; *************** *** 45,48 **** --- 66,90 ---- } + + /* (non-Javadoc) + * @see org.exist.xmldb.IndexQueryService#reindexCollection(java.lang.String) + */ + public void reindexCollection(String collectionPath) throws XMLDBException { + String path = (collectionPath.startsWith("/db") ? collectionPath : + parent.getPath() + '/' + collectionPath); + DBBroker broker = null; + try { + broker = pool.get(user); + broker.reindex(path); + broker.sync(); + } catch (PermissionDeniedException e) { + throw new XMLDBException(ErrorCodes.PERMISSION_DENIED, e.getMessage(), e); + } catch (EXistException e) { + throw new XMLDBException(ErrorCodes.VENDOR_ERROR, e.getMessage(), e); + } finally { + pool.release(broker); + } + } + /* (non-Javadoc) * @see org.exist.xmldb.IndexQueryService#getIndexedElements(boolean) Index: RemoteIndexQueryService.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/xmldb/RemoteIndexQueryService.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** RemoteIndexQueryService.java 28 May 2004 10:54:13 -0000 1.5 --- RemoteIndexQueryService.java 2 Jun 2004 11:28:42 -0000 1.6 *************** *** 1,6 **** /* ! * RemoteIndexQueryService.java - Mar 28, 2003 * ! * @author wolf */ package org.exist.xmldb; --- 1,22 ---- /* ! * eXist Open Source Native XML Database ! * ! * Copyright (C) 2001-04 Wolfgang M. Meier wol...@ex... * ! * This program is free software; you can redistribute it and/or modify it ! * under the terms of the GNU Lesser General Public License as published by the ! * Free Software Foundation; either version 2 of the License, or (at your ! * option) any later version. ! * ! * This program is distributed in the hope that it will be useful, but WITHOUT ! * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ! * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License ! * for more details. ! * ! * You should have received a copy of the GNU Lesser General Public License ! * along with this program; if not, write to the Free Software Foundation, ! * Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ! * ! * $Id$ */ package org.exist.xmldb; *************** *** 17,26 **** 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 RemoteIndexQueryService implements IndexQueryService { --- 33,36 ---- *************** *** 41,44 **** --- 51,62 ---- } + + /* (non-Javadoc) + * @see org.exist.xmldb.IndexQueryService#reindexCollection(java.lang.String) + */ + public void reindexCollection(String collectionPath) throws XMLDBException { + throw new XMLDBException(ErrorCodes.NOT_IMPLEMENTED); + } + /* (non-Javadoc) * @see org.exist.xmldb.IndexQueryService#getIndexedElements(boolean) Index: CollectionImpl.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/xmldb/CollectionImpl.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** CollectionImpl.java 15 Apr 2004 09:24:16 -0000 1.12 --- CollectionImpl.java 2 Jun 2004 11:28:42 -0000 1.13 *************** *** 1,6 **** /* ! * CollectionImpl.java - Aug 4, 2003 * ! * @author wolf */ package org.exist.xmldb; --- 1,22 ---- /* ! * eXist Open Source Native XML Database ! * ! * Copyright (C) 2001-04 Wolfgang M. Meier wol...@ex... * ! * This program is free software; you can redistribute it and/or modify it ! * under the terms of the GNU Lesser General Public License as published by the ! * Free Software Foundation; either version 2 of the License, or (at your ! * option) any later version. ! * ! * This program is distributed in the hope that it will be useful, but WITHOUT ! * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ! * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License ! * for more details. ! * ! * You should have received a copy of the GNU Lesser General Public License ! * along with this program; if not, write to the Free Software Foundation, ! * Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ! * ! * $Id$ */ package org.exist.xmldb; |