jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1055164 - /jackrabbit/trunk/jackrabbit-webapp/src/main/java/org/apache/jackrabbit/j2ee/DerbyShutdown.java
Date Tue, 04 Jan 2011 19:44:14 GMT
Author: jukka
Date: Tue Jan  4 19:44:14 2011
New Revision: 1055164

URL: http://svn.apache.org/viewvc?rev=1055164&view=rev
Log:
JCR-1301: Trouble undeploying jackrabbit-webapp from Tomcat

Avoid problems in the DerbyShutdown class when Derby is not used.

Modified:
    jackrabbit/trunk/jackrabbit-webapp/src/main/java/org/apache/jackrabbit/j2ee/DerbyShutdown.java

Modified: jackrabbit/trunk/jackrabbit-webapp/src/main/java/org/apache/jackrabbit/j2ee/DerbyShutdown.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-webapp/src/main/java/org/apache/jackrabbit/j2ee/DerbyShutdown.java?rev=1055164&r1=1055163&r2=1055164&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-webapp/src/main/java/org/apache/jackrabbit/j2ee/DerbyShutdown.java
(original)
+++ jackrabbit/trunk/jackrabbit-webapp/src/main/java/org/apache/jackrabbit/j2ee/DerbyShutdown.java
Tue Jan  4 19:44:14 2011
@@ -16,10 +16,11 @@
  */
 package org.apache.jackrabbit.j2ee;
 
+import java.lang.reflect.Method;
 import java.sql.Driver;
 import java.sql.DriverManager;
 import java.sql.SQLException;
-import java.util.Properties;
+import java.util.Enumeration;
 
 import javax.servlet.ServletContextEvent;
 import javax.servlet.ServletContextListener;
@@ -37,19 +38,38 @@ public class DerbyShutdown implements Se
     }
 
     public void contextDestroyed(ServletContextEvent event) {
+        ClassLoader loader = DerbyShutdown.class.getClassLoader();
+
+        // Deregister all JDBC drivers loaded from this webapp
+        Enumeration<Driver> drivers = DriverManager.getDrivers();
+        while (drivers.hasMoreElements()) {
+            Driver driver = drivers.nextElement();
+            // Check if this driver comes from this webapp
+            if (driver.getClass().getClassLoader() == loader) {
+                try {
+                    DriverManager.deregisterDriver(driver);
+                } catch (SQLException ignore) {
+                }
+            }
+        }
+
+        // Explicitly tell Derby to release all remaining resources.
+        // Use reflection to avoid problems when the Derby is not used.
         try {
-            String shutdown = "jdbc:derby:;shutdown=true";
-            // Try to find the Derby JDBC driver
-            Driver driver = DriverManager.getDriver(shutdown);
-            // Check if the Derby driver comes from this webapp
-            if (driver.getClass().getClassLoader()
-                    == DerbyShutdown.class.getClassLoader()) {
-                // Unregister the automatically loaded driver
-                DriverManager.deregisterDriver(driver);
-                // Tell Derby to release all remaining resources
-                driver.connect(shutdown, new Properties());
+            Class<?> monitorClass =
+                loader.loadClass("org.apache.derby.iapi.services.monitor.Monitor");
+            if (monitorClass.getClassLoader() == loader) {
+                Method getMonitorMethod =
+                    monitorClass.getMethod("getMonitor", new Class<?>[0]);
+                Object monitor =
+                    getMonitorMethod.invoke(null, new Object[0]);
+                if (monitor != null) {
+                    Method shutdownMethod =
+                        monitor.getClass().getMethod("shutdown", new Class<?>[0]);
+                    shutdownMethod.invoke(monitor, new Object[0]);
+                }
             }
-        } catch (SQLException ignore) {
+        } catch (Exception ignore) {
         }
     }
 



Mime
View raw message