vgritsenko 2003/08/08 15:45:28
Modified: java/tests/src/org/apache/xindice/integration/client
XmlDbClient.java XmlDbClientSetup.java
Log:
reformat code
Revision Changes Path
1.10 +158 -159
xml-xindice/java/tests/src/org/apache/xindice/integration/client/XmlDbClient.java
Index: XmlDbClient.java
===================================================================
RCS file:
/home/cvs/xml-xindice/java/tests/src/org/apache/xindice/integration/client/XmlDbClient.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- XmlDbClient.java 8 Aug 2003 22:44:25 -0000 1.9
+++ XmlDbClient.java 8 Aug 2003 22:45:28 -0000 1.10
@@ -62,6 +62,7 @@
import org.apache.xindice.client.xmldb.services.CollectionManager;
import org.apache.xindice.util.XindiceException;
import org.apache.xindice.xml.dom.DOMParser;
+
import org.w3c.dom.Document;
import org.xml.sax.ContentHandler;
import org.xmldb.api.DatabaseManager;
@@ -74,137 +75,135 @@
*/
public class XmlDbClient {
- protected String driver;
+ protected String driver;
+
+ public XmlDbClient(String driver) throws Exception {
+ this.driver = driver;
+ }
+
+ public String getName(String path) throws Exception {
+ Collection col = DatabaseManager.getCollection(driver + "/" + path);
+ if (col == null) {
+ throw new XindiceException("DatabaseManager.getCollection(" +
driver + "/" + path + ") returned null");
+ }
+ return col.getName();
+ }
+
+ public Collection createCollection(String path, String name) throws
Exception {
+ Collection col = DatabaseManager.getCollection(driver + "/" + path);
+ if (col == null) {
+ throw new XindiceException("DatabaseManager.getCollection(" +
driver + "/" + path + ") returned null");
+ }
+ CollectionManager service = (CollectionManager)
col.getService("CollectionManager", "1.0");
+
+ String collectionConfig
+ = "<collection compressed=\"true\" name=\"" + name + "\">"
+ + " <filer
class=\"org.apache.xindice.core.filer.BTreeFiler\" gzip=\"true\"/>"
+ + "</collection>";
+ return service.createCollection(name,
DOMParser.toDocument(collectionConfig));
+ }
+
+ public Collection createCollection(String path, String name, Document
configuration) throws Exception {
+ Collection col = DatabaseManager.getCollection(driver + "/" + path);
+ if (col == null) {
+ throw new XindiceException("DatabaseManager.getCollection(" +
driver + "/" + path + ") returned null");
+ }
+ CollectionManager service = (CollectionManager)
col.getService("CollectionManager", "1.0");
+ return service.createCollection(name, configuration);
+ }
+
+ public Collection getCollection(String path) throws Exception {
+ return DatabaseManager.getCollection(driver + "/" + path);
+ }
+
+ public void dropCollection(String path, String name) throws Exception {
+ Collection col = DatabaseManager.getCollection(driver + "/" + path);
+
+ if (col != null) {
+ CollectionManager service = (CollectionManager)
col.getService("CollectionManager", "1.0");
+ service.dropCollection(name);
+ }
+ }
+
+ public String[] listCollections(String path) throws Exception {
+ Collection col = DatabaseManager.getCollection(driver + "/" + path);
+ if (col == null) {
+ throw new XindiceException("DatabaseManager.getCollection(" +
driver + "/" + path + ") returned null");
+ }
+ return col.listChildCollections();
+ }
+
+ public int countCollections(String path) throws Exception {
+ Collection col = DatabaseManager.getCollection(driver + "/" + path);
+ if (col == null) {
+ throw new XindiceException("DatabaseManager.getCollection(" +
driver + "/" + path + ") returned null");
+ }
+ return col.getChildCollectionCount();
+ }
+
+ public void createIndexer(String path, String name, String indexdef)
throws Exception {
+ Collection col = DatabaseManager.getCollection(driver + "/" + path);
+ if (col == null) {
+ throw new XindiceException("DatabaseManager.getCollection(" +
driver + "/" + path + ") returned null");
+ }
+ CollectionManager service = (CollectionManager)
col.getService("CollectionManager", "1.0");
+
+ service.createIndexer(DOMParser.toDocument(indexdef));
+ }
+
+ public String[] listIndexes(String path) throws Exception {
+ Collection col = DatabaseManager.getCollection(driver + "/" + path);
+ if (col == null) {
+ throw new XindiceException("DatabaseManager.getCollection(" +
driver + "/" + path + ") returned null");
+ }
+ CollectionManager service = (CollectionManager)
col.getService("CollectionManager", "1.0");
+
+ return service.listIndexers();
+ }
+
+ public void dropIndexer(String path, String name) throws Exception {
+ Collection col = DatabaseManager.getCollection(driver + "/" + path);
+ if (col == null) {
+ throw new XindiceException("DatabaseManager.getCollection(" +
driver + "/" + path + ") returned null");
+ }
+ CollectionManager service = (CollectionManager)
col.getService("CollectionManager", "1.0");
- public XmlDbClient(String driver) throws Exception {
- this.driver = driver;
- }
-
- public String getName(String path) throws Exception {
- Collection col = DatabaseManager.getCollection(driver + "/" +
path);
- if (col == null) {
- throw new
XindiceException("DatabaseManager.getCollection(" + driver + "/" + path + ")
returned null");
- }
- return col.getName();
- }
-
- public Collection createCollection(String path, String name) throws
Exception {
- Collection col = DatabaseManager.getCollection(driver + "/" +
path);
- if (col == null) {
- throw new
XindiceException("DatabaseManager.getCollection(" + driver + "/" + path + ")
returned null");
- }
- CollectionManager service = (CollectionManager)
col.getService("CollectionManager", "1.0");
-
- String collectionConfig =
- "<collection compressed=\"true\" name=\""
- + name
- + "\">"
- + " <filer
class=\"org.apache.xindice.core.filer.BTreeFiler\" gzip=\"true\"/>"
- + "</collection>";
- return service.createCollection(name,
DOMParser.toDocument(collectionConfig));
- }
-
- public Collection createCollection(String path, String name, Document
configuration) throws Exception {
- Collection col = DatabaseManager.getCollection(driver + "/" +
path);
- if (col == null) {
- throw new
XindiceException("DatabaseManager.getCollection(" + driver + "/" + path + ")
returned null");
- }
- CollectionManager service = (CollectionManager)
col.getService("CollectionManager", "1.0");
- return service.createCollection(name, configuration);
- }
-
- public Collection getCollection(String path) throws Exception {
- return DatabaseManager.getCollection(driver + "/" + path);
- }
-
- public void dropCollection(String path, String name) throws Exception {
- Collection col = DatabaseManager.getCollection(driver + "/" +
path);
-
- if (col != null) {
- CollectionManager service = (CollectionManager)
col.getService("CollectionManager", "1.0");
- service.dropCollection(name);
- }
- }
-
- public String[] listCollections(String path) throws Exception {
- Collection col = DatabaseManager.getCollection(driver + "/" +
path);
- if (col == null) {
- throw new
XindiceException("DatabaseManager.getCollection(" + driver + "/" + path + ")
returned null");
- }
- return col.listChildCollections();
- }
-
- public int countCollections(String path) throws Exception {
- Collection col = DatabaseManager.getCollection(driver + "/" +
path);
- if (col == null) {
- throw new
XindiceException("DatabaseManager.getCollection(" + driver + "/" + path + ")
returned null");
- }
- return col.getChildCollectionCount();
- }
-
- public void createIndexer(String path, String name, String indexdef)
throws Exception {
- Collection col = DatabaseManager.getCollection(driver + "/" +
path);
- if (col == null) {
- throw new
XindiceException("DatabaseManager.getCollection(" + driver + "/" + path + ")
returned null");
- }
- CollectionManager service = (CollectionManager)
col.getService("CollectionManager", "1.0");
-
- service.createIndexer(DOMParser.toDocument(indexdef));
- }
-
- public String[] listIndexes(String path) throws Exception {
- Collection col = DatabaseManager.getCollection(driver + "/" +
path);
- if (col == null) {
- throw new
XindiceException("DatabaseManager.getCollection(" + driver + "/" + path + ")
returned null");
- }
- CollectionManager service = (CollectionManager)
col.getService("CollectionManager", "1.0");
-
- return service.listIndexers();
- }
-
- public void dropIndexer(String path, String name) throws Exception {
- Collection col = DatabaseManager.getCollection(driver + "/" +
path);
- if (col == null) {
- throw new
XindiceException("DatabaseManager.getCollection(" + driver + "/" + path + ")
returned null");
- }
- CollectionManager service = (CollectionManager)
col.getService("CollectionManager", "1.0");
-
- service.dropIndexer(name);
- }
-
- public void insertDocument(String path, String name, String doc) throws
Exception {
- Collection col = DatabaseManager.getCollection(driver + "/" +
path);
- if (col == null) {
- throw new
XindiceException("DatabaseManager.getCollection(" + driver + "/" + path + ")
returned null");
- }
-
- XMLResource document = (XMLResource) col.createResource(name,
"XMLResource");
- document.setContent(doc);
- col.storeResource(document);
- }
-
- public int countDocument(String path) throws Exception {
- Collection col = DatabaseManager.getCollection(driver + "/" +
path);
- if (col == null) {
- throw new
XindiceException("DatabaseManager.getCollection(" + driver + "/" + path + ")
returned null");
- }
-
- return col.getResourceCount();
- }
-
- public String getDocument(String path, String name) throws Exception {
- Collection col = DatabaseManager.getCollection(driver + "/" +
path);
- if (col == null) {
- throw new
XindiceException("DatabaseManager.getCollection(" + driver + "/" + path + ")
returned null");
- }
- XMLResource document = (XMLResource) col.getResource(name);
-
- if (document == null) {
- return null;
- }
+ service.dropIndexer(name);
+ }
- return document.getContent().toString();
- }
+ public void insertDocument(String path, String name, String doc) throws
Exception {
+ Collection col = DatabaseManager.getCollection(driver + "/" + path);
+ if (col == null) {
+ throw new XindiceException("DatabaseManager.getCollection(" +
driver + "/" + path + ") returned null");
+ }
+
+ XMLResource document = (XMLResource) col.createResource(name,
"XMLResource");
+ document.setContent(doc);
+ col.storeResource(document);
+ }
+
+ public int countDocument(String path) throws Exception {
+ Collection col = DatabaseManager.getCollection(driver + "/" + path);
+ if (col == null) {
+ throw new XindiceException("DatabaseManager.getCollection(" +
driver + "/" + path + ") returned null");
+ }
+
+ return col.getResourceCount();
+ }
+
+ public String getDocument(String path, String name) throws Exception {
+ Collection col = DatabaseManager.getCollection(driver + "/" + path);
+ if (col == null) {
+ throw new XindiceException("DatabaseManager.getCollection(" +
driver + "/" + path + ") returned null");
+ }
+ XMLResource document = (XMLResource) col.getResource(name);
+
+ if (document == null) {
+ return null;
+ }
+
+ return document.getContent().toString();
+ }
public void updateDocument(String path, String name, String doc) throws
Exception {
Collection col = DatabaseManager.getCollection(driver + "/" + path);
@@ -216,33 +215,33 @@
col.storeResource(document);
}
- public void getDocumentAsSax(String path, String name, ContentHandler
handler) throws Exception {
- Collection col = DatabaseManager.getCollection(driver + "/" +
path);
- if (col == null) {
- throw new
XindiceException("DatabaseManager.getCollection(" + driver + "/" + path + ")
returned null");
- }
- XMLResource document = (XMLResource) col.getResource(name);
-
- if (document == null) {
- return;
- }
-
- document.getContentAsSAX(handler);
- }
-
-
- public String[] listDocuments(String path) throws Exception {
- Collection col = DatabaseManager.getCollection(driver + "/" +
path);
- return col.listResources();
- }
-
- public void removeDocument(String path, String name) throws Exception {
- Collection col = DatabaseManager.getCollection(driver + "/" +
path);
- if (col == null) {
- throw new
XindiceException("DatabaseManager.getCollection(" + driver + "/" + path + ")
returned null");
- }
- XMLResource document = (XMLResource) col.getResource(name);
+ public void getDocumentAsSax(String path, String name, ContentHandler
handler) throws Exception {
+ Collection col = DatabaseManager.getCollection(driver + "/" + path);
+ if (col == null) {
+ throw new XindiceException("DatabaseManager.getCollection(" +
driver + "/" + path + ") returned null");
+ }
+ XMLResource document = (XMLResource) col.getResource(name);
+
+ if (document == null) {
+ return;
+ }
+
+ document.getContentAsSAX(handler);
+ }
+
- col.removeResource(document);
- }
+ public String[] listDocuments(String path) throws Exception {
+ Collection col = DatabaseManager.getCollection(driver + "/" + path);
+ return col.listResources();
+ }
+
+ public void removeDocument(String path, String name) throws Exception {
+ Collection col = DatabaseManager.getCollection(driver + "/" + path);
+ if (col == null) {
+ throw new XindiceException("DatabaseManager.getCollection(" +
driver + "/" + path + ") returned null");
+ }
+ XMLResource document = (XMLResource) col.getResource(name);
+
+ col.removeResource(document);
+ }
}
1.6 +32 -33
xml-xindice/java/tests/src/org/apache/xindice/integration/client/XmlDbClientSetup.java
Index: XmlDbClientSetup.java
===================================================================
RCS file:
/home/cvs/xml-xindice/java/tests/src/org/apache/xindice/integration/client/XmlDbClientSetup.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- XmlDbClientSetup.java 8 Aug 2003 22:44:25 -0000 1.5
+++ XmlDbClientSetup.java 8 Aug 2003 22:45:28 -0000 1.6
@@ -61,7 +61,6 @@
import junit.framework.Test;
import junit.framework.TestSuite;
-
import junitx.extensions.TestSetup;
/**
@@ -70,37 +69,37 @@
*/
public class XmlDbClientSetup extends TestSetup {
- static public final String INSTANCE_NAME = "db";
- static public final String TEST_COLLECTION_NAME = "testing";
+ static public final String INSTANCE_NAME = "db";
+ static public final String TEST_COLLECTION_NAME = "testing";
- private XmlDbClient client;
+ private XmlDbClient client;
- public XmlDbClientSetup(Test test,
- XmlDbClient client) {
- super(test);
- this.client = client;
- }
-
- public void setUp() throws Exception {
-
- this.client.createCollection(INSTANCE_NAME, TEST_COLLECTION_NAME);
-
- // now we set all tests with the client
- // we have an TestSuite of TestSuite of AbstractXmlDbClientTest :-)
- TestSuite suite = (TestSuite) fTest;
- for (int ii = 0; ii < suite.testCount(); ii++) {
- TestSuite subSuite = (TestSuite) suite.testAt(ii);
- for (int jj = 0; jj < subSuite.testCount(); jj++) {
- Object obj = subSuite.testAt(jj);
- if (obj instanceof AbstractXmlDbClientTest) {
- AbstractXmlDbClientTest test = (AbstractXmlDbClientTest) obj;
- test.setXmlDbClient(this.client);
+ public XmlDbClientSetup(Test test,
+ XmlDbClient client) {
+ super(test);
+ this.client = client;
+ }
+
+ public void setUp() throws Exception {
+
+ this.client.createCollection(INSTANCE_NAME, TEST_COLLECTION_NAME);
+
+ // now we set all tests with the client
+ // we have an TestSuite of TestSuite of AbstractXmlDbClientTest :-)
+ TestSuite suite = (TestSuite) fTest;
+ for (int ii = 0; ii < suite.testCount(); ii++) {
+ TestSuite subSuite = (TestSuite) suite.testAt(ii);
+ for (int jj = 0; jj < subSuite.testCount(); jj++) {
+ Object obj = subSuite.testAt(jj);
+ if (obj instanceof AbstractXmlDbClientTest) {
+ AbstractXmlDbClientTest test = (AbstractXmlDbClientTest)
obj;
+ test.setXmlDbClient(this.client);
+ }
}
- }
- }
- }
-
- public void tearDown() throws Exception {
- this.client.dropCollection(INSTANCE_NAME, TEST_COLLECTION_NAME);
- }
+ }
+ }
+
+ public void tearDown() throws Exception {
+ this.client.dropCollection(INSTANCE_NAME, TEST_COLLECTION_NAME);
+ }
}