portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject svn commit: r279759 - /portals/jetspeed-2/trunk/components/rdbms/src/java/org/apache/jetspeed/components/rdbms/ojb/ConnectionManagerImpl.java
Date Fri, 09 Sep 2005 12:51:33 GMT
Author: ate
Date: Fri Sep  9 05:51:26 2005
New Revision: 279759

URL: http://svn.apache.org/viewcvs?rev=279759&view=rev
Log:
Fix for http://issues.apache.org/jira/browse/JS2-326#action_12323032

Modified:
    portals/jetspeed-2/trunk/components/rdbms/src/java/org/apache/jetspeed/components/rdbms/ojb/ConnectionManagerImpl.java

Modified: portals/jetspeed-2/trunk/components/rdbms/src/java/org/apache/jetspeed/components/rdbms/ojb/ConnectionManagerImpl.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/rdbms/src/java/org/apache/jetspeed/components/rdbms/ojb/ConnectionManagerImpl.java?rev=279759&r1=279758&r2=279759&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/rdbms/src/java/org/apache/jetspeed/components/rdbms/ojb/ConnectionManagerImpl.java
(original)
+++ portals/jetspeed-2/trunk/components/rdbms/src/java/org/apache/jetspeed/components/rdbms/ojb/ConnectionManagerImpl.java
Fri Sep  9 05:51:26 2005
@@ -17,6 +17,7 @@
 
 import java.sql.Connection;
 import java.sql.SQLException;
+import java.util.HashMap;
 
 import org.apache.ojb.broker.OJBRuntimeException;
 import org.apache.ojb.broker.PBKey;
@@ -70,34 +71,50 @@
     private boolean batchMode;
     private BatchConnection batchCon = null;
 
+    private static HashMap connectionFactories = new HashMap();
+    
     public ConnectionManagerImpl(PersistenceBroker broker)
     {
         this.broker = broker;
         this.pbKey = broker.getPBKey();
-        this.jcd = MetadataManager.getInstance().connectionRepository().getDescriptor(pbKey);
-        ConnectionPoolDescriptor cpd = jcd.getConnectionPoolDescriptor();
+        this.jcd = MetadataManager.getInstance().connectionRepository().getDescriptor(pbKey);
       
+        ConnectionPoolDescriptor cpd = jcd.getConnectionPoolDescriptor();        
         if (cpd != null && cpd.getConnectionFactory() != null)
         {
-            try
-            {
-                connectionFactory = (ConnectionFactory)
-                    ClassHelper.newInstance (cpd.getConnectionFactory(), true);
-            }
-            catch (InstantiationException e)
-            {
-                String err = "Can't instantiate class " + cpd.getConnectionFactory();
-                log.error(err, e);
-                throw (IllegalStateException)(new IllegalStateException(err)).initCause(e);
-            }
-            catch (IllegalAccessException e)
+            connectionFactory = (ConnectionFactory)connectionFactories.get(cpd.getConnectionFactory());
+            if ( connectionFactory == null )
             {
-                String err = "Can't instantiate class " + cpd.getConnectionFactory();
-                log.error(err, e);
-                throw (IllegalStateException)(new IllegalStateException(err)).initCause(e);
+                try
+                {
+                    ClassLoader cl = Thread.currentThread().getContextClassLoader();    
           
+                    try
+                    {
+                        Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
+                        connectionFactory = (ConnectionFactory)
+                            ClassHelper.newInstance (cpd.getConnectionFactory(), true);
+                        connectionFactories.put(cpd.getConnectionFactory(), connectionFactory);
+                    }
+                    finally
+                    {
+                        Thread.currentThread().setContextClassLoader(cl);
+                    }
+                }
+                catch (InstantiationException e)
+                {
+                    String err = "Can't instantiate class " + cpd.getConnectionFactory();
+                    log.error(err, e);
+                    throw (IllegalStateException)(new IllegalStateException(err)).initCause(e);
+                }
+                catch (IllegalAccessException e)
+                {
+                    String err = "Can't instantiate class " + cpd.getConnectionFactory();
+                    log.error(err, e);
+                    throw (IllegalStateException)(new IllegalStateException(err)).initCause(e);
+                }
             }
         }
         else 
-        {
+        {                
             this.connectionFactory = ConnectionFactoryFactory.getInstance().createConnectionFactory();
         }
         this.platform = PlatformFactory.getPlatformFor(jcd);
@@ -155,7 +172,17 @@
         }
         if (con == null)
         {
-            con = this.connectionFactory.lookupConnection(jcd);
+            ClassLoader cl = Thread.currentThread().getContextClassLoader();
+            try
+            {
+                Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
+                con = this.connectionFactory.lookupConnection(jcd);
+            }
+            finally
+            {
+                Thread.currentThread().setContextClassLoader(cl);
+            }
+            
             if (con == null) throw new PersistenceBrokerException("Cannot get connection
for " + jcd);
             if (jcd.getUseAutoCommit() == JdbcConnectionDescriptor.AUTO_COMMIT_SET_TRUE_AND_TEMPORARY_FALSE)
             {



---------------------------------------------------------------------
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