Return-Path: Delivered-To: apmail-geronimo-scm-archive@www.apache.org Received: (qmail 78659 invoked from network); 25 Feb 2005 23:10:33 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 25 Feb 2005 23:10:33 -0000 Received: (qmail 57417 invoked by uid 500); 25 Feb 2005 23:10:33 -0000 Delivered-To: apmail-geronimo-scm-archive@geronimo.apache.org Received: (qmail 57266 invoked by uid 500); 25 Feb 2005 23:10:32 -0000 Mailing-List: contact scm-help@geronimo.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: dev@geronimo.apache.org Delivered-To: mailing list scm@geronimo.apache.org Received: (qmail 57252 invoked by uid 99); 25 Feb 2005 23:10:32 -0000 X-ASF-Spam-Status: No, hits=-9.8 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from minotaur.apache.org (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Fri, 25 Feb 2005 15:10:30 -0800 Received: (qmail 78647 invoked by uid 65534); 25 Feb 2005 23:10:29 -0000 Message-ID: <20050225231029.78646.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Mailer: svnmailer-1.0.0-dev Date: Fri, 25 Feb 2005 23:10:29 -0000 Subject: svn commit: r155376 - in geronimo/trunk/modules: connector/src/java/org/apache/geronimo/connector/outbound/ connector/src/test/org/apache/geronimo/connector/outbound/ timer/src/java/org/apache/geronimo/timer/ timer/src/test/org/apache/geronimo/timer/ transaction/src/java/org/apache/geronimo/transaction/ transaction/src/java/org/apache/geronimo/transaction/context/ To: scm@geronimo.apache.org From: dain@apache.org X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N Author: dain Date: Fri Feb 25 15:10:24 2005 New Revision: 155376 URL: http://svn.apache.org/viewcvs?view=3Drev&rev=3D155376 Log: Fixed bugs in TransactionContext and handling of the contexts unturned by t= urning back on in-tx caching Added support for entrancy tracking and killing InstanceContexts Modified: geronimo/trunk/modules/connector/src/java/org/apache/geronimo/connector= /outbound/TransactionCachingInterceptor.java geronimo/trunk/modules/connector/src/java/org/apache/geronimo/connector= /outbound/TransactionEnlistingInterceptor.java geronimo/trunk/modules/connector/src/test/org/apache/geronimo/connector= /outbound/TransactionCachingInterceptorTest.java geronimo/trunk/modules/timer/src/java/org/apache/geronimo/timer/Nontran= sactionalExecutorTask.java geronimo/trunk/modules/timer/src/java/org/apache/geronimo/timer/ThreadP= ooledTimer.java geronimo/trunk/modules/timer/src/java/org/apache/geronimo/timer/Transac= tionalExecutorTask.java geronimo/trunk/modules/timer/src/test/org/apache/geronimo/timer/Abstrac= tThreadPooledTimerTest.java geronimo/trunk/modules/transaction/src/java/org/apache/geronimo/transac= tion/DefaultInstanceContext.java geronimo/trunk/modules/transaction/src/java/org/apache/geronimo/transac= tion/InstanceContext.java geronimo/trunk/modules/transaction/src/java/org/apache/geronimo/transac= tion/context/InheritableTransactionContext.java geronimo/trunk/modules/transaction/src/java/org/apache/geronimo/transac= tion/context/TransactionContext.java geronimo/trunk/modules/transaction/src/java/org/apache/geronimo/transac= tion/context/UnspecifiedTransactionContext.java Modified: geronimo/trunk/modules/connector/src/java/org/apache/geronimo/con= nector/outbound/TransactionCachingInterceptor.java URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/connector/src/jav= a/org/apache/geronimo/connector/outbound/TransactionCachingInterceptor.java= ?view=3Ddiff&r1=3D155375&r2=3D155376 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- geronimo/trunk/modules/connector/src/java/org/apache/geronimo/connector= /outbound/TransactionCachingInterceptor.java (original) +++ geronimo/trunk/modules/connector/src/java/org/apache/geronimo/connector= /outbound/TransactionCachingInterceptor.java Fri Feb 25 15:10:24 2005 @@ -27,6 +27,7 @@ import org.apache.geronimo.transaction.ConnectionReleaser; import org.apache.geronimo.transaction.context.TransactionContext; import org.apache.geronimo.transaction.context.TransactionContextManager; +import org.apache.geronimo.transaction.context.InheritableTransactionConte= xt; =20 /** * TransactionCachingInterceptor.java @@ -59,16 +60,15 @@ } =20 public void getConnection(ConnectionInfo connectionInfo) throws Resour= ceException { - TransactionContext transactionContext =3D transactionContextManage= r=2EgetContext(); //There can be an inactive transaction context when a connection i= s requested in //Synchronization.afterCompletion(). - if (transactionContext =3D=3D null || !transactionContext.isActive= ()) { - next.getConnection(connectionInfo); - } else { - ManagedConnectionInfos managedConnectionInfos =3D (ManagedConn= ectionInfos) transactionContext.getManagedConnectionInfo(this); + TransactionContext transactionContext =3D transactionContextManage= r=2EgetContext(); + if ((transactionContext instanceof InheritableTransactionContext) = && ((InheritableTransactionContext) transactionContext).isActive()) { + InheritableTransactionContext inheritableTransactionContext = =3D ((InheritableTransactionContext) transactionContext); + ManagedConnectionInfos managedConnectionInfos =3D (ManagedConn= ectionInfos) inheritableTransactionContext.getManagedConnectionInfo(this); if (managedConnectionInfos =3D=3D null) { managedConnectionInfos =3D new ManagedConnectionInfos(); - transactionContext.setManagedConnectionInfo(this, managedC= onnectionInfos); + inheritableTransactionContext.setManagedConnectionInfo(thi= s, managedConnectionInfos); } if (connectionInfo.isUnshareable()) { if (!managedConnectionInfos.containsUnshared(connectionInf= o=2EgetManagedConnectionInfo())) { @@ -85,6 +85,8 @@ managedConnectionInfos.setShared(connectionInfo.getMan= agedConnectionInfo()); } } + } else { + next.getConnection(connectionInfo); } } =20 @@ -96,7 +98,7 @@ } =20 TransactionContext transactionContext =3D transactionContextManage= r=2EgetContext(); - if (transactionContext !=3D null && transactionContext.isActive())= { + if ((transactionContext instanceof InheritableTransactionContext) = && ((InheritableTransactionContext) transactionContext).isActive()) { return; } internalReturn(connectionInfo, connectionReturnAction); Modified: geronimo/trunk/modules/connector/src/java/org/apache/geronimo/con= nector/outbound/TransactionEnlistingInterceptor.java URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/connector/src/jav= a/org/apache/geronimo/connector/outbound/TransactionEnlistingInterceptor.ja= va?view=3Ddiff&r1=3D155375&r2=3D155376 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- geronimo/trunk/modules/connector/src/java/org/apache/geronimo/connector= /outbound/TransactionEnlistingInterceptor.java (original) +++ geronimo/trunk/modules/connector/src/java/org/apache/geronimo/connector= /outbound/TransactionEnlistingInterceptor.java Fri Feb 25 15:10:24 2005 @@ -24,6 +24,7 @@ =20 import org.apache.geronimo.transaction.context.TransactionContext; import org.apache.geronimo.transaction.context.TransactionContextManager; +import org.apache.geronimo.transaction.context.InheritableTransactionConte= xt; =20 /** * TransactionEnlistingInterceptor.java @@ -48,9 +49,12 @@ try { ManagedConnectionInfo mci =3D connectionInfo.getManagedConnect= ionInfo(); TransactionContext transactionContext =3D transactionContextMa= nager.getContext(); - if (transactionContext !=3D null && transactionContext.isActiv= e()) { - XAResource xares =3D mci.getXAResource(); - transactionContext.getTransaction().enlistResource(xares); + if ((transactionContext instanceof InheritableTransactionConte= xt)) { + InheritableTransactionContext inheritableTransactionContex= t =3D ((InheritableTransactionContext) transactionContext); + if (inheritableTransactionContext.isActive()) { + XAResource xares =3D mci.getXAResource(); + inheritableTransactionContext.getTransaction().enlistR= esource(xares); + } } =20 } catch (SystemException e) { @@ -76,9 +80,12 @@ try { ManagedConnectionInfo mci =3D connectionInfo.getManagedConnect= ionInfo(); TransactionContext transactionContext =3D transactionContextMa= nager.getContext(); - if (transactionContext !=3D null && transactionContext.isActiv= e()) { - XAResource xares =3D mci.getXAResource(); - transactionContext.getTransaction().delistResource(xares, = XAResource.TMSUSPEND); + if ((transactionContext instanceof InheritableTransactionConte= xt)) { + InheritableTransactionContext inheritableTransactionContex= t =3D ((InheritableTransactionContext) transactionContext); + if (inheritableTransactionContext.isActive()) { + XAResource xares =3D mci.getXAResource(); + inheritableTransactionContext.getTransaction().delistR= esource(xares, XAResource.TMSUSPEND); + } } =20 } catch (SystemException e) { Modified: geronimo/trunk/modules/connector/src/test/org/apache/geronimo/con= nector/outbound/TransactionCachingInterceptorTest.java URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/connector/src/tes= t/org/apache/geronimo/connector/outbound/TransactionCachingInterceptorTest.= java?view=3Ddiff&r1=3D155375&r2=3D155376 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- geronimo/trunk/modules/connector/src/test/org/apache/geronimo/connector= /outbound/TransactionCachingInterceptorTest.java (original) +++ geronimo/trunk/modules/connector/src/test/org/apache/geronimo/connector= /outbound/TransactionCachingInterceptorTest.java Fri Feb 25 15:10:24 2005 @@ -127,8 +127,6 @@ transactionCachingInterceptor.getConnection(connectionInfo1); assertTrue("Expected to get an initial connection", obtainedConnec= tionInfo !=3D null); assertTrue("Expected nothing returned yet", returnedConnectionInfo= =3D=3D null); - assertTrue("Expected no ManagedConnectionInfo in the TransactionCo= ntext", - null =3D=3D transactionContextManager.getContext().getMana= gedConnectionInfo(transactionCachingInterceptor)); obtainedConnectionInfo =3D null; ConnectionInfo connectionInfo2 =3D makeConnectionInfo(); transactionCachingInterceptor.getConnection(connectionInfo2); @@ -136,18 +134,12 @@ assertTrue("Expected nothing returned yet", returnedConnectionInfo= =3D=3D null); assertTrue("Expected different ManagedConnectionInfo in both Conne= ctionInfos", connectionInfo1.getManagedConnectionInfo() !=3D connection= Info2.getManagedConnectionInfo()); - assertTrue("Expected no ManagedConnectionInfo in the TransactionCo= ntext", - null =3D=3D transactionContextManager.getContext().getMana= gedConnectionInfo(transactionCachingInterceptor)); //we didn't create any handles, so the "ManagedConnection" should = be returned. - assertTrue("Expected TransactionContext to report inactive", !tran= sactionContextManager.getContext().isActive()); transactionCachingInterceptor.returnConnection(connectionInfo1, Co= nnectionReturnAction.RETURN_HANDLE); assertTrue("Expected connection to be returned", returnedConnectio= nInfo !=3D null); returnedConnectionInfo =3D null; transactionCachingInterceptor.returnConnection(connectionInfo2, Co= nnectionReturnAction.RETURN_HANDLE); assertTrue("Expected connection to be returned", returnedConnectio= nInfo !=3D null); - - assertTrue("Expected TransactionContext to report inactive", !tran= sactionContextManager.getContext().isActive()); - } =20 public void testTransactionIndependence() throws Exception { Modified: geronimo/trunk/modules/timer/src/java/org/apache/geronimo/timer/N= ontransactionalExecutorTask.java URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/timer/src/java/or= g/apache/geronimo/timer/NontransactionalExecutorTask.java?view=3Ddiff&r1=3D= 155375&r2=3D155376 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- geronimo/trunk/modules/timer/src/java/org/apache/geronimo/timer/Nontran= sactionalExecutorTask.java (original) +++ geronimo/trunk/modules/timer/src/java/org/apache/geronimo/timer/Nontran= sactionalExecutorTask.java Fri Feb 25 15:10:24 2005 @@ -19,14 +19,12 @@ =20 import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.geronimo.timer.ExecutorTask; +import org.apache.geronimo.transaction.context.TransactionContext; +import org.apache.geronimo.transaction.context.UnspecifiedTransactionConte= xt; =20 /** - * - * * @version $Rev$ $Date$ - * - * */ + */ public class NontransactionalExecutorTask implements ExecutorTask { =20 private static final Log log =3D LogFactory.getLog(NontransactionalExe= cutorTask.class); @@ -42,18 +40,26 @@ } =20 public void run() { + UnspecifiedTransactionContext transactionContext =3D new Unspecifi= edTransactionContext(); + TransactionContext oldTransactionContext =3D TransactionContext.ge= tContext(); + TransactionContext.setContext(transactionContext); try { - userTask.run(); - } catch (Exception e) { - log.info(e); - } - try { - threadPooledTimer.workPerformed(workInfo); - } catch (PersistenceException e) { - log.info(e); - } - if (workInfo.isOneTime()) { - threadPooledTimer.removeWorkInfo(workInfo); + try { + userTask.run(); + } catch (Exception e) { + log.info(e); + } + try { + threadPooledTimer.workPerformed(workInfo); + } catch (PersistenceException e) { + log.info(e); + } + if (workInfo.isOneTime()) { + threadPooledTimer.removeWorkInfo(workInfo); + } + } finally { + transactionContext.commit(); + TransactionContext.setContext(oldTransactionContext); } } =20 Modified: geronimo/trunk/modules/timer/src/java/org/apache/geronimo/timer/T= hreadPooledTimer.java URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/timer/src/java/or= g/apache/geronimo/timer/ThreadPooledTimer.java?view=3Ddiff&r1=3D155375&r2= =3D155376 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- geronimo/trunk/modules/timer/src/java/org/apache/geronimo/timer/ThreadP= ooledTimer.java (original) +++ geronimo/trunk/modules/timer/src/java/org/apache/geronimo/timer/ThreadP= ooledTimer.java Fri Feb 25 15:10:24 2005 @@ -37,6 +37,7 @@ import org.apache.geronimo.gbean.GBeanLifecycle; import org.apache.geronimo.transaction.context.TransactionContext; import org.apache.geronimo.transaction.context.TransactionContextManager; +import org.apache.geronimo.transaction.context.InheritableTransactionConte= xt; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; =20 @@ -243,13 +244,21 @@ =20 void registerSynchronization(Synchronization sync) throws RollbackExce= ption, SystemException { TransactionContext transactionContext =3D transactionContextManage= r=2EgetContext(); + //TODO move the registerSynchronization to the TransactionContext - Transaction transaction =3D transactionContext =3D=3D null? null: = transactionContext.getTransaction(); + Transaction transaction; + if (transactionContext instanceof InheritableTransactionContext) { + InheritableTransactionContext inheritableTransactionContext = =3D ((InheritableTransactionContext) transactionContext); + transaction =3D inheritableTransactionContext.getTransaction(); + assert transaction =3D=3D null || inheritableTransactionContex= t=2EisActive(): "Trying to register a sync on an inactive transaction conte= xt"; + } else { + transaction =3D null; + } + if (transaction =3D=3D null) { sync.beforeCompletion(); sync.afterCompletion(Status.STATUS_COMMITTED); } else { - assert transactionContext.isActive(): "Trying to register a sy= nc on an inactive transaction context"; transaction.registerSynchronization(sync); } } Modified: geronimo/trunk/modules/timer/src/java/org/apache/geronimo/timer/T= ransactionalExecutorTask.java URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/timer/src/java/or= g/apache/geronimo/timer/TransactionalExecutorTask.java?view=3Ddiff&r1=3D155= 375&r2=3D155376 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- geronimo/trunk/modules/timer/src/java/org/apache/geronimo/timer/Transac= tionalExecutorTask.java (original) +++ geronimo/trunk/modules/timer/src/java/org/apache/geronimo/timer/Transac= tionalExecutorTask.java Fri Feb 25 15:10:24 2005 @@ -17,26 +17,14 @@ =20 package org.apache.geronimo.timer; =20 -import javax.transaction.HeuristicMixedException; -import javax.transaction.HeuristicRollbackException; -import javax.transaction.NotSupportedException; -import javax.transaction.RollbackException; -import javax.transaction.SystemException; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.geronimo.transaction.context.ContainerTransactionContext; import org.apache.geronimo.transaction.context.TransactionContextManager; -import org.apache.geronimo.timer.ExecutorTask; -import org.apache.geronimo.timer.PersistenceException; -import org.apache.geronimo.timer.ThreadPooledTimer; =20 /** - * - * * @version $Rev$ $Date$ - * - * */ + */ public class TransactionalExecutorTask implements ExecutorTask { private static final Log log =3D LogFactory.getLog(TransactionalExecut= orTask.class); =20 @@ -54,49 +42,38 @@ this.transactionContextManager =3D transactionContextManager; this.repeatCount =3D repeatCount; } - + =20 public void run() { ContainerTransactionContext transactionContext =3D null; for (int tries =3D 0; tries < repeatCount; tries++) { try { transactionContext =3D transactionContextManager.newContai= nerTransactionContext(); - } catch (NotSupportedException e) { - log.info(e); - break; - } catch (SystemException e) { - log.info(e); + } catch (Exception e) { + log.info("Exception occured while starting container trans= action", e); break; } try { try { userTask.run(); } catch (Exception e) { - log.info(e); + log.info("Exception occured while running user task", = e); } try { threadPooledTimer.workPerformed(workInfo); } catch (PersistenceException e) { - log.info(e); + log.info("Exception occured while updating timer persi= stent state", e); } } finally { try { - if (transactionContext.getRollbackOnly()) { - transactionContext.rollback(); - } else { - transactionContext.commit(); + if (transactionContext.commit()) { if (workInfo.isOneTime()) { threadPooledTimer.removeWorkInfo(workInfo); } + // todo this is a very weird code structure.... re= turning from a finally is very confusing return; } - } catch (SystemException e) { - log.info(e); - } catch (HeuristicMixedException e) { - log.info(e); - } catch (HeuristicRollbackException e) { - log.info(e); - } catch (RollbackException e) { - log.info(e); + } catch (Exception e) { + log.info("Exception occured while completing container= transaction", e); } } } Modified: geronimo/trunk/modules/timer/src/test/org/apache/geronimo/timer/A= bstractThreadPooledTimerTest.java URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/timer/src/test/or= g/apache/geronimo/timer/AbstractThreadPooledTimerTest.java?view=3Ddiff&r1= =3D155375&r2=3D155376 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- geronimo/trunk/modules/timer/src/test/org/apache/geronimo/timer/Abstrac= tThreadPooledTimerTest.java (original) +++ geronimo/trunk/modules/timer/src/test/org/apache/geronimo/timer/Abstrac= tThreadPooledTimerTest.java Fri Feb 25 15:10:24 2005 @@ -23,11 +23,6 @@ import org.apache.geronimo.transaction.context.TransactionContext; import org.apache.geronimo.transaction.context.TransactionContextManager; import org.apache.geronimo.timer.vm.VMWorkerPersistence; -import org.apache.geronimo.timer.ExecutorTaskFactory; -import org.apache.geronimo.timer.ThreadPooledTimer; -import org.apache.geronimo.timer.UserTaskFactory; -import org.apache.geronimo.timer.WorkerPersistence; -import org.apache.geronimo.timer.WorkInfo; =20 /** * @@ -73,7 +68,7 @@ for (long i =3D 0; i < COUNT; i++) { timer.schedule(userTaskFactory, key, userId, userKey, i); } - Thread.currentThread().sleep(COUNT + SLOP); + Thread.sleep(COUNT + SLOP); assertEquals(COUNT, counter.get()); } =20 @@ -85,7 +80,7 @@ for (int i =3D 0; i < workInfos.length; i++) { workInfos[i].getExecutorFeedingTimerTask().cancel(); } - Thread.currentThread().sleep(SLOP + DELAY); + Thread.sleep(SLOP + DELAY); assertEquals(0, counter.get()); } =20 @@ -98,7 +93,7 @@ =20 timer.doStart(); timer.playback(key, userTaskFactory); - Thread.currentThread().sleep(2 * SLOP + DELAY); + Thread.sleep(2 * SLOP + DELAY); assertEquals(COUNT, counter.get()); } =20 @@ -134,48 +129,48 @@ for (long i =3D 0; i < COUNT; i++) { timer.schedule(userTaskFactory, key, userId, userKey, i); } - Thread.currentThread().sleep(COUNT + SLOP); + Thread.sleep(COUNT + SLOP); assertEquals(0, counter.get()); transactionContext.commit(); - Thread.currentThread().sleep(COUNT + SLOP); + Thread.sleep(COUNT + SLOP); assertEquals(COUNT, counter.get()); } =20 public void testCancelInCommittedTransaction() throws Exception { - Thread.currentThread().sleep(SLOP + DELAY); + Thread.sleep(SLOP + DELAY); WorkInfo[] workInfos =3D new WorkInfo[COUNT]; for (long i =3D 0; i < COUNT; i++) { workInfos[(int) i] =3D timer.scheduleAtFixedRate(key, userTask= Factory, userId, userKey, DELAY, DELAY); } - Thread.currentThread().sleep(SLOP + DELAY); + Thread.sleep(SLOP + DELAY); assertEquals(COUNT, counter.get()); TransactionContext transactionContext =3D transactionContextManage= r=2EnewContainerTransactionContext(); for (int i =3D 0; i < workInfos.length; i++) { workInfos[i].getExecutorFeedingTimerTask().cancel(); } - Thread.currentThread().sleep(SLOP + DELAY); + Thread.sleep(SLOP + DELAY); assertEquals(COUNT, counter.get()); transactionContext.commit(); - Thread.currentThread().sleep(SLOP + DELAY); + Thread.sleep(SLOP + DELAY); assertEquals(COUNT, counter.get()); } =20 public void testCancelInRolledBackTransaction() throws Exception { - Thread.currentThread().sleep(SLOP + DELAY); + Thread.sleep(SLOP + DELAY); WorkInfo[] workInfos =3D new WorkInfo[COUNT]; for (long i =3D 0; i < COUNT; i++) { workInfos[(int) i] =3D timer.scheduleAtFixedRate(key, userTask= Factory, userId, userKey, DELAY, DELAY); } - Thread.currentThread().sleep(SLOP + DELAY); + Thread.sleep(SLOP + DELAY); assertEquals(COUNT, counter.get()); TransactionContext transactionContext =3D transactionContextManage= r=2EnewContainerTransactionContext(); for (int i =3D 0; i < workInfos.length; i++) { workInfos[i].getExecutorFeedingTimerTask().cancel(); } - Thread.currentThread().sleep(SLOP + DELAY); + Thread.sleep(SLOP + DELAY); assertEquals(COUNT, counter.get()); transactionContext.rollback(); - Thread.currentThread().sleep(SLOP + DELAY); + Thread.sleep(SLOP + DELAY); // Catches up with two periods. assertEquals(3 * COUNT, counter.get()); } @@ -183,13 +178,13 @@ public void testRepeatCountFromPersisted() throws Exception { assert DELAY > 2 * SLOP; timer.scheduleAtFixedRate(key, userTaskFactory, userId, userKey, 0= L, DELAY); - Thread.currentThread().sleep(4 * DELAY + SLOP); + Thread.sleep(4 * DELAY + SLOP); timer.doStop(); assertEquals(5, counter.get()); =20 timer.doStart(); timer.playback(key, userTaskFactory); - Thread.currentThread().sleep(5 * DELAY + SLOP); + Thread.sleep(5 * DELAY + SLOP); assertEquals(2 * 5, counter.get()); =20 } Modified: geronimo/trunk/modules/transaction/src/java/org/apache/geronimo/t= ransaction/DefaultInstanceContext.java URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/transaction/src/j= ava/org/apache/geronimo/transaction/DefaultInstanceContext.java?view=3Ddiff= &r1=3D155375&r2=3D155376 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- geronimo/trunk/modules/transaction/src/java/org/apache/geronimo/transac= tion/DefaultInstanceContext.java (original) +++ geronimo/trunk/modules/transaction/src/java/org/apache/geronimo/transac= tion/DefaultInstanceContext.java Fri Feb 25 15:10:24 2005 @@ -29,10 +29,11 @@ * * */ public class DefaultInstanceContext implements InstanceContext { - private final Map connectionManagerMap =3D new HashMap(); private final Set unshareableResources; private final Set applicationManagedSecurityResources; + private int callDepth; + private boolean dead =3D false; =20 public DefaultInstanceContext(Set unshareableResources, Set applicatio= nManagedSecurityResources) { this.unshareableResources =3D unshareableResources; @@ -43,9 +44,6 @@ return null; } =20 - public void setId(Object id) { - } - public Object getContainerId() { return null; } @@ -62,6 +60,9 @@ public void afterCommit(boolean status) throws Exception { } =20 + public void unassociate() throws Throwable { + } + public Map getConnectionManagerMap() { return connectionManagerMap; } @@ -74,4 +75,24 @@ return applicationManagedSecurityResources; } =20 + public boolean isInCall() { + return callDepth > 0; + } + + public void enter() { + callDepth++; + } + + public void exit() { + assert isInCall(); + callDepth--; + } + + public boolean isDead() { + return dead; + } + + public void die() { + dead =3D true; + } } Modified: geronimo/trunk/modules/transaction/src/java/org/apache/geronimo/t= ransaction/InstanceContext.java URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/transaction/src/j= ava/org/apache/geronimo/transaction/InstanceContext.java?view=3Ddiff&r1=3D1= 55375&r2=3D155376 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- geronimo/trunk/modules/transaction/src/java/org/apache/geronimo/transac= tion/InstanceContext.java (original) +++ geronimo/trunk/modules/transaction/src/java/org/apache/geronimo/transac= tion/InstanceContext.java Fri Feb 25 15:10:24 2005 @@ -29,8 +29,6 @@ public interface InstanceContext { Object getId(); =20 - void setId(Object id); - Object getContainerId(); =20 void associate() throws Throwable; @@ -41,6 +39,8 @@ =20 void afterCommit(boolean status) throws Throwable; =20 + void unassociate() throws Throwable; + /** * IMPORTANT INVARIANT: this should always return a map, never null. * @return map of ConnectionManager to (list of ) managed connection i= nfo objects. @@ -51,4 +51,13 @@ =20 Set getApplicationManagedSecurityResources(); =20 + boolean isInCall(); + + void enter(); + + void exit(); + + boolean isDead(); + + void die(); } Modified: geronimo/trunk/modules/transaction/src/java/org/apache/geronimo/t= ransaction/context/InheritableTransactionContext.java URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/transaction/src/j= ava/org/apache/geronimo/transaction/context/InheritableTransactionContext.j= ava?view=3Ddiff&r1=3D155375&r2=3D155376 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- geronimo/trunk/modules/transaction/src/java/org/apache/geronimo/transac= tion/context/InheritableTransactionContext.java (original) +++ geronimo/trunk/modules/transaction/src/java/org/apache/geronimo/transac= tion/context/InheritableTransactionContext.java Fri Feb 25 15:10:24 2005 @@ -17,6 +17,10 @@ =20 package org.apache.geronimo.transaction.context; =20 +import java.util.Iterator; +import java.util.Map; +import java.util.HashMap; +import java.util.ArrayList; import javax.transaction.SystemException; import javax.transaction.Status; import javax.transaction.Transaction; @@ -27,16 +31,17 @@ import javax.transaction.RollbackException; =20 import org.apache.geronimo.transaction.ExtendedTransactionManager; +import org.apache.geronimo.transaction.ConnectionReleaser; +import org.apache.geronimo.transaction.InstanceContext; =20 /** - * - * * @version $Rev$ $Date$ */ public abstract class InheritableTransactionContext extends TransactionCon= text { private final ExtendedTransactionManager txnManager; private Transaction transaction; private boolean threadAssociated =3D false; + private Map managedConnections; =20 protected InheritableTransactionContext(ExtendedTransactionManager txn= Manager) { this.txnManager =3D txnManager; @@ -55,9 +60,26 @@ return transaction; } =20 + public void setManagedConnectionInfo(ConnectionReleaser key, Object in= fo) { + if (managedConnections =3D=3D null) { + managedConnections =3D new HashMap(); + } + managedConnections.put(key, info); + } + + public Object getManagedConnectionInfo(ConnectionReleaser key) { + if (managedConnections =3D=3D null) { + return null; + } + return managedConnections.get(key); + } + public boolean isActive() { + if (transaction =3D=3D null) { + return false; + } try { - int status =3D txnManager.getStatus(); + int status =3D transaction.getStatus(); return status =3D=3D Status.STATUS_ACTIVE || status =3D=3D Sta= tus.STATUS_MARKED_ROLLBACK; } catch (SystemException e) { return false; @@ -65,7 +87,6 @@ } =20 public boolean getRollbackOnly() throws SystemException { - Transaction transaction =3D getTransaction(); if (transaction =3D=3D null) { throw new IllegalStateException("There is no transaction in pr= ogress."); } @@ -77,7 +98,6 @@ } =20 public void setRollbackOnly() throws IllegalStateException, SystemExce= ption { - Transaction transaction =3D getTransaction(); if (transaction =3D=3D null) { throw new IllegalStateException("There is no transaction in pr= ogress."); } @@ -85,13 +105,16 @@ } =20 public void begin(long transactionTimeoutMilliseconds) throws SystemEx= ception, NotSupportedException { + assert transaction =3D=3D null: "Already associated with a transa= ction"; transaction =3D txnManager.begin(transactionTimeoutMilliseconds); threadAssociated =3D true; } =20 public void suspend() throws SystemException { Transaction suspendedTransaction =3D txnManager.suspend(); - assert (transaction =3D=3D suspendedTransaction) : "suspend did no= t return our transaction. ours: " + transaction + ", suspended returned: " = + suspendedTransaction; + if (transaction !=3D suspendedTransaction) { + throw new SystemException("Suspend did not return our transact= ion: expectedTx=3D" + transaction + ", suspendedTx=3D" + suspendedTransacti= on); + } threadAssociated =3D false; } =20 @@ -101,6 +124,29 @@ } =20 public boolean commit() throws HeuristicMixedException, HeuristicRollb= ackException, SystemException, RollbackException { + return complete(); + } + + public void rollback() throws SystemException { + setRollbackOnly(); + try { + complete(); + } catch (SystemException e) { + throw e; + } catch (RuntimeException e) { + throw e; + } catch (Error e) { + throw e; + } catch (Exception e) { + throw (SystemException) new SystemException("After commit of c= ontainer transaction failed").initCause(e); + } + } + + private boolean complete() throws HeuristicMixedException, HeuristicRo= llbackException, SystemException, RollbackException { + if (transaction =3D=3D null) { + throw new IllegalStateException("There is no transaction in pr= ogress."); + } + boolean wasCommitted =3D false; try { if (isRolledback()) { @@ -120,6 +166,14 @@ return false; } =20 + // verify our tx is the current tx associated with the thread + // this is really only an error case and should never happen, = but just to be sure double check + // immedately before committing using the transaction manager + Transaction currentTransaction =3D txnManager.getTransaction(); + if (currentTransaction !=3D transaction) { + throw new SystemException("An unknown transaction is curre= ntly associated with the thread: expectedTx=3D" + transaction + ", currentT= x=3D" + currentTransaction); + } + txnManager.commit(); wasCommitted =3D true; } catch (Throwable t) { @@ -130,23 +184,82 @@ } catch (Throwable e) { rollbackAndThrow("After commit of container transaction fa= iled", e); } finally { + unassociateAll(); connectorAfterCommit(); transaction =3D null; + threadAssociated =3D false; } } return wasCommitted; } =20 + private void beforeCommit() throws Throwable { + // @todo allow for enrollment during pre-commit + ArrayList toFlush =3D getAssociatedContexts(); + for (Iterator i =3D toFlush.iterator(); i.hasNext();) { + InstanceContext context =3D (InstanceContext) i.next(); + if (!context.isDead()) { + context.beforeCommit(); + } + } + } + + private void afterCommit(boolean status) throws Throwable { + Throwable firstThrowable =3D null; + ArrayList toFlush =3D getAssociatedContexts(); + for (Iterator i =3D toFlush.iterator(); i.hasNext();) { + InstanceContext context =3D (InstanceContext) i.next(); + if (!context.isDead()) { + try { + context.afterCommit(status); + } catch (Throwable e) { + if (firstThrowable =3D=3D null) { + firstThrowable =3D e; + } + } + } + } + + if (firstThrowable instanceof Error) { + throw (Error) firstThrowable; + } else if (firstThrowable instanceof Exception) { + throw (Exception) firstThrowable; + } else if (firstThrowable !=3D null) { + throw (SystemException) new SystemException().initCause(firstT= hrowable); + } + } + + private void connectorAfterCommit() { + if (managedConnections !=3D null) { + for (Iterator entries =3D managedConnections.entrySet().iterat= or(); entries.hasNext();) { + Map.Entry entry =3D (Map.Entry) entries.next(); + ConnectionReleaser key =3D (ConnectionReleaser) entry.getK= ey(); + key.afterCompletion(entry.getValue()); + } + //If BeanTransactionContext never reuses the same instance for= sequential BMT, this + //clearing is unnecessary. + managedConnections.clear(); + } + } + private boolean isRolledback() throws SystemException { int status; try { status =3D transaction.getStatus(); } catch (SystemException e) { - txnManager.rollback(); + transaction.rollback(); throw e; } =20 if (status =3D=3D Status.STATUS_MARKED_ROLLBACK) { + // verify our tx is the current tx associated with the thread + // this is really only an error case and should never happen, = but just to be sure double check + // immedately before committing using the transaction manager + Transaction currentTransaction =3D txnManager.getTransaction(); + if (currentTransaction !=3D transaction) { + throw new SystemException("An unknown transaction is curre= ntly associated with the thread: expectedTx=3D" + transaction + ", currentT= x=3D" + currentTransaction); + } + // we need to rollback txnManager.rollback(); return true; @@ -160,7 +273,6 @@ =20 private void rollbackAndThrow(String message, Throwable throwable) thr= ows HeuristicMixedException, HeuristicRollbackException, SystemException, R= ollbackException { try { - // just incase there is a junk transaction on the thread if (txnManager.getStatus() !=3D Status.STATUS_NO_TRANSACTION) { txnManager.rollback(); } @@ -168,6 +280,18 @@ log.error("Unable to roll back transaction", t); } =20 + try { + // make doubly sure our transaction was rolled back + // this can happen when there was a junk transaction on the th= read + int status =3D transaction.getStatus(); + if (status !=3D Status.STATUS_ROLLEDBACK && + status !=3D Status.STATUS_ROLLING_BACK) { + transaction.rollback(); + } + } catch (Throwable t) { + log.error("Unable to roll back transaction", t); + } + if (throwable instanceof HeuristicMixedException) { throw (HeuristicMixedException) throwable; } else if (throwable instanceof HeuristicRollbackException) { @@ -182,41 +306,6 @@ throw (RuntimeException) throwable; } else { throw (SystemException) new SystemException(message).initCause= (throwable); - } - } - - public void rollback() throws SystemException { - try { - try { - if (txnManager.getStatus() !=3D Status.STATUS_NO_TRANSACTI= ON) { - txnManager.rollback(); - } - } finally { - try { - afterCommit(false); - } catch (Throwable e) { - try { - // just incase there is a junk transaction on the = thread - if (txnManager.getStatus() !=3D Status.STATUS_NO_T= RANSACTION) { - txnManager.rollback(); - } - } catch (Throwable t1) { - log.error("Unable to roll back transaction", t1); - } - - if (e instanceof SystemException) { - throw (SystemException) e; - } else if (e instanceof Error) { - throw (Error) e; - } else if (e instanceof RuntimeException) { - throw (RuntimeException) e; - } - throw (SystemException) new SystemException("After com= mit of container transaction failed").initCause(e); - } - } - } finally { - connectorAfterCommit(); - transaction =3D null; } } } Modified: geronimo/trunk/modules/transaction/src/java/org/apache/geronimo/t= ransaction/context/TransactionContext.java URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/transaction/src/j= ava/org/apache/geronimo/transaction/context/TransactionContext.java?view=3D= diff&r1=3D155375&r2=3D155376 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- geronimo/trunk/modules/transaction/src/java/org/apache/geronimo/transac= tion/context/TransactionContext.java (original) +++ geronimo/trunk/modules/transaction/src/java/org/apache/geronimo/transac= tion/context/TransactionContext.java Fri Feb 25 15:10:24 2005 @@ -18,27 +18,21 @@ package org.apache.geronimo.transaction.context; =20 import java.util.ArrayList; -import java.util.HashMap; import java.util.Iterator; -import java.util.Map; import javax.transaction.HeuristicMixedException; import javax.transaction.HeuristicRollbackException; import javax.transaction.InvalidTransactionException; import javax.transaction.RollbackException; import javax.transaction.SystemException; -import javax.transaction.Transaction; =20 import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.geronimo.transaction.ConnectionReleaser; import org.apache.geronimo.transaction.DoubleKeyedHashMap; import org.apache.geronimo.transaction.InstanceContext; import org.tranql.cache.InTxCache; =20 =20 /** - * - * * @version $Rev$ $Date$ */ public abstract class TransactionContext { @@ -56,9 +50,12 @@ private InstanceContext currentContext; private final DoubleKeyedHashMap associatedContexts =3D new DoubleKeye= dHashMap(); private final DoubleKeyedHashMap dirtyContexts =3D new DoubleKeyedHash= Map(); - private Map managedConnections; private InTxCache inTxCache; =20 + public abstract boolean getRollbackOnly() throws SystemException; + + public abstract void setRollbackOnly() throws SystemException; + public abstract void suspend() throws SystemException; =20 public abstract void resume() throws SystemException, InvalidTransacti= onException; @@ -73,21 +70,51 @@ } } =20 - public final void unassociate(Object containerId, Object id) throws Ex= ception { - associatedContexts.remove(containerId, id); - dirtyContexts.remove(containerId, id); + public final void unassociate(InstanceContext context) throws Throwabl= e { + associatedContexts.remove(context.getContainerId(), context.getId(= )); + context.unassociate(); + } + + public final void unassociate(Object containerId, Object id) throws Th= rowable { + InstanceContext context =3D (InstanceContext) associatedContexts.r= emove(containerId, id); + if (context !=3D null) { + context.unassociate(); + } + } + + public final InstanceContext getContext(Object containerId, Object id)= { + return (InstanceContext) associatedContexts.get(containerId, id); + } + + protected final ArrayList getAssociatedContexts() { + return new ArrayList(associatedContexts.values()); + } + + protected final void unassociateAll() { + ArrayList toFlush =3D getAssociatedContexts(); + for (Iterator i =3D toFlush.iterator(); i.hasNext();) { + InstanceContext context =3D (InstanceContext) i.next(); + try { + context.unassociate(); + } catch (Throwable throwable) { + log.warn("Error while unassociating instance from transact= ion context: " + context, throwable); + } + } } =20 - public final InstanceContext beginInvocation(InstanceContext context) { + public final InstanceContext beginInvocation(InstanceContext context) = throws Throwable { if (context.getId() !=3D null) { + associate(context); dirtyContexts.put(context.getContainerId(), context.getId(), c= ontext); } + context.enter(); InstanceContext caller =3D currentContext; currentContext =3D context; return caller; } =20 public final void endInvocation(InstanceContext caller) { + currentContext.exit(); currentContext =3D caller; } =20 @@ -97,7 +124,9 @@ dirtyContexts.clear(); for (Iterator i =3D toFlush.iterator(); i.hasNext();) { InstanceContext context =3D (InstanceContext) i.next(); - context.flush(); + if (!context.isDead()) { + context.flush(); + } } } if (currentContext !=3D null && currentContext.getId() !=3D null) { @@ -108,42 +137,6 @@ } } =20 - protected void beforeCommit() throws Throwable { - // @todo allow for enrollment during pre-commit - ArrayList toFlush =3D new ArrayList(associatedContexts.values()); - for (Iterator i =3D toFlush.iterator(); i.hasNext();) { - InstanceContext context =3D (InstanceContext) i.next(); - context.beforeCommit(); - } - } - - protected void afterCommit(boolean status) throws Throwable { - Throwable firstThrowable =3D null; - ArrayList toFlush =3D new ArrayList(associatedContexts.values()); - for (Iterator i =3D toFlush.iterator(); i.hasNext();) { - InstanceContext context =3D (InstanceContext) i.next(); - try { - context.afterCommit(status); - } catch (Throwable e) { - if (firstThrowable =3D=3D null) { - firstThrowable =3D e; - } - } - } - - if (firstThrowable instanceof Error) { - throw (Error) firstThrowable; - } else if (firstThrowable instanceof Exception) { - throw (Exception) firstThrowable; - } else if (firstThrowable !=3D null) { - throw (SystemException) new SystemException().initCause(firstT= hrowable); - } - } - - public final InstanceContext getContext(Object containerId, Object id)= { - return (InstanceContext) associatedContexts.get(containerId, id); - } - public final void setInTxCache(InTxCache inTxCache) { this.inTxCache =3D inTxCache; } @@ -151,42 +144,4 @@ public final InTxCache getInTxCache() { return inTxCache; } - - //Geronimo connector framework support - public void setManagedConnectionInfo(ConnectionReleaser key, Object in= fo) { - if (managedConnections =3D=3D null) { - managedConnections =3D new HashMap(); - } - managedConnections.put(key, info); - } - - public Object getManagedConnectionInfo(ConnectionReleaser key) { - if (managedConnections =3D=3D null) { - return null; - } - return managedConnections.get(key); - } - - /** - * determines if the transaction is in a pre-prepared state - * of STATUS_ACTIVE or STATUS_MARKED_ROLLBACK. - * @return true if more work can be done in the transaction (although = it might be forced to roll back) - */ - public abstract boolean isActive(); - - public abstract Transaction getTransaction(); - - protected void connectorAfterCommit() { - if (managedConnections !=3D null) { - for (Iterator entries =3D managedConnections.entrySet().iterat= or(); entries.hasNext();) { - Map.Entry entry =3D (Map.Entry) entries.next(); - ConnectionReleaser key =3D (ConnectionReleaser) entry.getK= ey(); - key.afterCompletion(entry.getValue()); - } - //If BeanTransactionContext never reuses the same instance for= sequential BMT, this - //clearing is unnecessary. - managedConnections.clear(); - } - } - } Modified: geronimo/trunk/modules/transaction/src/java/org/apache/geronimo/t= ransaction/context/UnspecifiedTransactionContext.java URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/transaction/src/j= ava/org/apache/geronimo/transaction/context/UnspecifiedTransactionContext.j= ava?view=3Ddiff&r1=3D155375&r2=3D155376 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- geronimo/trunk/modules/transaction/src/java/org/apache/geronimo/transac= tion/context/UnspecifiedTransactionContext.java (original) +++ geronimo/trunk/modules/transaction/src/java/org/apache/geronimo/transac= tion/context/UnspecifiedTransactionContext.java Fri Feb 25 15:10:24 2005 @@ -17,16 +17,18 @@ =20 package org.apache.geronimo.transaction.context; =20 -import javax.transaction.Transaction; - -import org.apache.geronimo.transaction.ConnectionReleaser; - - /** * @version $Rev$ $Date$ */ public class UnspecifiedTransactionContext extends TransactionContext { - public void begin() { + private boolean failed =3D false; + + public boolean getRollbackOnly() { + return failed; + } + + public void setRollbackOnly() { + this.failed =3D true; } =20 public void suspend() { @@ -36,33 +38,28 @@ } =20 public boolean commit() { + complete(); + return true; + } + + public void rollback() { + setRollbackOnly(); + complete(); + } + + private void complete() { try { - flushState(); + if (!failed) { + flushState(); + } } catch (Error e) { throw e; } catch (RuntimeException re) { throw re; } catch (Throwable e) { log.error("Unable to flush state, continuing", e); + } finally { + unassociateAll(); } - return true; - } - - public void rollback() { - } - - public void setManagedConnectionInfo(ConnectionReleaser key, Object in= fo) { - } - - public Object getManagedConnectionInfo(ConnectionReleaser key) { - return null; - } - - public boolean isActive() { - return false; - } - - public Transaction getTransaction() { - return null; } }