portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject svn commit: r643121 - /portals/jetspeed-2/portal/trunk/components/jetspeed-rdbms/src/main/java/org/apache/jetspeed/components/datasource/DBCPDatasourceComponent.java
Date Mon, 31 Mar 2008 20:04:50 GMT
Author: ate
Date: Mon Mar 31 13:04:47 2008
New Revision: 643121

URL: http://svn.apache.org/viewvc?rev=643121&view=rev
Log:
Support for using an embedded Derby database multiple times from one JVM by properly shutting
it down after each (test) run

Modified:
    portals/jetspeed-2/portal/trunk/components/jetspeed-rdbms/src/main/java/org/apache/jetspeed/components/datasource/DBCPDatasourceComponent.java

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-rdbms/src/main/java/org/apache/jetspeed/components/datasource/DBCPDatasourceComponent.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-rdbms/src/main/java/org/apache/jetspeed/components/datasource/DBCPDatasourceComponent.java?rev=643121&r1=643120&r2=643121&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-rdbms/src/main/java/org/apache/jetspeed/components/datasource/DBCPDatasourceComponent.java
(original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-rdbms/src/main/java/org/apache/jetspeed/components/datasource/DBCPDatasourceComponent.java
Mon Mar 31 13:04:47 2008
@@ -16,8 +16,12 @@
  */
 package org.apache.jetspeed.components.datasource;
 
+import java.io.CharArrayWriter;
+import java.io.PrintWriter;
 import java.sql.Connection;
+import java.sql.Driver;
 import java.sql.DriverManager;
+import java.util.Properties;
 
 import javax.sql.DataSource;
 
@@ -38,7 +42,8 @@
  * 
  * @
  * @author <a href="mailto:weaver@apache.org">Scott T. Weaver</a>
- * @version $ $
+ * @author <a href="mailto:ate@douma.nu">Ate Douma</a>
+ * @version $Id$
  *
  */
 public class DBCPDatasourceComponent implements DatasourceComponent
@@ -131,14 +136,6 @@
         return dataSource;
     }
 
-    /** 
-     * <p>
-     * start
-     * </p>
-     * 
-     * @see org.picocontainer.Startable#start()
-     * 
-     */
     public void start()
     {
 
@@ -171,33 +168,58 @@
         }
         catch (Throwable e)
         {
-            
-            String msg = "Unable to start DBCPCDatasourceComponent: "+e.toString();
-            log.error(msg, e);
-            throw new IllegalStateException(msg);
+            CharArrayWriter caw = new CharArrayWriter();
+            e.printStackTrace(new PrintWriter(caw));
+            String msg = "Unable to start DBCPCDatasourceComponent: ";
+            log.error(msg+e.toString(), e);
+            throw new IllegalStateException(msg+caw.toString());
         }
     }
 
-    /** 
-     * <p>
-     * stop
-     * </p>
-     * 
-     * @see org.picocontainer.Startable#stop()
-     * 
-     */
     public void stop()
     {
         try
         {
+            log.info("Stopping DBCPCDatasourceComponent");
             dsConnectionFactory.getPool().close();
+
+            // Support for using an embedded Derby database multiple times from one JVM
+            // by properly shutting it down after each (test) run
+            if (driverName.equals("org.apache.derby.jdbc.EmbeddedDriver"))
+            {
+                String shutDownURI = null;
+                int parIndex = connectURI.indexOf(";");
+                if (parIndex > -1)
+                {
+                    shutDownURI = connectURI.substring(0, parIndex)+";shutdown=true";
+                }
+                else
+                {
+                    shutDownURI = connectURI+";shutdown=true";
+                }
+                Class dc = Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
+                Driver driver = (Driver)dc.newInstance();                
+                Properties info = new Properties();
+                info.put( "user", user );
+                info.put( "password", password );
+                
+                driver.connect(shutDownURI, info);
+            }
+
         }
         catch (Exception e)
         {
             IllegalStateException ise =
                 new IllegalStateException("Unable to sfaely shutdown the DBCPConnection pool:
" + e.toString());
             ise.initCause(e);
+            try
+            {
+                log.error(ise);
+            }
+            catch (Exception e1)
+            {
+                // ignore if logger itself is gone too
+            }
         }
     }
-
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org


Mime
View raw message