vgritsenko    2004/03/30 06:01:07

  Modified:    .        status.xml
               java/src/org/apache/xindice/client/xmldb/embed
                        CollectionImpl.java DatabaseImpl.java
               java/tests/src/org/apache/xindice/integration/client
                        XmlDbClient.java
               java/tests/src/org/apache/xindice/integration/client/basic
                        CollectionTest.java
  Log:
  Fix getCanonicalName in embedded collection.
  Fix getParentCollection test - Root collection now always has a name, name of 
the database.
  
  Revision  Changes    Path
  1.41      +3 -0      xml-xindice/status.xml
  
  Index: status.xml
  ===================================================================
  RCS file: /home/cvs/xml-xindice/status.xml,v
  retrieving revision 1.40
  retrieving revision 1.41
  diff -u -r1.40 -r1.41
  --- status.xml        20 Mar 2004 14:02:38 -0000      1.40
  +++ status.xml        30 Mar 2004 14:01:07 -0000      1.41
  @@ -74,6 +74,9 @@
   
       <changes>
           <release version="1.1b4-dev" date="March 4 2004">
  +            <action dev="VG" type="fix">
  +                Fixed embedded Collection's getCanonicalName.
  +            </action>
               <action dev="VG" type="update">
                   Implemented support for MetaData for Binary resources.
               </action>
  
  
  
  1.34      +19 -13    
xml-xindice/java/src/org/apache/xindice/client/xmldb/embed/CollectionImpl.java
  
  Index: CollectionImpl.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xindice/java/src/org/apache/xindice/client/xmldb/embed/CollectionImpl.java,v
  retrieving revision 1.33
  retrieving revision 1.34
  diff -u -r1.33 -r1.34
  --- CollectionImpl.java       24 Feb 2004 03:20:27 -0000      1.33
  +++ CollectionImpl.java       30 Mar 2004 14:01:07 -0000      1.34
  @@ -61,6 +61,8 @@
        * Creates new <code>CollectionImpl</code> instance representing 
connection
        * to server collection.
        *
  +     * @param db Database this collection resides in
  +     * @param collPath Canonical path of this collection (including database 
name)
        * @exception XMLDBException thrown if a connection could not be 
established,
        *            because of URL syntax errors, or connection failure, or if 
no
        *            collection with path <code>collPath</code> could be 
located.
  @@ -69,8 +71,18 @@
           super(collPath);
           this.db = db;
   
  +        // Extract path of the collection within database
  +        String collName = "/";
  +        int colIndex = collPath.indexOf('/', 1);
  +        if (colIndex != -1) {
  +            collName = collPath.substring(colIndex);
  +            if (collName.equals("")) {
  +                collName = "/";
  +            }
  +        }
  +
           try {
  -            this.col = db.getCollection(collPath);
  +            this.col = db.getCollection(collName);
           } catch (Exception e) {
               throw 
FaultCodes.createXMLDBException(ErrorCodes.INVALID_COLLECTION,
                                                     "Collection not available: 
" + collPath, e);
  @@ -288,6 +300,7 @@
        */
       public void close() throws XMLDBException {
           col = null;
  +        // FIXME Should not be necessary here:
           db.flushConfig();
       }
   
  @@ -303,27 +316,20 @@
        *  method has been called on the <code>Collection</code><br />
        */
       public org.xmldb.api.base.Collection getParentCollection() throws 
XMLDBException {
  +
           // If there's only one slash then it's the root.
  -        // Not too sure about the robustness of this code.
  -        if (collPath.equals("/") || collPath.equals("")) {
  +        if (collPath.lastIndexOf("/") == 0) {
               return null;
           }
   
  -        String parent = collPath.substring(0, collPath.lastIndexOf('/'));
  -        if ("".equals(parent)) {
  -            parent = "/";
  -        }
  -
           try {
  -            return new CollectionImpl(db, parent);
  +            return new CollectionImpl(db, collPath.substring(0, 
collPath.lastIndexOf('/')));
           } catch (XMLDBException e) {
               if (e.errorCode == ErrorCodes.NO_SUCH_COLLECTION) {
                   // per getParentCollection contract, return null if no parent
                   return null;
               }
               throw e;
  -        } catch (Exception e) {
  -            throw FaultCodes.createXMLDBException(e);
           }
       }
   
  
  
  
  1.26      +6 -12     
xml-xindice/java/src/org/apache/xindice/client/xmldb/embed/DatabaseImpl.java
  
  Index: DatabaseImpl.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xindice/java/src/org/apache/xindice/client/xmldb/embed/DatabaseImpl.java,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- DatabaseImpl.java 12 Feb 2004 03:12:18 -0000      1.25
  +++ DatabaseImpl.java 30 Mar 2004 14:01:07 -0000      1.26
  @@ -371,22 +371,15 @@
                                        "Invalid URL (collection name must 
start with '/'): " + uri);
           }
   
  -        // find the database name. We just skip the first slash
  +        // Find the database name. We just skip the first slash
           int colIndex = collPath.indexOf('/', 1);
   
           // We assume there's no collection specified
           String dbName = collPath.substring(1);
  -        String colName = "/";
   
  -        // if colIndex isn't -1 then we need to pick out the db and 
collection
  +        // If colIndex isn't -1 then we need to pick out the db name
           if (colIndex != -1) {
               dbName = collPath.substring(1, colIndex);
  -
  -            // The rest of the name locates the collection
  -            colName = collPath.substring(colIndex);
  -            if (colName.equals("")) {
  -                colName = "/";
  -            }
           }
   
           Database database = getDatabase(dbName, uri);
  @@ -394,8 +387,9 @@
               throw new XMLDBException(ErrorCodes.NO_SUCH_DATABASE,
                                        "Database '" + dbName + "' not found. 
URL: " + uri);
           }
  +
           try {
  -            return new CollectionImpl(database, colName);
  +            return new CollectionImpl(database, collPath);
           } catch (XMLDBException e) {
               if (e.errorCode == ErrorCodes.NO_SUCH_COLLECTION) {
                   // Per getCollection contract, return null if not found
  
  
  
  1.18      +2 -18     
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.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- XmlDbClient.java  8 Feb 2004 03:57:02 -0000       1.17
  +++ XmlDbClient.java  30 Mar 2004 14:01:07 -0000      1.18
  @@ -87,22 +87,6 @@
           }
       }
   
  -    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 indexDoc) throws Exception 
{
           createIndexer(path, DOMParser.toDocument(indexDoc));
       }
  
  
  
  1.20      +39 -36    
xml-xindice/java/tests/src/org/apache/xindice/integration/client/basic/CollectionTest.java
  
  Index: CollectionTest.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xindice/java/tests/src/org/apache/xindice/integration/client/basic/CollectionTest.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- CollectionTest.java       4 Mar 2004 13:15:22 -0000       1.19
  +++ CollectionTest.java       30 Mar 2004 14:01:07 -0000      1.20
  @@ -36,6 +36,11 @@
    */
   public class CollectionTest extends AbstractXmlDbClientTest {
   
  +    public void testGetDatabase() throws Exception {
  +        Collection col = 
this.client.getCollection(XmlDbClientSetup.INSTANCE_NAME);
  +        assertNotNull(col);
  +    }
  +
       public void testGetUnknownDatabase() throws Exception {
           try {
               Collection col = this.client.getCollection("doesnotexist");
  @@ -46,37 +51,39 @@
           }
       }
   
  -    // This is just to make sure that the system is up and running.
       public void testListInitialCollections() throws Exception {
  -        String[] collections = 
this.client.listCollections(XmlDbClientSetup.INSTANCE_NAME);
  -        List col = new Vector(Arrays.asList(collections));
  +        Collection db = 
this.client.getCollection(XmlDbClientSetup.INSTANCE_NAME);
  +        String[] collections = db.listChildCollections();
  +        List collist = new Vector(Arrays.asList(collections));
           if (collections.length == 2) {
  -            assertTrue(col.contains(XmlDbClientSetup.TEST_COLLECTION_NAME));
  -            assertTrue(col.contains("system"));
  +            
assertTrue(collist.contains(XmlDbClientSetup.TEST_COLLECTION_NAME));
  +            assertTrue(collist.contains("system"));
           } else if (collections.length == 3) {
  -            assertTrue(col.contains(XmlDbClientSetup.TEST_COLLECTION_NAME));
  -            assertTrue(col.contains("system"));
  -            assertTrue(col.contains("meta"));
  +            
assertTrue(collist.contains(XmlDbClientSetup.TEST_COLLECTION_NAME));
  +            assertTrue(collist.contains("system"));
  +            assertTrue(collist.contains("meta"));
           } else {
               fail("Initial number of collections should be 2, or 3 if meta 
enabled");
           }
       }
   
       public void testCreateNestedCollection() throws Exception {
  -        this.client.createCollection(TEST_COLLECTION_PATH, "nested");
  -        assertEquals(1, this.client.countCollections(TEST_COLLECTION_PATH));
  +        Collection col = this.client.getCollection(TEST_COLLECTION_PATH);
  +
  +        Collection nested = 
this.client.createCollection(TEST_COLLECTION_PATH, "nested");
  +        assertEquals(1, col.getChildCollectionCount());
   
           // Test create collection with path
           this.client.createCollection(TEST_COLLECTION_PATH, "nested/child2", 
"child2");
   
           this.client.createCollection(TEST_COLLECTION_PATH + "/nested", 
"child3");
  -        assertEquals(2, this.client.countCollections(TEST_COLLECTION_PATH + 
"/nested"));
  +        assertEquals(2, nested.getChildCollectionCount());
   
           this.client.dropCollection(TEST_COLLECTION_PATH + "/nested", 
"child2");
  -        assertEquals(1, this.client.countCollections(TEST_COLLECTION_PATH + 
"/nested"));
  +        assertEquals(1, nested.getChildCollectionCount());
   
           this.client.dropCollection(TEST_COLLECTION_PATH + "/nested", 
"child3");
  -        assertEquals(0, this.client.countCollections(TEST_COLLECTION_PATH + 
"/nested"));
  +        assertEquals(0, nested.getChildCollectionCount());
   
           this.client.dropCollection(TEST_COLLECTION_PATH, "nested");
       }
  @@ -158,34 +165,38 @@
       }
   
       public void testGetCollectionCount() throws Exception {
  +        Collection col = this.client.getCollection(TEST_COLLECTION_PATH);
  +
           this.client.createCollection(TEST_COLLECTION_PATH, "count");
  -        assertEquals(1, this.client.countCollections(TEST_COLLECTION_PATH));
  +        assertEquals(1, col.getChildCollectionCount());
   
           this.client.dropCollection(TEST_COLLECTION_PATH, "count");
  -        assertEquals(0, this.client.countCollections(TEST_COLLECTION_PATH));
  +        assertEquals(0, col.getChildCollectionCount());
       }
   
       public void testListCollections() throws Exception {
  -        String[] collections = 
this.client.listCollections(TEST_COLLECTION_PATH);
  +        Collection col = this.client.getCollection(TEST_COLLECTION_PATH);
  +
  +        String[] collections = col.listChildCollections();
           assertEquals(0, collections.length);
   
           this.client.createCollection(TEST_COLLECTION_PATH, "child1");
           this.client.createCollection(TEST_COLLECTION_PATH, "child2");
   
  -        collections = this.client.listCollections(TEST_COLLECTION_PATH);
  +        collections = col.listChildCollections();
           assertEquals(2, collections.length);
  -        List col = new Vector(Arrays.asList(collections));
  -        assertTrue(col.contains("child1"));
  -        assertTrue(col.contains("child2"));
  +        List collist = new Vector(Arrays.asList(collections));
  +        assertTrue(collist.contains("child1"));
  +        assertTrue(collist.contains("child2"));
   
           this.client.dropCollection(TEST_COLLECTION_PATH, "child1");
  -        collections = this.client.listCollections(TEST_COLLECTION_PATH);
  +        collections = col.listChildCollections();
           assertEquals(1, collections.length);
           assertEquals("child2", collections[0]);
   
           this.client.dropCollection(TEST_COLLECTION_PATH, "child2");
   
  -        collections = this.client.listCollections(TEST_COLLECTION_PATH);
  +        collections = col.listChildCollections();
           assertEquals(0, collections.length);
       }
   
  @@ -216,7 +227,10 @@
   
           // Must return root database collection
           assertNotNull(parent);
  -        assertEquals("", parent.getName());
  +        assertEquals("db", parent.getName());
  +
  +        // Database (== root collection) has no parent
  +        assertNull(parent.getParentCollection());
   
           this.client.dropCollection(TEST_COLLECTION_PATH, "childcol");
       }
  @@ -233,17 +247,6 @@
           } catch (XMLDBException e) {
               assertEquals("ErrorCodes.INVALID_COLLECTION", 
ErrorCodes.INVALID_COLLECTION, e.errorCode);
           }
  -    }
  -
  -    public void testChildCollectionCount() throws Exception {
  -        Collection col = this.client.createCollection(TEST_COLLECTION_PATH, 
"childcol");
  -        assertEquals(0, col.getChildCollectionCount());
  -
  -        this.client.createCollection(TEST_COLLECTION_PATH, "colcount");
  -        assertEquals(0, col.getChildCollectionCount());
  -
  -        this.client.dropCollection(TEST_COLLECTION_PATH, "colcount");
  -        assertEquals(0, col.getChildCollectionCount());
       }
   
       public void testClose() throws Exception {
  
  
  

Reply via email to