You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ddlutils-dev@db.apache.org by to...@apache.org on 2006/06/24 14:33:09 UTC

svn commit: r416907 - in /db/ddlutils/trunk/src: java/org/apache/ddlutils/platform/hsqldb/ java/org/apache/ddlutils/task/ test/org/apache/ddlutils/

Author: tomdz
Date: Sat Jun 24 05:33:09 2006
New Revision: 416907

URL: http://svn.apache.org/viewvc?rev=416907&view=rev
Log:
Added support for the shutdown of (embedded) databases like Hsqldb

Modified:
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/hsqldb/HsqlDbPlatform.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/task/DatabaseTaskBase.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/task/PlatformConfiguration.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteDataToDatabaseCommand.java
    db/ddlutils/trunk/src/test/org/apache/ddlutils/TestDatabaseWriterBase.java

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/hsqldb/HsqlDbPlatform.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/hsqldb/HsqlDbPlatform.java?rev=416907&r1=416906&r2=416907&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/hsqldb/HsqlDbPlatform.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/hsqldb/HsqlDbPlatform.java Sat Jun 24 05:33:09 2006
@@ -17,9 +17,11 @@
  */
 
 import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.Statement;
 import java.sql.Types;
 
-import org.apache.ddlutils.DynaSqlException;
+import org.apache.ddlutils.DdlUtilsException;
 import org.apache.ddlutils.PlatformInfo;
 import org.apache.ddlutils.platform.PlatformImplBase;
 
@@ -86,20 +88,22 @@
     /**
      * {@inheritDoc}
      */
-    public void shutdownDatabase(Connection connection) throws DynaSqlException
+    public void shutdownDatabase(Connection connection)
     {
-        // TODO: Determine whether we're running in embedded mode (from the url ?)
-//        
-//        try
-//        {
-//            Statement stmt = connection.createStatement();
-//
-//            stmt.executeUpdate("SHUTDOWN");
-//            stmt.close();
-//        }
-//        catch (SQLException ex)
-//        {
-//            throw new DynaSqlException(ex);
-//        }
+        Statement stmt = null;
+
+        try
+        {
+            stmt = connection.createStatement();
+            stmt.executeUpdate("SHUTDOWN");
+        }
+        catch (SQLException ex)
+        {
+            throw new DdlUtilsException(ex);
+        }
+        finally
+        {
+            closeStatement(stmt);    
+        }
     }
 }

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/task/DatabaseTaskBase.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/task/DatabaseTaskBase.java?rev=416907&r1=416906&r2=416907&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/task/DatabaseTaskBase.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/task/DatabaseTaskBase.java Sat Jun 24 05:33:09 2006
@@ -130,6 +130,26 @@
     }
 
     /**
+     * Determines whether the database shall be shut down after the task has finished.
+     *
+     * @return <code>true</code> if the database shall be shut down
+     */
+    public boolean isShutdownDatabase()
+    {
+        return _platformConf.isShutdownDatabase();
+    }
+
+    /**
+     * Specifies whether the database shall be shut down after the task has finished.
+     *
+     * @param shutdownDatabase <code>true</code> if the database shall be shut down
+     */
+    public void setShutdownDatabase(boolean shutdownDatabase)
+    {
+        _platformConf.setShutdownDatabase(shutdownDatabase);
+    }
+
+    /**
      * Adds a command.
      * 
      * @param command The command
@@ -223,6 +243,10 @@
         }
         finally
         {
+            if ((getDataSource() != null) && isShutdownDatabase())
+            {
+                getPlatform().shutdownDatabase();
+            }
             // rollback of our classloader change
             Thread.currentThread().setContextClassLoader(sysClassLoader);
         }

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/task/PlatformConfiguration.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/task/PlatformConfiguration.java?rev=416907&r1=416906&r2=416907&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/task/PlatformConfiguration.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/task/PlatformConfiguration.java Sat Jun 24 05:33:09 2006
@@ -36,6 +36,8 @@
     private BasicDataSource _dataSource;
     /** Whether to use delimited SQL identifiers. */
     private boolean _useDelimitedSqlIdentifiers;
+    /** Whether to shutdown the database after the task has finished. */
+    private boolean _shutdownDatabase = false;
     /** The catalog pattern. */
     private String _catalogPattern;
     /** The schema pattern. */
@@ -139,6 +141,26 @@
     public void setUseDelimitedSqlIdentifiers(boolean useDelimitedSqlIdentifiers)
     {
         _useDelimitedSqlIdentifiers = useDelimitedSqlIdentifiers;
+    }
+
+    /**
+     * Determines whether the database shall be shut down after the task has finished.
+     *
+     * @return <code>true</code> if the database shall be shut down
+     */
+    public boolean isShutdownDatabase()
+    {
+        return _shutdownDatabase;
+    }
+
+    /**
+     * Specifies whether the database shall be shut down after the task has finished.
+     *
+     * @param shutdownDatabase <code>true</code> if the database shall be shut down
+     */
+    public void setShutdownDatabase(boolean shutdownDatabase)
+    {
+        _shutdownDatabase = shutdownDatabase;
     }
 
     /**

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteDataToDatabaseCommand.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteDataToDatabaseCommand.java?rev=416907&r1=416906&r2=416907&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteDataToDatabaseCommand.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteDataToDatabaseCommand.java Sat Jun 24 05:33:09 2006
@@ -20,6 +20,7 @@
 import java.util.ArrayList;
 import java.util.Iterator;
 
+import org.apache.commons.lang.exception.ExceptionUtils;
 import org.apache.ddlutils.Platform;
 import org.apache.ddlutils.io.DataReader;
 import org.apache.ddlutils.io.DataToDatabaseSink;
@@ -187,17 +188,18 @@
             try
             {
                 reader.parse(dataFile);
-                task.log("Read data file "+dataFile.getAbsolutePath(), Project.MSG_INFO);
+                task.log("Written data file "+dataFile.getAbsolutePath() + " to database", Project.MSG_INFO);
             }
             catch (Exception ex)
             {
                 if (isFailOnError())
                 {
-                    throw new BuildException("Could not read data file "+dataFile.getAbsolutePath(), ex);
+                    throw new BuildException("Could not parse or write data file "+dataFile.getAbsolutePath(), ex);
                 }
                 else
                 {
-                    task.log("Could not read data file "+dataFile.getAbsolutePath(), Project.MSG_ERR);
+                    task.log("Could not parse or write data file "+dataFile.getAbsolutePath() + ":", Project.MSG_ERR);
+                    task.log(ExceptionUtils.getFullStackTrace(ex));
                 }
             }
         }

Modified: db/ddlutils/trunk/src/test/org/apache/ddlutils/TestDatabaseWriterBase.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/test/org/apache/ddlutils/TestDatabaseWriterBase.java?rev=416907&r1=416906&r2=416907&view=diff
==============================================================================
--- db/ddlutils/trunk/src/test/org/apache/ddlutils/TestDatabaseWriterBase.java (original)
+++ db/ddlutils/trunk/src/test/org/apache/ddlutils/TestDatabaseWriterBase.java Sat Jun 24 05:33:09 2006
@@ -196,17 +196,10 @@
      */
     protected void tearDown() throws Exception
     {
-        try
+        if (_model != null)
         {
-            if (_model != null)
-            {
-                dropDatabase();
-                _model = null;
-            }
-        }
-        finally
-        {
-            getPlatform().shutdownDatabase();
+            dropDatabase();
+            _model = null;
         }
         super.tearDown();
     }