Index: components/jetspeed-rdbms/src/main/java/org/apache/jetspeed/components/rdbms/ojb/ConnectionManagerImpl.java =================================================================== --- components/jetspeed-rdbms/src/main/java/org/apache/jetspeed/components/rdbms/ojb/ConnectionManagerImpl.java (revision 775412) +++ components/jetspeed-rdbms/src/main/java/org/apache/jetspeed/components/rdbms/ojb/ConnectionManagerImpl.java (revision 775413) @@ -81,63 +81,76 @@ { this.broker = broker; this.pbKey = broker.getPBKey(); - this.jcd = MetadataManager.getInstance().connectionRepository().getDescriptor(pbKey); + this.jcd = MetadataManager.getInstance().connectionRepository().getDescriptor(pbKey); + this.connectionFactory = setupConnectionFactory(jcd); + this.platform = PlatformFactory.getPlatformFor(jcd); + /* + by default batch mode is not enabled and after use of a PB + instance, before instance was returned to pool, batch mode + was set to false again (PB implementation close method) + Be carefully in modify this behaviour, changes could cause + unexpected behaviour + */ + setBatchMode(false); + + // save connection manager instance + ConnectionManagerManagementBean.addConnectionManager(this); + } + + /** + * Construct new connection factory. + * + * @param jcd JDBC connection descriptor + * @return + */ + private static ConnectionFactory setupConnectionFactory(JdbcConnectionDescriptor jcd) + { + ConnectionFactory cf = null; ConnectionPoolDescriptor cpd = jcd.getConnectionPoolDescriptor(); if (cpd != null && cpd.getConnectionFactory() != null) { - connectionFactory = (ConnectionFactory)connectionFactories.get(cpd.getConnectionFactory()); - if ( connectionFactory == null ) + cf = (ConnectionFactory)connectionFactories.get(cpd.getConnectionFactory()); + if ( cf == null ) { try { - if (Boolean.valueOf(this.jcd.getAttribute("org.apache.jetspeed.engineScoped", "false")).booleanValue()) { + if (Boolean.valueOf(jcd.getAttribute("org.apache.jetspeed.engineScoped", "false")).booleanValue()) { ClassLoader cl = Thread.currentThread().getContextClassLoader(); try { - Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader()); - connectionFactory = (ConnectionFactory) - ClassHelper.newInstance (cpd.getConnectionFactory(), true); - connectionFactories.put(cpd.getConnectionFactory(), connectionFactory); + Thread.currentThread().setContextClassLoader(ConnectionManagerImpl.class.getClassLoader()); + cf = (ConnectionFactory) ClassHelper.newInstance(cpd.getConnectionFactory(), true); + connectionFactories.put(cpd.getConnectionFactory(), cf); } finally { Thread.currentThread().setContextClassLoader(cl); - connectionFactories.put(cpd.getConnectionFactory(), connectionFactory); + cf = (ConnectionFactory) ClassHelper.newInstance(cpd.getConnectionFactory(), true); + connectionFactories.put(cpd.getConnectionFactory(), cf); } } else { - connectionFactory = (ConnectionFactory) - ClassHelper.newInstance (cpd.getConnectionFactory(), true); + cf = (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) { 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(); + cf = (ConnectionFactory) ConnectionFactoryFactory.getInstance().createNewInstance(); } - this.platform = PlatformFactory.getPlatformFor(jcd); - /* - by default batch mode is not enabled and after use of a PB - instance, before instance was returned to pool, batch mode - was set to false again (PB implementation close method) - Be carefully in modify this behaviour, changes could cause - unexpected behaviour - */ - setBatchMode(false); + return cf; } /** @@ -485,4 +498,31 @@ batchCon.clearBatch(); } } + + /** + * Reset cached connection and connection factory. + */ + protected void reset() + { + // roll back and/or release cached connection + if (isInLocalTransaction()) + { + localRollback(); + } + else + { + releaseConnection(); + } + // reset connection factory + connectionFactory = setupConnectionFactory(jcd); + } + + /** + * Reset cached connection factories. + */ + protected static void resetConnectionFactories() + { + // clear cached connection factories + connectionFactories.clear(); + } } Index: components/jetspeed-rdbms/src/main/java/org/apache/jetspeed/components/rdbms/ojb/ConnectionManagerManagementBean.java =================================================================== --- components/jetspeed-rdbms/src/main/java/org/apache/jetspeed/components/rdbms/ojb/ConnectionManagerManagementBean.java (revision 0) +++ components/jetspeed-rdbms/src/main/java/org/apache/jetspeed/components/rdbms/ojb/ConnectionManagerManagementBean.java (revision 775413) @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.jetspeed.components.rdbms.ojb; + +import java.util.ArrayList; +import java.util.List; + +/** + * Manage OJB ConnectionManagerImpl instance state. + * + * @author Randy Watler + * @version $Id$ + */ +public class ConnectionManagerManagementBean +{ + private static List connectionManagers = new ArrayList(); + + /** + * Add connection manager to list of ConnectionManagerImpl instances. + * + * @param connectionManager connection manager instance + */ + protected static void addConnectionManager(ConnectionManagerImpl connectionManager) + { + // manage connection manager instances + synchronized (connectionManagers) + { + connectionManagers.add(connectionManager); + } + } + + /** + * Manage connection manager instances on bean creation. + */ + public ConnectionManagerManagementBean() + { + // reset connection manager instances + synchronized (connectionManagers) + { + ConnectionManagerImpl.resetConnectionFactories(); + for (ConnectionManagerImpl connectionManager : connectionManagers) + { + connectionManager.reset(); + } + } + } +} Index: jetspeed-portal-resources/src/main/resources/assembly/boot/datasource.xml =================================================================== --- jetspeed-portal-resources/src/main/resources/assembly/boot/datasource.xml (revision 775412) +++ jetspeed-portal-resources/src/main/resources/assembly/boot/datasource.xml (revision 775413) @@ -27,8 +27,10 @@ - + + +