[jboss-cvs] JBossAS SVN: r65588 - branches/Branch_4_2/transaction/src/main/org/jboss/tm.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Sep 24 11:25:48 EDT 2007
Author: jhalliday
Date: 2007-09-24 11:25:48 -0400 (Mon, 24 Sep 2007)
New Revision: 65588
Modified:
branches/Branch_4_2/transaction/src/main/org/jboss/tm/TransactionLocal.java
Log:
Added fix to make TransactionLocal.get() mask IllegalStateExceptions. The old delegate did not throw them, but the new JBossTS one does and the client code can't alway cope.
Modified: branches/Branch_4_2/transaction/src/main/org/jboss/tm/TransactionLocal.java
===================================================================
--- branches/Branch_4_2/transaction/src/main/org/jboss/tm/TransactionLocal.java 2007-09-24 15:24:15 UTC (rev 65587)
+++ branches/Branch_4_2/transaction/src/main/org/jboss/tm/TransactionLocal.java 2007-09-24 15:25:48 UTC (rev 65588)
@@ -36,11 +36,11 @@
* @author <a href="mailto:bill at jboss.org">Bill Burke</a>
* @version $Revision$
*/
-public class TransactionLocal
+public class TransactionLocal
{
/**
- * To simplify null values handling in the preloaded data pool we use
+ * To simplify null values handling in the preloaded data pool we use
* this value instead of 'null'
*/
private static final Object NULL_VALUE = new Object();
@@ -91,9 +91,9 @@
/**
* Lock the TransactionLocal using the current transaction<p>
- *
+ *
* WARN: The current implemention just "locks the transactions"
- *
+ *
* @throws IllegalStateException if the transaction is not active
* @throws InterruptedException if the thread is interrupted
*/
@@ -101,12 +101,12 @@
{
lock(getTransaction());
}
-
+
/**
* Lock the TransactionLocal using the provided transaction<p>
- *
+ *
* WARN: The current implemention just "locks the transactions"
- *
+ *
* @param transaction the transaction
* @throws IllegalStateException if the transaction is not active
* @throws InterruptedException if the thread is interrupted
@@ -116,7 +116,7 @@
// ignore when there is no transaction
if (transaction == null)
return;
-
+
delegate.lock(this, transaction);
}
@@ -127,10 +127,10 @@
{
unlock(getTransaction());
}
-
+
/**
* Unlock the ThreadLocal using the provided transaction
- *
+ *
* @param transaction the transaction
*/
public void unlock(Transaction transaction)
@@ -143,18 +143,18 @@
}
/**
- * Returns the initial value for this thransaction local. This method
+ * Returns the initial value for this thransaction local. This method
* will be called once per accessing transaction for each TransactionLocal,
- * the first time each transaction accesses the variable with get or set.
- * If the programmer desires TransactionLocal variables to be initialized to
+ * the first time each transaction accesses the variable with get or set.
+ * If the programmer desires TransactionLocal variables to be initialized to
* some value other than null, TransactionLocal must be subclassed, and this
- * method overridden. Typically, an anonymous inner class will be used.
- * Typical implementations of initialValue will call an appropriate
+ * method overridden. Typically, an anonymous inner class will be used.
+ * Typical implementations of initialValue will call an appropriate
* constructor and return the newly constructed object.
*
* @return the initial value for this TransactionLocal
*/
- protected Object initialValue()
+ protected Object initialValue()
{
return null;
}
@@ -172,7 +172,7 @@
* put the value in the TransactionImpl map
*/
protected void storeValue(Transaction tx, Object value)
- {
+ {
delegate.storeValue(this, tx, value);
}
@@ -198,11 +198,11 @@
/**
- * Returns the value of this TransactionLocal variable associated with the
- * specified transaction. Creates and initializes the copy if this is the
+ * Returns the value of this TransactionLocal variable associated with the
+ * specified transaction. Creates and initializes the copy if this is the
* first time the method is called in a transaction.
*
- * @param transaction the transaction for which the variable it to
+ * @param transaction the transaction for which the variable it to
* be retrieved
* @return the value of this TransactionLocal
* @throws IllegalStateException if an error occures while registering
@@ -219,7 +219,7 @@
{
// get the initial value
value = initialValue();
-
+
// if value is null replace it with the null value standin
if(value == null)
{
@@ -227,7 +227,18 @@
}
// store the value
- storeValue(transaction, value);
+ try
+ {
+ storeValue(transaction, value);
+ }
+ catch(IllegalStateException e)
+ {
+ // depending on the delegate implementation it may be considered an error to
+ // call storeValue after the tx has ended. Further, the tx ending may have
+ // caused the disposal of a previously stored initial value.
+ // for user convenience we ignore such errors and return the initialvalue here.
+ return initialValue();
+ }
}
// if the value is the null standin return null
@@ -241,12 +252,12 @@
}
/**
- * Sets the value of this TransactionLocal variable associtated with the
+ * Sets the value of this TransactionLocal variable associtated with the
* thread context transaction. This is only used to change the value from
- * the one assigned by the initialValue method, and many applications will
+ * the one assigned by the initialValue method, and many applications will
* have no need for this functionality.
*
- * @param value the value to be associated with the thread context
+ * @param value the value to be associated with the thread context
* transactions's TransactionLocal
*/
public void set(Object value)
@@ -255,20 +266,20 @@
}
/**
- * Sets the value of this TransactionLocal variable associtated with the
+ * Sets the value of this TransactionLocal variable associtated with the
* specified transaction. This is only used to change the value from
- * the one assigned by the initialValue method, and many applications will
+ * the one assigned by the initialValue method, and many applications will
* have no need for this functionality.
*
* @param transaction the transaction for which the value will be set
- * @param value the value to be associated with the thread context
+ * @param value the value to be associated with the thread context
* transactions's TransactionLocal
*/
public void set(Transaction transaction, Object value)
{
if (transaction == null) throw new IllegalStateException("there is no transaction");
// If this transaction is unknown, register for synchroniztion callback,
- // and call initialValue to give subclasses a chance to do some
+ // and call initialValue to give subclasses a chance to do some
// initialization.
if(!containsValue(transaction))
{
@@ -284,7 +295,7 @@
// finally store the value
storeValue(transaction, value);
}
-
+
public Transaction getTransaction()
{
try
More information about the jboss-cvs-commits
mailing list