You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by rw...@apache.org on 2009/06/18 06:54:56 UTC
svn commit: r785900 - in /portals/jetspeed-2/portal/trunk:
components/jetspeed-portal/src/test/testdata/pages/pages/
components/jetspeed-rdbms/src/main/java/org/apache/jetspeed/components/rdbms/ojb/
jetspeed-portal-resources/src/main/resources/assembly...
Author: rwatler
Date: Thu Jun 18 04:54:55 2009
New Revision: 785900
URL: http://svn.apache.org/viewvc?rev=785900&view=rev
Log:
JS2-1014: JDK6 unit test fixes for connection pool reset between tests
Added:
portals/jetspeed-2/portal/trunk/components/jetspeed-rdbms/src/main/java/org/apache/jetspeed/components/rdbms/ojb/ConnectionManagerManagementBean.java
Modified:
portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/testdata/pages/pages/page.security
portals/jetspeed-2/portal/trunk/components/jetspeed-rdbms/src/main/java/org/apache/jetspeed/components/rdbms/ojb/ConnectionManagerImpl.java
portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/alternate/debug/datasource.xml
portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/boot/datasource.xml
Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/testdata/pages/pages/page.security
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/testdata/pages/pages/page.security?rev=785900&r1=785899&r2=785900&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/testdata/pages/pages/page.security (original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/testdata/pages/pages/page.security Thu Jun 18 04:54:55 2009
@@ -1,20 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
-<!--
-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.
--->
<page-security>
<security-constraints-def name="admin">
<security-constraint>
Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-rdbms/src/main/java/org/apache/jetspeed/components/rdbms/ojb/ConnectionManagerImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-rdbms/src/main/java/org/apache/jetspeed/components/rdbms/ojb/ConnectionManagerImpl.java?rev=785900&r1=785899&r2=785900&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-rdbms/src/main/java/org/apache/jetspeed/components/rdbms/ojb/ConnectionManagerImpl.java (original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-rdbms/src/main/java/org/apache/jetspeed/components/rdbms/ojb/ConnectionManagerImpl.java Thu Jun 18 04:54:55 2009
@@ -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();
+ }
}
Added: portals/jetspeed-2/portal/trunk/components/jetspeed-rdbms/src/main/java/org/apache/jetspeed/components/rdbms/ojb/ConnectionManagerManagementBean.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-rdbms/src/main/java/org/apache/jetspeed/components/rdbms/ojb/ConnectionManagerManagementBean.java?rev=785900&view=auto
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-rdbms/src/main/java/org/apache/jetspeed/components/rdbms/ojb/ConnectionManagerManagementBean.java (added)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-rdbms/src/main/java/org/apache/jetspeed/components/rdbms/ojb/ConnectionManagerManagementBean.java Thu Jun 18 04:54:55 2009
@@ -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 <a href="mailto:rwatler@apache.org">Randy Watler</a>
+ * @version $Id$
+ */
+public class ConnectionManagerManagementBean
+{
+ private static List<ConnectionManagerImpl> connectionManagers = new ArrayList<ConnectionManagerImpl>();
+
+ /**
+ * 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();
+ }
+ }
+ }
+}
Modified: portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/alternate/debug/datasource.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/alternate/debug/datasource.xml?rev=785900&r1=785899&r2=785900&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/alternate/debug/datasource.xml (original)
+++ portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/alternate/debug/datasource.xml Thu Jun 18 04:54:55 2009
@@ -29,9 +29,11 @@
<value>com.fmr</value>
</list>
</property>
- </bean>
+ </bean>
- <bean id="ojbConfigurer" class="org.springframework.orm.ojb.support.LocalOjbConfigurer"/>
+ <bean id="ojbConnectionManagement" class="org.apache.jetspeed.components.rdbms.ojb.ConnectionManagerManagementBean" />
+
+ <bean id="ojbConfigurer" class="org.springframework.orm.ojb.support.LocalOjbConfigurer" depends-on="ojbConnectionManagement" />
<!--
Dynamically configures Database Platform for OJB by looking at the connection string
Modified: portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/boot/datasource.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/boot/datasource.xml?rev=785900&r1=785899&r2=785900&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/boot/datasource.xml (original)
+++ portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/boot/datasource.xml Thu Jun 18 04:54:55 2009
@@ -27,7 +27,9 @@
<property name="jndiName" value="java:comp/env/jdbc/jetspeed" />
</bean>
- <bean id="ojbConfigurer" class="org.springframework.orm.ojb.support.LocalOjbConfigurer" />
+ <bean id="ojbConnectionManagement" class="org.apache.jetspeed.components.rdbms.ojb.ConnectionManagerManagementBean" />
+
+ <bean id="ojbConfigurer" class="org.springframework.orm.ojb.support.LocalOjbConfigurer" depends-on="ojbConnectionManagement" />
<!--
Dynamically configures Database Platform for OJB by looking at the connection string
---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org