Viner, David wrote:
For the API, I'm not sure what the best way to access it is. I made an XMLRPC api for it, which is how i access it. I can send those classes if you're interested. If you want to go for the Service approach, I'd be all for seeing a prototype. To be honest, I'm not sure which is more "correct".
Ideally, it should be in XML:DB API. Less then ideal case is the extenstion of the API - that's service. Least ideal way is proprietary API. At least that's my opinion.
WRT to prototype - attached (patch includes some other changes as well). Tested with embed driver, xmlrpc is not tested. Comments are welcome!
As for the last mod time and the code you point out, the meta object is constructed if it needs to be, and has its values set if they are missing. Does that make sense? In other words, if the meta object is already there and properly initialized, the created and modified variables are unused.
Does not work for me... All the time returns "now" even when I patched MetaData to include time into serialization / deserialization. You can try it too with attached MyMain program. Output after two runs:
Collection DOES NOT Exist!
Resource DOES NOT Exist!
...
Resource /db/test/MyTest created time: 1059535843558 (Tue Jul 29 23:30:43 EDT 2003)
Resource /db/test/MyTest modified time: 1059535843558 (Tue Jul 29 23:30:43 EDT 2003)
Update Resource!
Resource: <?xml version="1.0"?>
<root><data modified="1059535848565" /></root>
Collection /db/test created time: 0 (Wed Dec 31 19:00:00 EST 1969)
Collection /db/test modified time: 1059535848575 (Tue Jul 29 23:30:48 EDT 2003)
Resource /db/test/MyTest created time: 1059535848605 (Tue Jul 29 23:30:48 EDT 2003)
Resource /db/test/MyTest modified time: 1059535848605 (Tue Jul 29 23:30:48 EDT 2003)
Collection ALREADY Exists!
Resource ALREADY Exists!
Resource: <?xml version="1.0"?>
<root><data modified="1059535848565" /></root>
Resource /db/test/MyTest created time: 1059535870787 (Tue Jul 29 23:31:10 EDT 2003)
Resource /db/test/MyTest modified time: 1059535870787 (Tue Jul 29 23:31:10 EDT 2003)
Update Resource!
Resource: <?xml version="1.0"?>
<root><data modified="1059535875795" /></root>
Collection /db/test created time: 0 (Wed Dec 31 19:00:00 EST 1969)
Collection /db/test modified time: 1059535875815 (Tue Jul 29 23:31:15 EDT 2003)
Resource /db/test/MyTest created time: 1059535875825 (Tue Jul 29 23:31:15 EDT 2003)
Resource /db/test/MyTest modified time: 1059535875825 (Tue Jul 29 23:31:15 EDT 2003)
What do I miss?
However, it appears that the codebase no longer supports the metadata
implementation that I submitted. See the commit comments
http://cvs.apache.org/viewcvs.cgi/xml-xindice/java/src/org/apache/xindice/co
re/Collection.java?rev=1.14&content-type=text/vnd.viewcvs-markup . The
comments for putDocument now read
/** * This is the lowest-level method for storing a record into the backing store. * It does not update non-inline metadata. */ private void putDocument
But this putDocument is not related to MetaData? MetaData is stored just like any other regular XML document - AFAIU.
Vadim
? java/src/org/apache/xindice/client/xmldb/services/MetaService.java Index: java/src/org/apache/xindice/client/xmldb/XindiceCollection.java =================================================================== RCS file: /home/cvspublic/xml-xindice/java/src/org/apache/xindice/client/xmldb/XindiceCollection.java,v retrieving revision 1.8 diff -u -r1.8 XindiceCollection.java --- java/src/org/apache/xindice/client/xmldb/XindiceCollection.java 10 Jul 2003 21:44:44 -0000 1.8 +++ java/src/org/apache/xindice/client/xmldb/XindiceCollection.java 30 Jul 2003 03:42:11 -0000 @@ -61,7 +61,9 @@ import org.apache.xindice.client.xmldb.services.CollectionManagementServiceImpl; import org.apache.xindice.client.xmldb.services.XPathQueryServiceImpl; import org.apache.xindice.client.xmldb.services.XUpdateQueryServiceImpl; +import org.apache.xindice.client.xmldb.services.MetaService; import org.apache.xindice.core.FaultCodes; +import org.apache.xindice.core.meta.MetaData; import org.w3c.dom.*; import org.xmldb.api.base.Collection; @@ -118,6 +120,11 @@ xupdate.setCollection(this); registerService(xupdate); + // TODO if (this.col.isMetaEnabled()) { + MetaService meta = new MetaService(); + meta.setCollection(this); + registerService(meta); + try { CollectionManagementServiceImpl manager = new CollectionManagementServiceImpl(); manager.setCollection(this); @@ -303,7 +310,7 @@ * * @param name The name for new child collection * @return object representing newly created collection - * @exception XMLDBException thrown if collection createion fails for some + * @exception XMLDBException thrown if collection creation fails for some * reason */ public abstract Collection createCollection(String name) throws XMLDBException; @@ -313,7 +320,7 @@ * * @param name The name for new child collection * @return object representing newly created collection - * @exception XMLDBException thrown if collection createion fails for some + * @exception XMLDBException thrown if collection creation fails for some * reason */ public abstract Collection createCollection(String name, Document configuration) throws XMLDBException; @@ -322,7 +329,7 @@ * Removes child collection from this collection * * @param childName name of child collection - * @exception XMLDBException thrown if collection createion fails for some + * @exception XMLDBException thrown if collection creation fails for some * reason */ public abstract void removeCollection(String childName) throws XMLDBException; @@ -358,4 +365,13 @@ */ public abstract void shutdown() throws XMLDBException; + /** + * Returns [EMAIL PROTECTED] MetaData} object for the specified document or the current + * collection + * @param name name of document to get meta, or <code>null</code> to get meta + * of the collection. + * @return Requested meta data object + * @exception XMLDBException thrown if unable to obtain meta information + */ + public abstract MetaData getMetaData(String name) throws XMLDBException; } Index: java/src/org/apache/xindice/client/xmldb/embed/CollectionImpl.java =================================================================== RCS file: /home/cvspublic/xml-xindice/java/src/org/apache/xindice/client/xmldb/embed/CollectionImpl.java,v retrieving revision 1.12 diff -u -r1.12 CollectionImpl.java --- java/src/org/apache/xindice/client/xmldb/embed/CollectionImpl.java 10 Jul 2003 14:32:28 -0000 1.12 +++ java/src/org/apache/xindice/client/xmldb/embed/CollectionImpl.java 30 Jul 2003 03:42:12 -0000 @@ -66,6 +66,7 @@ import org.apache.xindice.core.DBException; import org.apache.xindice.core.Database; import org.apache.xindice.core.FaultCodes; +import org.apache.xindice.core.meta.MetaData; import org.apache.xindice.core.data.NodeSet; import org.apache.xindice.util.Configuration; import org.apache.xindice.xml.NamespaceMap; @@ -80,6 +81,7 @@ import org.xmldb.api.base.XMLDBException; import org.xmldb.api.modules.BinaryResource; import org.xmldb.api.modules.XMLResource; +import org.MetaService; import java.util.Enumeration; import java.util.Hashtable; @@ -148,7 +150,7 @@ } else if (entry instanceof byte[]) { - return new BinaryResourceImpl(id, (byte[]) entry); + return new BinaryResourceImpl(id, entry); } else { throw new XMLDBException(ErrorCodes.UNKNOWN_RESOURCE_TYPE, "Internal error: unexpected type " + entry.getClass().getName()); @@ -597,4 +599,16 @@ } } + public MetaData getMetaData(String id) throws XMLDBException { + try { + if (id == null) { + return col.getCollectionMeta(); + } else { + return col.getDocumentMeta(id); + } + } + catch (Exception e) { + throw FaultCodes.createXMLDBException(e); + } + } } Index: java/src/org/apache/xindice/client/xmldb/embed/DatabaseImpl.java =================================================================== RCS file: /home/cvspublic/xml-xindice/java/src/org/apache/xindice/client/xmldb/embed/DatabaseImpl.java,v retrieving revision 1.12 diff -u -r1.12 DatabaseImpl.java --- java/src/org/apache/xindice/client/xmldb/embed/DatabaseImpl.java 17 Jul 2003 14:33:20 -0000 1.12 +++ java/src/org/apache/xindice/client/xmldb/embed/DatabaseImpl.java 30 Jul 2003 03:42:13 -0000 @@ -120,12 +120,13 @@ protected Configuration loadConfiguration() throws FileNotFoundException, XindiceException, ReadOnlyException { Configuration config; + String configDir = null; String configFile = System.getProperty(Xindice.PROP_XINDICE_CONFIGURATION); if (configFile != null && !configFile.equals("")) { - log.info("Specified configuration file: '" + configFile + "'"); - FileInputStream configXMLFile = new FileInputStream(new File(configFile)); + FileInputStream configXMLFile = new FileInputStream(configFile); config = new Configuration(DOMParser.toDocument(configXMLFile), false); + configDir = new File(configFile).getAbsoluteFile().getParent(); } else { log.info("No configuration file specified, going with the default configuration"); @@ -133,6 +134,24 @@ } config = config.getChild("root-collection", false); + String dbRoot = config.getAttribute(Database.DBROOT, Database.DBROOT_DEFAULT); + if (!new File(dbRoot).isAbsolute()) { + // Let's see if the property was specified. + String home = System.getProperty(Xindice.PROP_XINDICE_DB_HOME); + if (home != null) { + config.setAttribute(Database.DBROOT, home + File.separator + dbRoot); + } + else if (configDir != null) { + config.setAttribute(Database.DBROOT, configDir + File.separator + dbRoot); + } + else { + log.warn("The database configuration file is not specified and there was no " + + Xindice.PROP_XINDICE_DB_HOME + " property set, " + + "so Xindice was unable to determine a database location. " + + "Database will be created relative to the current directory."); + config.setAttribute(Database.DBROOT, new File(".").getAbsolutePath() + File.separator + dbRoot); + } + } return config; } Index: java/src/org/apache/xindice/client/xmldb/xmlrpc/CollectionImpl.java =================================================================== RCS file: /home/cvspublic/xml-xindice/java/src/org/apache/xindice/client/xmldb/xmlrpc/CollectionImpl.java,v retrieving revision 1.24 diff -u -r1.24 CollectionImpl.java --- java/src/org/apache/xindice/client/xmldb/xmlrpc/CollectionImpl.java 14 Jul 2003 21:26:47 -0000 1.24 +++ java/src/org/apache/xindice/client/xmldb/xmlrpc/CollectionImpl.java 30 Jul 2003 03:42:14 -0000 @@ -70,10 +70,12 @@ import org.apache.xindice.client.xmldb.XindiceCollection; import org.apache.xindice.client.xmldb.resources.XMLResourceImpl; import org.apache.xindice.core.FaultCodes; +import org.apache.xindice.core.meta.MetaData; import org.apache.xindice.server.rpc.RPCDefaultMessage; import org.apache.xindice.server.rpc.RPCMessageInterface; import org.apache.xindice.util.SymbolDeserializer; import org.apache.xindice.xml.TextWriter; +import org.apache.xindice.xml.dom.DOMParser; import org.apache.xmlrpc.XmlRpc; import org.apache.xmlrpc.XmlRpcClient; @@ -193,7 +195,6 @@ String xmlrpcURI = "http://" + hostPort + serviceLocation; try { - client = new XmlRpcClient(xmlrpcURI); /* Just check the collection does actually exist */ @@ -206,7 +207,6 @@ } } catch (MalformedURLException e) { - client = null; throw new XMLDBException(ErrorCodes.INVALID_URI, e); } @@ -215,7 +215,6 @@ throw x; // propagate any xmldb exception. } catch (Exception e) { - client = null; throw new XMLDBException(ErrorCodes.NO_SUCH_COLLECTION, "Collection not found: " + collPath, e); } @@ -773,4 +772,24 @@ } } + public MetaData getMetaData(String id) throws XMLDBException { + checkOpen(); + try { + Hashtable params = new Hashtable(); + params.put(RPCDefaultMessage.COLLECTION, collPath); + if (id != null) { + params.put(RPCDefaultMessage.NAME, id); + } + params.put(RPCDefaultMessage.COMPRESSED, "true"); + + Object result = runRemoteCommand(id == null? "GetCollectionMeta" : "GetDocumentMeta", params); + Document metaDoc = DOMParser.toDocument(result.toString()); + MetaData meta = new MetaData(id); + meta.streamFromXML(metaDoc.getDocumentElement(), true); + return meta; + } + catch (Exception e) { + throw FaultCodes.createXMLDBException(e); + } + } } Index: java/src/org/apache/xindice/core/Collection.java =================================================================== RCS file: /home/cvspublic/xml-xindice/java/src/org/apache/xindice/core/Collection.java,v retrieving revision 1.22 diff -u -r1.22 Collection.java --- java/src/org/apache/xindice/core/Collection.java 15 Jul 2003 15:44:35 -0000 1.22 +++ java/src/org/apache/xindice/core/Collection.java 30 Jul 2003 03:42:18 -0000 @@ -253,7 +253,7 @@ protected Collection() {} /** - * + * * @param parentCollection */ public Collection(Collection parentCollection) { @@ -364,9 +364,8 @@ */ public void dispose() { try { - ((Collection) this).close(); - } - catch (Exception e) { + close(); + } catch (Exception e) { log.warn(e); } } @@ -519,7 +518,7 @@ /** * Return the MetaData for this collection. - * + * * If metadata is not enabled in the configuration, the MetaData object * returned will be null. * @return MetaData this collection's metadata. @@ -601,15 +600,15 @@ * @return The Document count */ public final long getDocumentCount() throws DBException { - // a collection in which you are unable to file documents will have no filer - // (for example the root collection). Rather than throwing an exception return + // a collection in which you are unable to file documents will have no filer + // (for example the root collection). Rather than throwing an exception return // a constant result (nothing) return null == filer ? 0 : filer.getRecordCount(); } /** * Return the MetaData object for a document within this collection. - * + * * If metadata is not enabled, the MetaData object returned will be null. * @param id the document whose metadata you want */ @@ -634,7 +633,7 @@ TimeRecord rec = null; if( null == meta || !meta.hasContext() ) rec = getDatabase().getTime(path); - + long created = (null != rec) ? rec.getCreatedTime() : System.currentTimeMillis(); long modified = (null != rec) ? rec.getModifiedTime() : System.currentTimeMillis(); */ @@ -661,8 +660,8 @@ * @return The DocumentSet */ public final DocumentSet getDocumentSet() throws DBException { - // a collection in which you are unable to file documents will have no filer - // (for example the root collection). Rather than throwing an exception return + // a collection in which you are unable to file documents will have no filer + // (for example the root collection). Rather than throwing an exception return // a constant result (nothing) return null == filer ? EMPTY_DOCUMENTSET : new ColDocumentSet(filer.getRecordSet()); } @@ -701,7 +700,7 @@ /* * If the key has a corresponding value in the cache, return it * and save a disk access. - * + * * At some point the current document-centric cache implementation * needs to be converted to an entry cache which can hold both * Document and byte[]. @@ -800,7 +799,7 @@ /** * Return the MetaSystemCollection for the database containing this * collection. - * + * * @return MetaSystemCollection */ private MetaSystemCollection getMetaSystemCollection() //throws DBException @@ -920,7 +919,7 @@ * insertBinary inserts a new binary object into a Xindice Collection. * * @param docKey The document Key - * @param document The document to insert + * @param bytes The document to insert * @throws DBException if inline-metadata is not enabled, the key is * already in the database, or an error occurs while saving. */ @@ -1012,9 +1011,9 @@ * @return the list of document keys */ public final String[] listDocuments() throws DBException { - // a collection in which you are unable to file documents will have no filer - // (for example the root collection). Rather than throwing an exception return - // a constant result (nothing) + // a collection in which you are unable to file documents will have no filer + // (for example the root collection). Rather than throwing an exception return + // a constant result (nothing) if (null == filer) { return EMPTY_STRING_ARRAY; } @@ -1022,8 +1021,8 @@ RecordSet set = filer.getRecordSet(); // todo: what happens if the size if > than the size of an int. - // I'm pretty sure some sort of runtime exception will occur - // in the ArrayList.add method. + // I'm pretty sure some sort of runtime exception will occur + // in the ArrayList.add method. // give a hint to the size of the record set, saves on arraylist array copies. ArrayList temp = new ArrayList((int) filer.getRecordCount()); @@ -1113,7 +1112,7 @@ String localDebugHeader = debugHeader() + "putDocument: docKey=<" + key.toString() + ">: "; - log.debug(localDebugHeader + "document=<" + TextWriter.toString(document).toString() + ">"); + log.debug(localDebugHeader + "document=<" + TextWriter.toString(document) + ">"); checkFiler(FaultCodes.COL_NO_FILER); @@ -1237,8 +1236,8 @@ * @return The resulting NodeSet */ public final NodeSet queryCollection(String style, String query, NamespaceMap nsMap) throws DBException { - // a collection in which you are unable to file documents will have no filer - // (for example the root collection). Rather than throwing an exception return + // a collection in which you are unable to file documents will have no filer + // (for example the root collection). Rather than throwing an exception return // a constant result (nothing) return null == filer ? EMPTY_NODESET : getQueryEngine().query(this, style, query, nsMap, null); } @@ -1334,8 +1333,6 @@ } public void setConfig(Configuration config) throws XindiceException { - super.setConfig(config); - name = config.getAttribute(NAME); compressed = config.getBooleanAttribute(COMPRESSED, true); @@ -1366,8 +1363,13 @@ log.debug(localDebugHeader + "collection root=<" + getCollectionRoot().toString() + ">"); } - if (config.getBooleanAttribute(CACHE, true)) + // Init super now, when collectionRoot is known. Otherwise child collections + // created in unexpected places + super.setConfig(config); + + if (config.getBooleanAttribute(CACHE, true)) { documentCache = getDatabase().getDocumentCache(); + } // If no Filer is defined, skip Symbols and Indexes Configuration filerConfig = config.getChild(FILER); @@ -1451,7 +1453,7 @@ /** * Set the metadata associated with a document within this collection. - * + * * @param id the document name * @param meta the metadata object to be used. */ @@ -1514,8 +1516,7 @@ return; } - if (log.isInfoEnabled()) - log.info("Updating modified time for this collection's meta"); + log.info("Updating modified time for this collection's meta"); long now = System.currentTimeMillis(); if (null == meta) { meta = new MetaData(MetaData.COLLECTION, getCanonicalName(), now, now); @@ -1524,12 +1525,14 @@ // this collection already has a meta. so update its modified time. meta.setContext(0, now); } + try { metacol.setCollectionMeta(this, meta); } catch (DBException e) { - if (log.isWarnEnabled()) + if (log.isWarnEnabled()) { log.warn("Error setting the collection meta. " + e); + } return; } } @@ -1556,7 +1559,7 @@ TimeRecord rec = null; if( null == meta || !meta.hasContext() ) rec = getDatabase().getTime(path); - + long created = (null != rec) ? rec.getCreatedTime() : System.currentTimeMillis(); long modified = (null != rec) ? rec.getModifiedTime() : System.currentTimeMillis(); */ Index: java/src/org/apache/xindice/core/CollectionManager.java =================================================================== RCS file: /home/cvspublic/xml-xindice/java/src/org/apache/xindice/core/CollectionManager.java,v retrieving revision 1.12 diff -u -r1.12 CollectionManager.java --- java/src/org/apache/xindice/core/CollectionManager.java 15 Jul 2003 15:44:35 -0000 1.12 +++ java/src/org/apache/xindice/core/CollectionManager.java 30 Jul 2003 03:42:18 -0000 @@ -79,8 +79,10 @@ private static final String COLLECTION = "collection"; private static final String COLLECTIONS = "collections"; private static final String[] EmptyStrings = new String[0]; + private static Log log = LogFactory.getLog("org.apache.xindice.core"); private static final String NAME = "name"; + private Map collections = new HashMap(); // Collection private Configuration config = null; Index: java/src/org/apache/xindice/core/Database.java =================================================================== RCS file: /home/cvspublic/xml-xindice/java/src/org/apache/xindice/core/Database.java,v retrieving revision 1.21 diff -u -r1.21 Database.java --- java/src/org/apache/xindice/core/Database.java 14 Jul 2003 19:07:14 -0000 1.21 +++ java/src/org/apache/xindice/core/Database.java 30 Jul 2003 03:42:19 -0000 @@ -73,6 +73,7 @@ import org.apache.xindice.util.ConfigurationException; import org.apache.xindice.util.Named; import org.apache.xindice.util.XindiceException; +import org.apache.xindice.server.Xindice; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -83,11 +84,13 @@ public static final String DBROOT = "dbroot"; public static final String NAME = "name"; - public static final String PROP_XINDICE_HOME = "xindice.home"; private static final String QUERYENGINE = "queryengine"; private static final String COLKEY = "database.xml"; private static final String DATABASE = "database"; private static final String METADATA = "use-metadata"; + + public static final String DBROOT_DEFAULT = "./db/"; + private static Log log = LogFactory.getLog("org.apache.xindice.core"); private static final Map databases = new HashMap(); // String to Database @@ -120,8 +123,8 @@ try { database.setConfig(config); } - catch (XindiceException x) { // TODO: Configurable interface should use ConfigurationException instead of XindiceException. - + catch (XindiceException x) { + // TODO: Configurable interface should use ConfigurationException instead of XindiceException. throw new ConfigurationException(x); } @@ -289,13 +292,14 @@ public void setConfig(Configuration config) throws XindiceException { super.setConfig(config); - setName(config.getAttribute(NAME)); + // FIXME: super sets this: setName(config.getAttribute(NAME)); setCanonicalName('/' + getName()); String dbroot = config.getAttribute(DBROOT); File dbrootDir = new File(dbroot); if (!dbrootDir.isAbsolute()) { - dbrootDir = new File(System.getProperty(PROP_XINDICE_HOME), dbroot); + // TODO: Here, DB root already should be absolute. XMLRPC and Embed drivers take care of it. + dbrootDir = new File(System.getProperty(Xindice.PROP_XINDICE_DB_HOME), dbroot); } setCollectionRoot(dbrootDir); log.info("Database points to " + dbrootDir.getAbsolutePath()); @@ -303,11 +307,11 @@ try { Configuration queryCfg = config.getChild(QUERYENGINE); - if (queryCfg != null) + if (queryCfg != null) { this.engine.setConfig(queryCfg); + } } catch (Exception e) { - log.warn(e); } Index: java/src/org/apache/xindice/core/meta/MetaData.java =================================================================== RCS file: /home/cvspublic/xml-xindice/java/src/org/apache/xindice/core/meta/MetaData.java,v retrieving revision 1.2 diff -u -r1.2 MetaData.java --- java/src/org/apache/xindice/core/meta/MetaData.java 3 Jun 2003 02:18:58 -0000 1.2 +++ java/src/org/apache/xindice/core/meta/MetaData.java 30 Jul 2003 03:42:21 -0000 @@ -407,7 +407,7 @@ /** * Copies from another meta data - * @param from the meta to copy from + * @param meta the meta to copy from */ public void copyFrom( final MetaData meta ) { @@ -457,7 +457,8 @@ public final Element streamToXML(Document doc) throws DOMException { - return streamToXML(doc, false); + // TODO: Why false? + return streamToXML(doc, true); } /** @@ -608,7 +609,8 @@ public final void streamFromXML(Element source) throws DOMException { - streamFromXML(source, false); + // TODO: Why false? + streamFromXML(source, true); } /** @@ -638,7 +640,7 @@ Element element = (Element)node; String elementName = element.getNodeName(); - String prefix = element.getPrefix(); + // TODO: Not Used: String prefix = element.getPrefix(); if( systemElemName.equals(elementName) ) { @@ -866,4 +868,3 @@ return buffer.toString(); } } - Index: java/src/org/apache/xindice/server/Xindice.java =================================================================== RCS file: /home/cvspublic/xml-xindice/java/src/org/apache/xindice/server/Xindice.java,v retrieving revision 1.11 diff -u -r1.11 Xindice.java --- java/src/org/apache/xindice/server/Xindice.java 14 Jul 2003 16:20:58 -0000 1.11 +++ java/src/org/apache/xindice/server/Xindice.java 30 Jul 2003 03:42:21 -0000 @@ -65,8 +65,19 @@ public interface Xindice { // Global Property Information + + /** + * System property specyfying location of the xindice CVS checkout. + * Used by the tools to locate configuration file. + */ public static final String PROP_XINDICE_HOME = "xindice.home"; - public static final String PROP_CMD_HOME = "cmd.home"; + + /** + * System property specyfying location of the xindice database. + * If present, this property overrides location determined by the driver. + */ + public static final String PROP_XINDICE_DB_HOME = "xindice.db.home"; + public static final String PROP_XINDICE_CONFIGURATION = "xindice.configuration"; // Version Information Index: java/src/org/apache/xindice/server/XindiceServlet.java =================================================================== RCS file: /home/cvspublic/xml-xindice/java/src/org/apache/xindice/server/XindiceServlet.java,v retrieving revision 1.16 diff -u -r1.16 XindiceServlet.java --- java/src/org/apache/xindice/server/XindiceServlet.java 14 Jul 2003 18:30:55 -0000 1.16 +++ java/src/org/apache/xindice/server/XindiceServlet.java 30 Jul 2003 03:42:22 -0000 @@ -97,8 +97,6 @@ protected Database database; protected XmlRpcServer xmlrpcServer; - private String xmlRpcDriver; - public void destroy() { try { // When the servlet engine goes down we need to close the @@ -136,18 +134,6 @@ } /** - * Return the XML-RPC driver, a classname or shorthand string informing - * the XmlRpc package which SAX parser we wish it to use. [Created for - * unit-testing purposes.] - * - * @returns String containing the classname or shorthand name of the SAX - * parser the XmlRpc package will use. - */ - public String getXmlRpcDriver() { - return xmlRpcDriver; - } - - /** * TODO: verify that if is an error occured, the database will be closed * propertly */ @@ -162,7 +148,6 @@ Configuration rootCollectionConfiguration = configuration.getChild("root-collection"); if (rootCollectionConfiguration == null) { - throw new ConfigurationException("The database configuration is missing the <root-collection> element"); } else { @@ -176,13 +161,12 @@ // the war has not been unpacked. In this case, we throw an exception and // ask the user to specify the location of database root // - String dbRoot = rootCollectionConfiguration.getAttribute(Database.DBROOT, "./db/"); - File dbRootDir = new File(dbRoot); + String dbRoot = rootCollectionConfiguration.getAttribute(Database.DBROOT, Database.DBROOT_DEFAULT); // // If there is no absolute path, we have to perform some checks. // - if (!dbRootDir.isAbsolute()) { + if (!new File(dbRoot).isAbsolute()) { // Stupid hack but spec compliant. // If getRealPath() returns null the war archive has not been unpacked. @@ -190,30 +174,27 @@ String realPath = servletConfig.getServletContext().getRealPath("/WEB-INF"); // Let's see if the property was specified. - String home = System.getProperty("xindice.db.home"); - + String home = System.getProperty(Xindice.PROP_XINDICE_DB_HOME); if (home != null) { - rootCollectionConfiguration.setAttribute(Database.DBROOT, home + System.getProperty("file.separator") + dbRoot); + rootCollectionConfiguration.setAttribute(Database.DBROOT, home + File.separator + dbRoot); } else if (realPath != null) { + String root = realPath + File.separator + dbRoot; log.warn( "The database root directory has been set to " - + realPath - + System.getProperty("file.separator") - + dbRoot + + root + ". Keep in mind that if a war upgrade will take place the database will be lost."); - - rootCollectionConfiguration.setAttribute(Database.DBROOT, realPath + System.getProperty("file.separator") + dbRoot); + rootCollectionConfiguration.setAttribute(Database.DBROOT, root); } else { throw new ConfigurationException( "The database configuration points to a relative path, " - + "but there was no xindice.home property set. " + + "but there was no " + Xindice.PROP_XINDICE_DB_HOME + " property set. " + "Furthermore, the war was not unpacked by the application server " + "so Xindice was unable to find a database location " + "Please check /WEB-INF/system.xml and set an absolute path " + "as the \"dbroot\" attribute of \"root-collection\" " - + "or specify a suitable xindice.db.home system property."); + + "or specify a suitable " + Xindice.PROP_XINDICE_DB_HOME + " system property."); } } Index: java/src/org/apache/xindice/server/rpc/messages/GetDocumentMeta.java =================================================================== RCS file: /home/cvspublic/xml-xindice/java/src/org/apache/xindice/server/rpc/messages/GetDocumentMeta.java,v retrieving revision 1.2 diff -u -r1.2 GetDocumentMeta.java --- java/src/org/apache/xindice/server/rpc/messages/GetDocumentMeta.java 27 Mar 2003 07:05:32 -0000 1.2 +++ java/src/org/apache/xindice/server/rpc/messages/GetDocumentMeta.java 30 Jul 2003 03:42:22 -0000 @@ -90,7 +90,6 @@ */ public Hashtable execute(Hashtable message) throws Exception { Collection col = getCollection( (String) message.get(COLLECTION) ); - Hashtable result = new Hashtable(); if( !col.isMetaEnabled() ) { // meta information is not enabled ! @@ -105,6 +104,7 @@ Document doc = new DocumentImpl(); meta.streamToXML(doc, true); + Hashtable result = new Hashtable(3); result.put( RESULT, TextWriter.toString( doc ) ); return result; }
package org.apache.xindice.client.xmldb.services; /* * The Apache Software License, Version 1.1 * * * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Xindice" and "Apache Software Foundation" must * not be used to endorse or promote products derived from this * software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache", * nor may "Apache" appear in their name, without prior written * permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation and was * originally based on software copyright (c) 1999-2001, The dbXML * Group, L.L.C., http://www.dbxmlgroup.com. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. * * $Id: QueryService.java,v 1.4 2002/11/21 07:44:35 vladimir Exp $ */
import org.apache.xindice.client.xmldb.CommonConfigurable; import org.apache.xindice.client.xmldb.XindiceCollection; import org.apache.xindice.core.meta.MetaData; import org.xmldb.api.base.Collection; import org.xmldb.api.base.Service; import org.xmldb.api.base.XMLDBException; /** * Meta information service. * * @author <a href="mailto:[EMAIL PROTECTED]">Vadim Gritsenko</a> */ public class MetaService extends CommonConfigurable implements Service { /* Collection that this query service should query in */ Collection collection; public String getVersion() { return "1.0"; } public String getName() { return "MetaService"; } public void setCollection(Collection collection) { this.collection = collection; } public MetaData getMetaData() throws XMLDBException { return ((XindiceCollection) collection).getMetaData(null); } public MetaData getMetaData(String id) throws XMLDBException { return ((XindiceCollection) collection).getMetaData(id); } public long getLastModifiedTime() throws XMLDBException { return ((XindiceCollection) collection).getMetaData(null).getLastModifiedTime(); } public long getCreatedTime() throws XMLDBException { return ((XindiceCollection) collection).getMetaData(null).getCreatedTime(); } public long getLastModifiedTime(String name) throws XMLDBException { return ((XindiceCollection) collection).getMetaData(name).getLastModifiedTime(); } public long getCreatedTime(String name) throws XMLDBException { return ((XindiceCollection) collection).getMetaData(name).getCreatedTime(); } }
import org.apache.xerces.dom.DocumentImpl; import org.apache.xindice.client.xmldb.DatabaseImpl; import org.apache.xindice.client.xmldb.services.CollectionManager; import org.apache.xindice.client.xmldb.services.MetaService; import org.apache.xindice.core.meta.MetaData; import org.apache.xindice.xml.TextWriter; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.xmldb.api.DatabaseManager; import org.xmldb.api.base.Collection; import org.xmldb.api.base.XMLDBException; import org.xmldb.api.modules.XMLResource; import java.util.Date; public class MyMain { public static void main(String args[]) { try { System.setProperty("xindice.configuration", "./config/system.xml"); System.setProperty("xindice.db.home", "."); System.setProperty("org.apache.commons.logging.simplelog.defaultlog", "error"); System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog"); org.xmldb.api.base.Database db = new DatabaseImpl(); DatabaseManager.registerDatabase(db); Collection collection = DatabaseManager.getCollection("xmldb:xindice-embed:///db/test"); if (collection == null) { System.out.println("Collection DOES NOT Exist!"); Collection root = DatabaseManager.getCollection("xmldb:xindice-embed:///db"); CollectionManager manager = (CollectionManager)root.getService("CollectionManager", "1.0"); Document doc = new DocumentImpl(); Element colEle = doc.createElement("collection"); colEle.setAttribute("compressed", "false"); colEle.setAttribute("name", "test"); doc.appendChild(colEle); Element filEle = doc.createElement("filer"); filEle.setAttribute("class", "org.apache.xindice.core.filer.BTreeFiler"); colEle.appendChild(filEle); collection = manager.createCollection("test", doc); } else { System.out.println("Collection ALREADY Exists!"); } MetaService metaService = (MetaService)collection.getService("MetaService", "1.0"); XMLResource r = (XMLResource)collection.getResource("MyTest"); if (r == null) { System.out.println("Resource DOES NOT Exist!"); r = (XMLResource)collection.createResource("MyTest", "XMLResource"); r.setContent("<?xml version='1.0'?><root><data/></root>"); collection.storeResource(r); r = (XMLResource)collection.getResource("MyTest"); } else { System.out.println("Resource ALREADY Exists!"); } try { System.out.println("Resource: " + TextWriter.toString(r.getContentAsDOM())); } catch(XMLDBException e) { e.printStackTrace(); } print("Resource", metaService.getMetaData("MyTest")); Thread.sleep(5000L); System.out.println("Update Resource!"); r.setContent("<?xml version='1.0'?><root><data modified='" + System.currentTimeMillis() + "'/></root>"); collection.storeResource(r); System.out.println("Resource: " + TextWriter.toString(r.getContentAsDOM())); print("Collection", metaService.getMetaData()); print("Resource", metaService.getMetaData("MyTest")); } catch(Exception e) { e.printStackTrace(); } } private static void print(String s, MetaData meta) { System.out.println(s + " " + meta.getOwner() + " created time: " + meta.getCreatedTime() + " (" + new Date(meta.getCreatedTime()) + ")"); System.out.println(s + " " + meta.getOwner() + " modified time: " + meta.getLastModifiedTime() + " (" + new Date(meta.getLastModifiedTime()) + ")"); } }