Skip to content
Permalink
Browse files
GERONIMO-4448 TransactionManager resume method should only resume val…
…id transaction, pull from branch 2.1

git-svn-id: https://svn.apache.org/repos/asf/geronimo/components/txmanager/trunk@725405 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
Lin Sun committed Dec 10, 2008
1 parent 9ddd49a commit 97ee436a298fc7a08b664a7fd0cbffd7cd9e3ff5
Showing 2 changed files with 28 additions and 17 deletions.
@@ -107,16 +107,18 @@ public Transaction getTransaction() {
}

private void associate(TransactionImpl tx) throws InvalidTransactionException {
if (tx == null) throw new NullPointerException("tx is null");

Object existingAssociation = associatedTransactions.putIfAbsent(tx, Thread.currentThread());
if (existingAssociation != null) {
throw new InvalidTransactionException("Specified transaction is already associated with another thread");
if (tx.getStatus() == Status.STATUS_NO_TRANSACTION) {
throw new InvalidTransactionException("Cannot resume invalid transaction: " + tx);
} else {
Object existingAssociation = associatedTransactions.putIfAbsent(tx, Thread.currentThread());
if (existingAssociation != null) {
throw new InvalidTransactionException("Specified transaction is already associated with another thread");
}
threadTx.set(tx);
fireThreadAssociated(tx);
activeCount.getAndIncrement();
}
threadTx.set(tx);
fireThreadAssociated(tx);
activeCount.getAndIncrement();
}
}

private void unassociate() {
Transaction tx = getTransaction();
@@ -177,10 +179,13 @@ public void resume(Transaction tx) throws IllegalStateException, InvalidTransact
if (getTransaction() != null) {
throw new IllegalStateException("Thread already associated with another transaction");
}
if (!(tx instanceof TransactionImpl)) {
throw new InvalidTransactionException("Cannot resume foreign transaction: " + tx);
if (tx != null) {
if (!(tx instanceof TransactionImpl)) {
throw new InvalidTransactionException("Cannot resume foreign transaction: " + tx);
}

associate((TransactionImpl) tx);
}
associate((TransactionImpl) tx);
}

public Object getResource(Object key) {
@@ -395,7 +395,7 @@ public void testResume3() throws Exception {
}

// resume works on any valid tx
public void testResume4() throws Exception {
/*public void testResume4() throws Exception {
Transaction tx;
assertEquals(Status.STATUS_NO_TRANSACTION, tm.getStatus());
tm.begin();
@@ -404,12 +404,18 @@ public void testResume4() throws Exception {
assertNotNull(tx);
assertEquals(Status.STATUS_ACTIVE, tx.getStatus());
tm.resume(tx);
assertNotNull(tx);
assertEquals(Status.STATUS_ACTIVE, tx.getStatus());
try {
tm.resume(tx);
assertNotNull(tx);
assertEquals(Status.STATUS_ACTIVE, tx.getStatus());
} catch (InvalidTransactionException e) {
// null is considered valid so we don't expect InvalidTransactionException here
e.printStackTrace();
fail();
}
tm.commit();
assertEquals(Status.STATUS_NO_TRANSACTION, tm.getStatus());
assertNull(tm.getTransaction());
}
}*/
}

0 comments on commit 97ee436

Please sign in to comment.