geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ke...@apache.org
Subject svn commit: r510637 - /geronimo/server/branches/2.0-M3/modules/geronimo-persistence-jpa10/src/main/java/org/apache/geronimo/persistence/PersistenceUnitGBean.java
Date Thu, 22 Feb 2007 20:08:39 GMT
Author: kevan
Date: Thu Feb 22 12:08:39 2007
New Revision: 510637

URL: http://svn.apache.org/viewvc?view=rev&rev=510637
Log:
GERONIMO-2873 Make sure that the temporary classloader created for JPA is properly destroyed

Modified:
    geronimo/server/branches/2.0-M3/modules/geronimo-persistence-jpa10/src/main/java/org/apache/geronimo/persistence/PersistenceUnitGBean.java

Modified: geronimo/server/branches/2.0-M3/modules/geronimo-persistence-jpa10/src/main/java/org/apache/geronimo/persistence/PersistenceUnitGBean.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/2.0-M3/modules/geronimo-persistence-jpa10/src/main/java/org/apache/geronimo/persistence/PersistenceUnitGBean.java?view=diff&rev=510637&r1=510636&r2=510637
==============================================================================
--- geronimo/server/branches/2.0-M3/modules/geronimo-persistence-jpa10/src/main/java/org/apache/geronimo/persistence/PersistenceUnitGBean.java
(original)
+++ geronimo/server/branches/2.0-M3/modules/geronimo-persistence-jpa10/src/main/java/org/apache/geronimo/persistence/PersistenceUnitGBean.java
Thu Feb 22 12:08:39 2007
@@ -93,10 +93,13 @@
             PersistenceProvider persistenceProvider = (PersistenceProvider) clazz.newInstance();
             entityManagerFactory = persistenceProvider.createContainerEntityManagerFactory(persistenceUnitInfo,
properties);
         } catch (ClassNotFoundException e) {
+            persistenceUnitInfo.destroyTempClassLoader();
             throw new PersistenceException("Could not locate PersistenceProvider class: "
+ persistenceProviderClassName + " in classloader " + classLoader, e);
         } catch (InstantiationException e) {
+            persistenceUnitInfo.destroyTempClassLoader();
             throw new PersistenceException("Could not create PersistenceProvider instance:
" + persistenceProviderClassName + " loaded from classloader " + classLoader, e);
         } catch (IllegalAccessException e) {
+            persistenceUnitInfo.destroyTempClassLoader();
             throw new PersistenceException("Could not create PersistenceProvider instance:
" + persistenceProviderClassName + " loaded from classloader " + classLoader, e);
         }
         this.transactionManager = transactionManager;
@@ -176,10 +179,12 @@
     public void doStop() throws Exception {
         //TODO remove any classtransformers added
         entityManagerFactory.close();
+        persistenceUnitInfo.destroyTempClassLoader();
     }
 
     public void doFail() {
         entityManagerFactory.close();
+        persistenceUnitInfo.destroyTempClassLoader();
     }
 
     private static class PersistenceUnitInfoImpl implements PersistenceUnitInfo {
@@ -195,6 +200,7 @@
         private final boolean excludeUnlistedClassesValue;
         private final Properties properties;
         private final ClassLoader classLoader;
+        private final JarFileClassLoader tempClassLoader;
 
 
         public PersistenceUnitInfoImpl(String persistenceUnitName, String persistenceProviderClassName,
PersistenceUnitTransactionType persistenceUnitTransactionType, DataSource jtaDataSource, DataSource
nonJtaDataSource, List<String> mappingFileNames, List<URL> jarFileUrls, URL persistenceUnitRootUrl,
List<String> managedClassNames, boolean excludeUnlistedClassesValue, Properties properties,
ClassLoader classLoader) {
@@ -210,6 +216,10 @@
             this.excludeUnlistedClassesValue = excludeUnlistedClassesValue;
             this.properties = properties;
             this.classLoader = classLoader;
+            
+            // This classloader can only be used during PersistenceProvider.createContainerEntityManagerFactory()
calls
+            // Possible that it could be cleaned up sooner, but for now it's destroyed when
the PUGBean is stopped
+            this.tempClassLoader = (JarFileClassLoader)JarFileClassLoader.copy(classLoader);

         }
 
         public String getPersistenceUnitName() {
@@ -265,7 +275,11 @@
         }
 
         public ClassLoader getNewTempClassLoader() {
-            return JarFileClassLoader.copy(classLoader);
+            return tempClassLoader;
+        }
+
+        private void destroyTempClassLoader() {
+            tempClassLoader.destroy();
         }
 
     }



Mime
View raw message