| Method from org.jboss.tm.TransactionLocal Detail: |
protected boolean containsValue(Transaction tx) {
return delegate.containsValue(this, tx);
}
does Transaction contain object? |
public Object get() {
return get(getTransaction());
}
Returns the value of this TransactionLocal variable associated with the
thread context transaction. Creates and initializes the copy if this is
the first time the method is called in a transaction. |
public Object get(Transaction transaction) {
if (transaction == null) return initialValue();
Object value = getValue(transaction);
// is we didn't get a value initalize this object with initialValue()
if(value == null)
{
// get the initial value
value = initialValue();
// if value is null replace it with the null value standin
if(value == null)
{
value = NULL_VALUE;
}
// store the value
storeValue(transaction, value);
}
// if the value is the null standin return null
if(value == NULL_VALUE)
{
return null;
}
// finall return the value
return value;
}
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. |
protected Transaction getTransaction() {
try
{
return transactionManager.getTransaction();
}
catch(SystemException e)
{
throw new IllegalStateException("An error occured while getting the " +
"transaction associated with the current thread: " + e);
}
}
|
protected Object getValue(Transaction tx) {
return delegate.getValue(this, tx);
}
get the transaction local value. |
protected void initDelegate() {
if (transactionManager instanceof TransactionLocalDelegate)
delegate = (TransactionLocalDelegate) transactionManager;
else
delegate = new TransactionLocalDelegateImpl(transactionManager);
}
|
protected Object initialValue() {
return null;
}
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
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
constructor and return the newly constructed object. |
public void set(Object value) {
set(getTransaction(), value);
}
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
have no need for this functionality. |
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
// initialization.
if(!containsValue(transaction))
{
initialValue();
}
// if value is null replace it with the null value standin
if(value == null)
{
value = NULL_VALUE;
}
// finally store the value
storeValue(transaction, value);
}
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
have no need for this functionality. |
protected void storeValue(Transaction tx,
Object value) {
delegate.storeValue(this, tx, value);
}
put the value in the TransactionImpl map |