jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1055168 - in /jackrabbit/branches/2.2: ./ jackrabbit-webapp/src/main/java/org/apache/jackrabbit/j2ee/DerbyShutdown.java jackrabbit-webapp/src/main/webapp/WEB-INF/web.xml
Date Tue, 04 Jan 2011 19:54:03 GMT
Author: jukka
Date: Tue Jan  4 19:54:03 2011
New Revision: 1055168

URL: http://svn.apache.org/viewvc?rev=1055168&view=rev
Log:
2.2: Merged revisions 1055134 and 1055164 (JCR-1301)

Modified:
    jackrabbit/branches/2.2/   (props changed)
    jackrabbit/branches/2.2/jackrabbit-webapp/src/main/java/org/apache/jackrabbit/j2ee/DerbyShutdown.java
    jackrabbit/branches/2.2/jackrabbit-webapp/src/main/webapp/WEB-INF/web.xml

Propchange: jackrabbit/branches/2.2/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Jan  4 19:54:03 2011
@@ -2,4 +2,4 @@
 /jackrabbit/sandbox/JCR-1456:774917-886178
 /jackrabbit/sandbox/JCR-2170:812417-816332
 /jackrabbit/sandbox/tripod-JCR-2209:795441-795863
-/jackrabbit/trunk:1038201,1038203,1038205,1038657,1039064,1039347,1039408,1039422-1039423,1039888,1039946,1040033,1040090,1040459,1040601,1040606,1040661,1040958,1041379,1041439,1041761,1042643,1042647,1042978-1042982,1043084-1043086,1043088,1043343,1043357-1043358,1043430,1043554,1043616,1043618,1043637,1043656,1044312,1049473,1049491,1049520,1050346,1055068,1055070-1055071,1055116-1055117,1055127
+/jackrabbit/trunk:1038201,1038203,1038205,1038657,1039064,1039347,1039408,1039422-1039423,1039888,1039946,1040033,1040090,1040459,1040601,1040606,1040661,1040958,1041379,1041439,1041761,1042643,1042647,1042978-1042982,1043084-1043086,1043088,1043343,1043357-1043358,1043430,1043554,1043616,1043618,1043637,1043656,1044312,1049473,1049491,1049520,1050346,1055068,1055070-1055071,1055116-1055117,1055127,1055134,1055164

Modified: jackrabbit/branches/2.2/jackrabbit-webapp/src/main/java/org/apache/jackrabbit/j2ee/DerbyShutdown.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.2/jackrabbit-webapp/src/main/java/org/apache/jackrabbit/j2ee/DerbyShutdown.java?rev=1055168&r1=1055167&r2=1055168&view=diff
==============================================================================
--- jackrabbit/branches/2.2/jackrabbit-webapp/src/main/java/org/apache/jackrabbit/j2ee/DerbyShutdown.java
(original)
+++ jackrabbit/branches/2.2/jackrabbit-webapp/src/main/java/org/apache/jackrabbit/j2ee/DerbyShutdown.java
Tue Jan  4 19:54:03 2011
@@ -16,18 +16,19 @@
  */
 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;
 
 /**
  * Servlet context listener that releases all remaining Derby resources
- * when the web application is undeployed. Should only be used when the
- * Derby library has been deployed as a part of this webapp.
+ * when the web application is undeployed. The resources are released only
+ * if the Derby classes were loaded from within this webapp.
  *
  * @see <a href="https://issues.apache.org/jira/browse/JCR-1301">JCR-1301</a>
  */
@@ -37,15 +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";
-            Driver driver = DriverManager.getDriver(shutdown);
-            if (driver.getClass().getClassLoader()
-                    == DerbyShutdown.class.getClassLoader()) {
-                DriverManager.deregisterDriver(driver);
-                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) {
         }
     }
 

Modified: jackrabbit/branches/2.2/jackrabbit-webapp/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.2/jackrabbit-webapp/src/main/webapp/WEB-INF/web.xml?rev=1055168&r1=1055167&r2=1055168&view=diff
==============================================================================
--- jackrabbit/branches/2.2/jackrabbit-webapp/src/main/webapp/WEB-INF/web.xml (original)
+++ jackrabbit/branches/2.2/jackrabbit-webapp/src/main/webapp/WEB-INF/web.xml Tue Jan  4 19:54:03
2011
@@ -22,9 +22,6 @@
 
     <listener>
         <!-- Releases all Derby resources when the webapp is undeployed.  -->
-        <!-- You should comment out this entry if you are not using Derby -->
-        <!-- for Jackrabbit persistence, or if you've deployed the Derby  -->
-        <!-- outside the Jackrabbit webapp.                               -->
         <!-- See https://issues.apache.org/jira/browse/JCR-1301           -->
         <listener-class>
             org.apache.jackrabbit.j2ee.DerbyShutdown



Mime
View raw message