Author: djencks Date: Tue Mar 15 18:18:05 2005 New Revision: 157628 URL: http://svn.apache.org/viewcvs?view=rev&rev=157628 Log: GERONIMO-610. Provide a thread context classloader where possible for calls into the connector
Added: geronimo/trunk/modules/connector/src/java/org/apache/geronimo/connector/outbound/TCCLInterceptor.java Modified: geronimo/trunk/modules/connector/src/java/org/apache/geronimo/connector/outbound/GenericConnectionManager.java geronimo/trunk/modules/connector/src/test/org/apache/geronimo/connector/outbound/ConnectionManagerTestUtils.java Modified: geronimo/trunk/modules/connector/src/java/org/apache/geronimo/connector/outbound/GenericConnectionManager.java URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/connector/src/java/org/apache/geronimo/connector/outbound/GenericConnectionManager.java?view=diff&r1=157627&r2=157628 ============================================================================== --- geronimo/trunk/modules/connector/src/java/org/apache/geronimo/connector/outbound/GenericConnectionManager.java (original) +++ geronimo/trunk/modules/connector/src/java/org/apache/geronimo/connector/outbound/GenericConnectionManager.java Tue Mar 15 18:18:05 2005 @@ -42,11 +42,13 @@ public GenericConnectionManager(TransactionSupport transactionSupport, PoolingSupport pooling, - String objectName, RealmBridge realmBridge, ConnectionTracker connectionTracker, - TransactionContextManager transactionContextManager) { - super(new InterceptorsImpl(transactionSupport, pooling, objectName, realmBridge, connectionTracker, transactionContextManager)); + TransactionContextManager transactionContextManager, + String objectName, + ClassLoader classLoader + ) { + super(new InterceptorsImpl(transactionSupport, pooling, objectName, realmBridge, connectionTracker, transactionContextManager, classLoader)); } private static class InterceptorsImpl implements AbstractConnectionManager.Interceptors { @@ -59,6 +61,7 @@ * Order of constructed interceptors: * <p/> * ConnectionTrackingInterceptor (connectionTracker != null) + * TCCLInterceptor * ConnectionHandleInterceptor * TransactionCachingInterceptor (useTransactions & useTransactionCaching) * TransactionEnlistingInterceptor (useTransactions) @@ -67,7 +70,13 @@ * LocalXAResourceInsertionInterceptor or XAResourceInsertionInterceptor (useTransactions (&localTransactions)) * MCFConnectionInterceptor */ - public InterceptorsImpl(TransactionSupport transactionSupport, PoolingSupport pooling, String objectName, RealmBridge realmBridge, ConnectionTracker connectionTracker, TransactionContextManager transactionContextManager) { + public InterceptorsImpl(TransactionSupport transactionSupport, + PoolingSupport pooling, + String objectName, + RealmBridge realmBridge, + ConnectionTracker connectionTracker, + TransactionContextManager transactionContextManager, + ClassLoader classLoader) { //check for consistency between attributes if (realmBridge == null && pooling instanceof PartitionedPool && ((PartitionedPool) pooling).isPartitionBySubject()) { throw new IllegalStateException("To use Subject in pooling, you need a SecurityDomain"); @@ -91,9 +100,12 @@ stack = new SubjectInterceptor(stack, realmBridge); } - recoveryStack = stack; + ConnectionInterceptor recoveryStack = stack; + this.recoveryStack = new TCCLInterceptor(recoveryStack, classLoader); + stack = new ConnectionHandleInterceptor(stack); + stack = new TCCLInterceptor(stack, classLoader); if (connectionTracker != null) { stack = new ConnectionTrackingInterceptor(stack, objectName, @@ -127,6 +139,7 @@ infoBuilder.addAttribute("pooling", PoolingSupport.class, true); infoBuilder.addAttribute("objectName", String.class, false); + infoBuilder.addAttribute("classLoader", ClassLoader.class, false); infoBuilder.addReference("ConnectionTracker", ConnectionTracker.class, NameFactory.JCA_RESOURCE); infoBuilder.addReference("RealmBridge", RealmBridge.class, NameFactory.GERONIMO_SERVICE); @@ -135,10 +148,12 @@ infoBuilder.setConstructor(new String[]{ "transactionSupport", "pooling", - "objectName", "RealmBridge", "ConnectionTracker", - "TransactionContextManager"}); + "TransactionContextManager", + "objectName", + "classLoader" + }); GBEAN_INFO = infoBuilder.getBeanInfo(); } Added: geronimo/trunk/modules/connector/src/java/org/apache/geronimo/connector/outbound/TCCLInterceptor.java URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/connector/src/java/org/apache/geronimo/connector/outbound/TCCLInterceptor.java?view=auto&rev=157628 ============================================================================== --- geronimo/trunk/modules/connector/src/java/org/apache/geronimo/connector/outbound/TCCLInterceptor.java (added) +++ geronimo/trunk/modules/connector/src/java/org/apache/geronimo/connector/outbound/TCCLInterceptor.java Tue Mar 15 18:18:05 2005 @@ -0,0 +1,55 @@ +/** + * + * Copyright 2003-2004 The Apache Software Foundation + * + * Licensed 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.geronimo.connector.outbound; + +import javax.resource.ResourceException; + +/** + * @version $Rev: $ $Date: $ + */ +public class TCCLInterceptor implements ConnectionInterceptor{ + private final ConnectionInterceptor next; + private final ClassLoader classLoader; + + public TCCLInterceptor(ConnectionInterceptor next, ClassLoader classLoader) { + this.next = next; + this.classLoader = classLoader; + } + + + public void getConnection(ConnectionInfo connectionInfo) throws ResourceException { + Thread currentThread = Thread.currentThread(); + ClassLoader oldClassLoader = currentThread.getContextClassLoader(); + currentThread.setContextClassLoader(classLoader); + try { + next.getConnection(connectionInfo); + } finally { + currentThread.setContextClassLoader(oldClassLoader); + } + } + + public void returnConnection(ConnectionInfo connectionInfo, ConnectionReturnAction connectionReturnAction) { + Thread currentThread = Thread.currentThread(); + ClassLoader oldClassLoader = currentThread.getContextClassLoader(); + currentThread.setContextClassLoader(classLoader); + try { + next.returnConnection(connectionInfo, connectionReturnAction); + } finally { + currentThread.setContextClassLoader(oldClassLoader); + } + } +} Modified: geronimo/trunk/modules/connector/src/test/org/apache/geronimo/connector/outbound/ConnectionManagerTestUtils.java URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/connector/src/test/org/apache/geronimo/connector/outbound/ConnectionManagerTestUtils.java?view=diff&r1=157627&r2=157628 ============================================================================== --- geronimo/trunk/modules/connector/src/test/org/apache/geronimo/connector/outbound/ConnectionManagerTestUtils.java (original) +++ geronimo/trunk/modules/connector/src/test/org/apache/geronimo/connector/outbound/ConnectionManagerTestUtils.java Tue Mar 15 18:18:05 2005 @@ -87,6 +87,7 @@ return null; } }; + private ClassLoader classLoader = this.getClass().getClassLoader(); protected void setUp() throws Exception { connectionTrackingCoordinator = new ConnectionTrackingCoordinator(); @@ -98,10 +99,11 @@ connectionManagerDeployment = new GenericConnectionManager( transactionSupport, poolingSupport, - name, realmBridge, connectionTrackingCoordinator, - transactionContextManager); + transactionContextManager, + name, + classLoader); connectionFactory = (MockConnectionFactory) connectionManagerDeployment.createConnectionFactory(mockManagedConnectionFactory); defaultComponentContext = new DefaultInstanceContext(unshareableResources, applicationManagedSecurityResources); defaultComponentInterceptor = new DefaultComponentInterceptor(this, connectionTrackingCoordinator, transactionContextManager);