You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xindice-dev@xml.apache.org by vg...@apache.org on 2007/04/28 01:27:11 UTC

svn commit: r533255 - in /xml/xindice/trunk/java/src/org/apache/xindice: core/CollectionManager.java core/Database.java tools/XMLTools.java

Author: vgritsenko
Date: Fri Apr 27 16:27:10 2007
New Revision: 533255

URL: http://svn.apache.org/viewvc?view=rev&rev=533255
Log:
delay initialization of database till after the lock is obtained.

Modified:
    xml/xindice/trunk/java/src/org/apache/xindice/core/CollectionManager.java
    xml/xindice/trunk/java/src/org/apache/xindice/core/Database.java
    xml/xindice/trunk/java/src/org/apache/xindice/tools/XMLTools.java

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=533255&r1=533254&r2=533255
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/core/CollectionManager.java (original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/core/CollectionManager.java Fri Apr 27 16:27:10 2007
@@ -155,8 +155,8 @@
 
     public boolean close() throws DBException {
         synchronized (collections) {
-            for(Iterator i = collections.values().iterator(); i.hasNext(); ) {
-                Collection collection = (Collection)i.next();
+            for (Iterator i = collections.values().iterator(); i.hasNext(); ) {
+                Collection collection = (Collection) i.next();
                 try {
                     collection.close();
                 } catch (DBException e) {

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=533255&r1=533254&r2=533255
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/core/Database.java (original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/core/Database.java Fri Apr 27 16:27:10 2007
@@ -76,33 +76,31 @@
      * name if one has already been loaded, otherwise it will
      * create a new instance.
      *
-     * @param config
-     * @return Database
+     * @param config Database configuration
+     * @return Database instance
      * @throws ConfigurationException if database name is missing in the configuration
      */
     public static Database getDatabase(Configuration config) {
-
         String name = config.getAttribute(Database.NAME);
 
         // No name in the config file ... can't get the database
-        if (null == name) {
+        if (name == null) {
             throw new ConfigurationException("Database configuration didn't contain a database name");
         }
 
         Database database = (Database) databases.get(name);
-        if (null == database) {
+        if (database == null) {
             // In case it's currently being added (only pay the sync hit on a miss)
             synchronized (databases) {
                 // Was it created while we waited?
                 database = (Database) databases.get(name);
-                if (null == database) {
+                if (database == null) {
                     database = new Database();
-
                     try {
                         database.setConfig(config);
                     } catch (XindiceException x) {
-                        // TODO: Configurable interface should use ConfigurationException instead of XindiceException.
-                        throw new ConfigurationException(x);
+                        // TODO: Configurable interface should use ConfigurationException instead of XindiceException... Right?
+                        throw new ConfigurationException("XindiceException: " + x.getMessage(), x);
                     }
 
                     databases.put(database.getName(), database);
@@ -115,15 +113,14 @@
 
     /**
      * This will merely return an instance of a Database for the given
-     *     name if one has already been loaded.
+     * name if one has already been loaded.
      *
-     * @param name
+     * @param name Database name
      * @return Database
      */
     public static Database getDatabase(String name) {
-
         Database database = (Database) databases.get(name);
-        if (null == database) {
+        if (database == null) {
             // in case it's currently being added (only pay the sync hit on a miss)
             synchronized (databases) {
                 database = (Database) databases.get(name);
@@ -160,11 +157,9 @@
 
     public Database() {
         super();
-        this.docCache = new DocumentCache();
-        this.engine = new QueryEngine(this);
-        shutdownHandler.registerDatabase(this);
-        timer = new Timer(false);
-        closed = false;
+        docCache = new DocumentCache();
+        engine = new QueryEngine(this);
+        closed = true;
     }
 
     /**
@@ -172,9 +167,10 @@
      * twice.
      *
      * @param removeFromShutdown If true removes its self from the shutdown hook
+     * @return true if closed
+     * @throws DBException if unable to close
      */
     protected synchronized boolean close(boolean removeFromShutdown) throws DBException {
-
         if (removeFromShutdown) {
             // we have already been closed so no need to do this again.
             shutdownHandler.removeDatabase(this);
@@ -283,6 +279,7 @@
 
     /**
      * Return database's timer instance.
+     * @return Database timer instance
      */
     protected Timer getTimer() {
         return timer;
@@ -348,11 +345,16 @@
                                        "Exception: " + e);
         }
 
+        // Now we are ready to open it up
+        shutdownHandler.registerDatabase(this);
+        timer = new Timer(false);
+        closed = false;
+
         // Initialize query engine
         try {
             Configuration queryCfg = config.getChild(QUERYENGINE);
             if (queryCfg != null) {
-                this.engine.setConfig(queryCfg);
+                engine.setConfig(queryCfg);
             }
         } catch (Exception e) {
             if (log.isWarnEnabled()) {

Modified: xml/xindice/trunk/java/src/org/apache/xindice/tools/XMLTools.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/tools/XMLTools.java?view=diff&rev=533255&r1=533254&r2=533255
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/tools/XMLTools.java (original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/tools/XMLTools.java Fri Apr 27 16:27:10 2007
@@ -269,39 +269,39 @@
             }
         }
 
-        if (commandClass != null) {
-        	Command command;
-        	try {
-                // Register Xindice Database with xml:db
-                DatabaseImpl db = new DatabaseImpl();
-                DatabaseManager.registerDatabase(db);
+        if (commandClass == null) {
+            throw new IllegalArgumentException("\"" + action +  "\" not recognized.");
+        }
 
-                // Execute command class
-                command = (Command) Class.forName(commandClass).newInstance();
-                command.execute(table);
+        Command command;
+        try {
+            // Register Xindice Database with XML:DB
+            DatabaseImpl db = new DatabaseImpl();
+            DatabaseManager.registerDatabase(db);
 
-                return true;
-            } catch (XMLDBException e) {
-                System.err.println("XMLDB Exception " + e.errorCode + ": " + e.getMessage());
-                if (isVerbose()) {
-                    e.printStackTrace(System.err);
-                }
-                return false;
-            } catch (Exception e) {
-                System.err.println("ERROR : " + e.getMessage());
-                if (isVerbose()) {
-                    e.printStackTrace(System.err);
-                }
-                return false;
-            } finally {
-                // Close Database
-                if ("true".equals(table.get(LOCAL))) {
-                    command = new org.apache.xindice.tools.command.Shutdown();
-                    command.execute(table);
-                }
+            // Execute command class
+            command = (Command) Class.forName(commandClass).newInstance();
+            command.execute(table);
+
+            return true;
+        } catch (XMLDBException e) {
+            System.err.println("XMLDB Exception " + e.errorCode + ": " + e.getMessage());
+            if (isVerbose()) {
+                e.printStackTrace(System.err);
+            }
+            return false;
+        } catch (Exception e) {
+            System.err.println("ERROR : " + e.getMessage());
+            if (isVerbose()) {
+                e.printStackTrace(System.err);
+            }
+            return false;
+        } finally {
+            // Close Database
+            if ("true".equals(table.get(LOCAL))) {
+                command = new org.apache.xindice.tools.command.Shutdown();
+                command.execute(table);
             }
-        } else {
-            throw new IllegalArgumentException("\"" + action +  "\" not recognized.");
         }
     }