svn commit: r564832 - in /xml/xindice/trunk/java/src/org/apache/xindice/core: Collection.java CollectionManager.java Container.java DBObject.java Database.java filer/Paged.java indexer/IndexManager.java indexer/MemValueIndexer.java

[email protected]
Newsgroups gmane.text.xml.xindice.devel
Message-ID <[email protected]>
Author: vgritsenko
Date: Fri Aug 10 21:18:09 2007
New Revision: 564832

URL: http://svn.apache.org/viewvc?view=rev&rev=564832
Log:
Removed throws from DBObject.isOpened() method.
Cleanup.

Modified:
    xml/xindice/trunk/java/src/org/apache/xindice/core/Collection.java
    xml/xindice/trunk/java/src/org/apache/xindice/core/CollectionManager.java
    xml/xindice/trunk/java/src/org/apache/xindice/core/Container.java
    xml/xindice/trunk/java/src/org/apache/xindice/core/DBObject.java
    xml/xindice/trunk/java/src/org/apache/xindice/core/Database.java
    xml/xindice/trunk/java/src/org/apache/xindice/core/filer/Paged.java
    xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/IndexManager.java
    xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/MemValueIndexer.java

Modified: xml/xindice/trunk/java/src/org/apache/xindice/core/Collection.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/core/Collection.java?view=diff&rev=564832&r1=564831&r2=564832
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/core/Collection.java (original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/core/Collection.java Fri Aug 10 21:18:09 2007
@@ -209,22 +209,24 @@
     }
 
 
+    private String name;
     private String canonicalName;
+    private Collection parent;
+
     // Object ID Stuff
-    private int collectionId;
+    private final Object oidMutex = new Object();
+    private String oidTemplate;
+    private long documentId;
+
+    private boolean internalSymbols;
+    private SymbolTable symbols;
+
     private File collectionRoot;
     private boolean compressed;
-    private long documentId;
-    private DocumentCache documentCache;
     private Filer filer;
-    private IndexManager indexManager;
     private InlineMetaService inlineMetaService;
-    private boolean internalSymbols;
-    private String name;
-    private final Object oidMutex = new Object();
-    private String oidTemplate;
-    private Collection parent;
-    private SymbolTable symbols;
+    private DocumentCache documentCache;
+    private IndexManager indexManager;
 
     // document keys identity map
     private final Map identityMap = new WeakHashMap();
@@ -235,10 +237,10 @@
     }
 
     /**
-     * @param parentCollection
+     * @param parent parent collection
      */
-    public Collection(Collection parentCollection) {
-        this.parent = parentCollection;
+    public Collection(Collection parent) {
+        this.parent = parent;
     }
 
     private void checkFiler(int faultCode) throws DBException {
@@ -246,17 +248,25 @@
             throw new DBException(faultCode,
                                   "Collection '" + name + "' cannot store resources (no filer)");
         }
+        if (!filer.isOpened()) {
+            throw new DBException(FaultCodes.COL_COLLECTION_CLOSED,
+                                  "Collection '" + name + "' is closed.");
+        }
     }
 
     /**
      * @see org.apache.xindice.core.DBObject#close()
      */
     public boolean close() throws DBException {
+        // Close children collections first
+        super.close();
+
+        // Close its own filer
         if (filer != null) {
             indexManager.close();
             filer.close();
         }
-        super.close();
+
         return true;
     }
 
@@ -272,7 +282,7 @@
     }
 
     /**
-     * @see org.apache.xindice.core.CollectionManager#createCollection(java.lang.String, org.apache.xindice.util.Configuration)
+     * @see CollectionManager#createCollection(String, Configuration)
      */
     public final Collection createCollection(String path, Configuration config) throws DBException {
         Collection col = super.createCollection(path, config);
@@ -348,11 +358,6 @@
      * @see org.apache.xindice.core.DBObject#drop()
      */
     public boolean drop() throws DBException {
-        if (this == getDatabase()) {
-            throw new DBException(FaultCodes.DBE_CANNOT_DROP,
-                                  "You cannot drop the database");
-        }
-
         DBObserver.getInstance().dropCollection(this);
 
         // Drop the meta if necessary
@@ -1050,14 +1055,20 @@
 
     /**
      * Returns whether or not meta data is enabled.
+     *
      * @return boolean whether or not meta data is enabled.
      */
     public boolean isMetaEnabled() {
         return getDatabase().isMetaEnabled();
     }
 
-    public boolean isOpened() throws DBException {
-        return true;
+    public boolean isOpened() {
+        // Collection without filer is always open ... for now.
+        if (filer == null) {
+            return true;
+        }
+
+        return filer.isOpened();
     }
 
     /**
@@ -1421,12 +1432,13 @@
         this.canonicalName = canonicalName;
 
         // Calculate The OID Template
-        collectionId = Math.abs(canonicalName.hashCode());
         StringBuffer sb = new StringBuffer("00000000000000000000000000000000");
         String host = Integer.toString(host_id, 16);
-        String collection = Integer.toString(collectionId, 16);
         sb.insert(8 - host.length(), host);
+
+        String collection = Integer.toString(Math.abs(canonicalName.hashCode()), 16);
         sb.insert(16 - collection.length(), collection);
+        
         sb.setLength(32);
         oidTemplate = sb.toString();
     }
@@ -1516,8 +1528,8 @@
             internalSymbols = (symConfig != null);
             if (internalSymbols) {
                 if (log.isTraceEnabled()) {
-                    log.trace(localDebugHeader
-                              + "Internal symbols=<" + TextWriter.toString(symConfig.getElement()) + ">");
+                    log.trace(localDebugHeader +
+                              "Internal symbols=<" + TextWriter.toString(symConfig.getElement()) + ">");
                 }
 
                 try {

Modified: xml/xindice/trunk/java/src/org/apache/xindice/core/CollectionManager.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/core/CollectionManager.java?view=diff&rev=564832&r1=564831&r2=564832
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/core/CollectionManager.java (original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/core/CollectionManager.java Fri Aug 10 21:18:09 2007
@@ -41,10 +41,11 @@
 
     private static final Log log = LogFactory.getLog(CollectionManager.class);
 
-    private static final String COLLECTION = "collection";
     private static final String COLLECTIONS = "collections";
+    private static final String COLLECTION  = "collection";
+    private static final String NAME        = "name";
+
     private static final String[] EMPTY_STRINGS = new String[0];
-    private static final String NAME = "name";
 
     private final Map collections = Collections.synchronizedMap(new HashMap());
     private Configuration config;
@@ -54,8 +55,7 @@
     }
 
     /**
-     *
-     * @param collection
+     * @param collection a collection to add
      */
     protected void addCollection(Collection collection) {
         this.collections.put(collection.getName(), collection);
@@ -65,6 +65,7 @@
      * Returns number of child collections
      *
      * @return number of collections
+     * @throws DBException never
      */
     public final long countCollections() throws DBException {
         return (long) collections.size();
@@ -77,6 +78,7 @@
      * @param path The relative path of the Collection
      * @param cfg The Collection's configuration
      * @return The newly created Collection
+     * @throws DBException if operation failed
      */
     public Collection createCollection(String path, Configuration cfg) throws DBException {
         if (path == null || "".equals(path)) {
@@ -97,25 +99,19 @@
                     continue;
                 }
 
-                if (st.hasMoreTokens()) {
-                    cm = (CollectionManager) cm.collections.get(path);
-                } else {
+                if (!st.hasMoreTokens()) {
                     return cm.createCollection(path, cfg);
                 }
+                
+                cm = (CollectionManager) cm.collections.get(path);
             }
 
             throw new DBException(FaultCodes.COL_COLLECTION_NOT_FOUND,
                                   "Parent Collection '" + path + "' doesn't exist");
         }
 
-        if (path.indexOf('/') != -1) {
-            throw new DBException(FaultCodes.COL_CANNOT_CREATE, "Name cannot contain '/'");
-        }
-
-        Collection collection = new Collection((Collection) this);
+        // Get collection name and do a check
         String n = cfg.getAttribute(NAME);
-
-        // Do a name check to see if all is well
         if (n == null || n.trim().equals("")) {
             throw new DBException(FaultCodes.COL_CANNOT_CREATE,
                                   "No name specified in collection configuration");
@@ -126,7 +122,8 @@
                                   "Name does not match with path name");
         }
 
-        synchronized(collections) {
+        Collection collection = new Collection((Collection) this);
+        synchronized (collections) {
             try {
                 if (getCollection(n) != null) {
                     throw new DBException(FaultCodes.COL_DUPLICATE_COLLECTION,
@@ -149,6 +146,7 @@
                 throw new DBException(FaultCodes.COL_CANNOT_CREATE,
                                       "Error Creating Collection '" + path + "'", e);
             }
+
             return collection;
         }
     }
@@ -176,6 +174,7 @@
      *
      * @param collection The Collection to drop
      * @return Whether or not the Collection was dropped
+     * @throws DBException if operation failed
      */
     public boolean dropCollection(Collection collection) throws DBException {
         if (collection == null) {
@@ -224,6 +223,7 @@
      *
      * @param path The Collection path
      * @return The Collection (or null)
+     * @throws DBException if operation failed
      */
     public Collection getCollection(String path) throws DBException {
         if (path == null) {
@@ -234,20 +234,25 @@
             CollectionManager cm = this;
             StringTokenizer st = new StringTokenizer(path, "/");
             while (cm != null && st.hasMoreTokens()) {
-                path = st.nextToken();
+                path = st.nextToken().trim();
+                if (path.length() == 0) {
+                    continue;
+                }
+
                 cm = (CollectionManager) cm.collections.get(path);
             }
+
             return (Collection) cm;
-        } else {
-            return (Collection) collections.get(path);
         }
+        
+        return (Collection) collections.get(path);
     }
 
     /**
      * @return The collections map
      */
     protected Map getCollections() {
-        return this.collections;
+        return Collections.unmodifiableMap(this.collections);
     }
 
     /**
@@ -262,9 +267,12 @@
      * Strings.
      *
      * @return The Collection list
+     * @throws DBException never
      */
     public final String[] listCollections() throws DBException {
-        return (String[]) collections.keySet().toArray(EMPTY_STRINGS);
+        synchronized (collections) {
+            return (String[]) collections.keySet().toArray(EMPTY_STRINGS);
+        }
     }
 
     /**

Modified: xml/xindice/trunk/java/src/org/apache/xindice/core/Container.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/core/Container.java?view=diff&rev=564832&r1=564831&r2=564832
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/core/Container.java (original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/core/Container.java Fri Aug 10 21:18:09 2007
@@ -87,4 +87,3 @@
      */
     void commit(Document document) throws DBException;
 }
-

Modified: xml/xindice/trunk/java/src/org/apache/xindice/core/DBObject.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/core/DBObject.java?view=diff&rev=564832&r1=564831&r2=564832
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/core/DBObject.java (original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/core/DBObject.java Fri Aug 10 21:18:09 2007
@@ -36,6 +36,7 @@
      * DBObject, such as disk files, etc.
      *
      * @return Whether or not the DBObject was created
+     * @throws DBException if operation failed
      */
     boolean create() throws DBException;
 
@@ -43,6 +44,7 @@
      * open opens the DBObject
      *
      * @return Whether or not the DBObject was opened
+     * @throws DBException if operation failed
      */
     boolean open() throws DBException;
 
@@ -51,7 +53,7 @@
      *
      * @return The open status of the DBObject
      */
-    boolean isOpened() throws DBException;
+    boolean isOpened();
 
     /**
      * exists returns whether or not a physical representation of this
@@ -60,6 +62,7 @@
      * perform a connection check.
      *
      * @return Whether or not the physical resource exists
+     * @throws DBException if operation failed
      */
     boolean exists() throws DBException;
 
@@ -69,6 +72,7 @@
      * references to the DBObject in its own context.
      *
      * @return Whether or not the DBObject was dropped
+     * @throws DBException if operation failed
      */
     boolean drop() throws DBException;
 
@@ -76,6 +80,7 @@
      * close closes the DBObject
      *
      * @return Whether or not the DBObject was closed
+     * @throws DBException if operation failed
      */
     boolean close() throws DBException;
 }

Modified: xml/xindice/trunk/java/src/org/apache/xindice/core/Database.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/core/Database.java?view=diff&rev=564832&r1=564831&r2=564832
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/core/Database.java (original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/core/Database.java Fri Aug 10 21:18:09 2007
@@ -446,4 +446,16 @@
         // observer
         DBObserver.getInstance().setDatabaseConfig(this, getCollections(), config);
     }
+
+
+    /**
+     * Database can not be dropped.
+     *
+     * @return nothing.
+     * @throws DBException Always throws DBE_CANNOT_DROP fault code.
+     */
+    public boolean drop() throws DBException {
+        throw new DBException(FaultCodes.DBE_CANNOT_DROP,
+                              "You cannot drop the database");
+    }
 }

Modified: xml/xindice/trunk/java/src/org/apache/xindice/core/filer/Paged.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/core/filer/Paged.java?view=diff&rev=564832&r1=564831&r2=564832
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/core/filer/Paged.java (original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/core/filer/Paged.java Fri Aug 10 21:18:09 2007
@@ -666,6 +666,7 @@
                                          "Error closing " + file.getName(), e);
             }
         }
+
         return true;
     }
 

Modified: xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/IndexManager.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/IndexManager.java?view=diff&rev=564832&r1=564831&r2=564832
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/IndexManager.java (original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/IndexManager.java Fri Aug 10 21:18:09 2007
@@ -206,7 +206,7 @@
      */
     public synchronized void close() {
         // wait for all scheduled tasks to finish
-        synchronized(lock) {
+        synchronized (lock) {
             while (taskCount > 0) {
                 try {
                     lock.wait();
@@ -215,6 +215,7 @@
                 }
             }
         }
+
         // close all indexers
         for (Iterator i = indexes.values().iterator(); i.hasNext(); ) {
             Indexer idx = (Indexer) i.next();

Modified: xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/MemValueIndexer.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/MemValueIndexer.java?view=diff&rev=564832&r1=564831&r2=564832
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/MemValueIndexer.java (original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/MemValueIndexer.java Fri Aug 10 21:18:09 2007
@@ -895,7 +895,7 @@
      *
      * @return true if open, false otherwise
      */
-    public synchronized boolean isOpened() throws DBException {
+    public synchronized boolean isOpened() {
         return itsValues != null && itsOpen;
     }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.