com.caucho.transaction
Class TransactionImpl

java.lang.Object
  extended by com.caucho.transaction.TransactionImpl
All Implemented Interfaces:
AlarmListener, java.util.EventListener, Transaction

public class TransactionImpl
extends java.lang.Object
implements Transaction, AlarmListener

Implementation of the transaction. Transactions are normally associated with a single thread.


Method Summary
 boolean allowLocalTransactionOptimization()
          Returns true if the local transaction optimization would be allowed.
 void close()
          Close the transaction, rolling back everything and removing all enlisted resources.
 void commit()
          Commit the transaction.
 boolean delistResource(XAResource resource, int flag)
          De-lists a resource from the current transaction
 boolean enlistResource(XAResource resource)
          Enlists a resource with the current transaction.
 java.lang.Object getAttribute(java.lang.String var)
          Gets an attribute.
static TransactionImpl getCurrent()
           
 int getEnlistedResourceCount()
          Returns the current number of resources.
 java.lang.Object getResource(java.lang.Object key)
          Gets a Resource from the underlying map.
 int getStatus()
          Returns the status of this transaction
 int getTransactionTimeout()
          sets the timeout for the transaction
 Xid getXid()
           
 void handleAlarm(Alarm alarm)
          Handles a callback from an alarm.
 boolean isActive()
           
 boolean isEmpty()
          Return true if the transaction has no resources.
 boolean isRollbackOnly()
           
 void putResource(java.lang.Object key, java.lang.Object resource)
           
 void putResource(java.lang.Object key, XAResource resource)
          Puts a resource into a map of resources and adds the resource to the transaction.
 void registerInterposedSynchronization(Synchronization synchronization)
          Registers synchronization interposed by container resources such as the JPA persistence provider.
 void registerSynchronization(Synchronization synchronization)
          Register a synchronization callback
 void rollback()
          Rollback the transaction.
 void setAttribute(java.lang.String var, java.lang.Object value)
          Adds an attribute.
 void setRollbackOnly()
          Force any completion to be a roll-back.
 void setRollbackOnly(java.lang.Throwable exn)
          Force any completion to be a rollback.
 void setTransactionTimeout(int seconds)
          sets the timeout for the transaction
 void setUserTransaction(UserTransactionImpl ut)
          Sets the user transaction.
 java.lang.String toString()
          Printable version of the transaction.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

getCurrent

public static TransactionImpl getCurrent()

setUserTransaction

public void setUserTransaction(UserTransactionImpl ut)
Sets the user transaction.


getXid

public Xid getXid()

isActive

public boolean isActive()

putResource

public void putResource(java.lang.Object key,
                        XAResource resource)
                 throws RollbackException,
                        SystemException
Puts a resource into a map of resources and adds the resource to the transaction.

Parameters:
key - User defined key for the Resource.
resource - The Resource to enlist in the transaction.
Throws:
RollbackException - If a roll-back occurs.
SystemException - If an unexpected problem occurs.

putResource

public void putResource(java.lang.Object key,
                        java.lang.Object resource)

getResource

public java.lang.Object getResource(java.lang.Object key)
Gets a Resource from the underlying map.

Parameters:
key - User defined key for the resource.
Returns:
The Resource mapped to the key.

enlistResource

public boolean enlistResource(XAResource resource)
                       throws RollbackException,
                              SystemException
Enlists a resource with the current transaction. Example resources are database or JMS connections.

Specified by:
enlistResource in interface Transaction
Returns:
true if successful
Throws:
RollbackException
SystemException

delistResource

public boolean delistResource(XAResource resource,
                              int flag)
                       throws SystemException
De-lists a resource from the current transaction

Specified by:
delistResource in interface Transaction
Parameters:
resource - the resource to delist
flag - XXX: ???
Returns:
true if successful
Throws:
SystemException

getEnlistedResourceCount

public int getEnlistedResourceCount()
Returns the current number of resources.


isEmpty

public boolean isEmpty()
Return true if the transaction has no resources.


allowLocalTransactionOptimization

public boolean allowLocalTransactionOptimization()
Returns true if the local transaction optimization would be allowed.


setTransactionTimeout

public void setTransactionTimeout(int seconds)
                           throws SystemException
sets the timeout for the transaction

Throws:
SystemException

getTransactionTimeout

public int getTransactionTimeout()
                          throws SystemException
sets the timeout for the transaction

Throws:
SystemException

setAttribute

public void setAttribute(java.lang.String var,
                         java.lang.Object value)
Adds an attribute.


getAttribute

public java.lang.Object getAttribute(java.lang.String var)
Gets an attribute.


registerInterposedSynchronization

public void registerInterposedSynchronization(Synchronization synchronization)
Registers synchronization interposed by container resources such as the JPA persistence provider.

Parameters:
synchronization - Interposed synchronization.

registerSynchronization

public void registerSynchronization(Synchronization synchronization)
Register a synchronization callback

Specified by:
registerSynchronization in interface Transaction

getStatus

public int getStatus()
Returns the status of this transaction

Specified by:
getStatus in interface Transaction

setRollbackOnly

public void setRollbackOnly()
                     throws SystemException
Force any completion to be a roll-back.

Specified by:
setRollbackOnly in interface Transaction
Throws:
SystemException

setRollbackOnly

public void setRollbackOnly(java.lang.Throwable exn)
Force any completion to be a rollback.


isRollbackOnly

public boolean isRollbackOnly()

commit

public void commit()
            throws RollbackException,
                   HeuristicMixedException,
                   HeuristicRollbackException,
                   SystemException
Commit the transaction.

Specified by:
commit in interface Transaction
Throws:
RollbackException
HeuristicMixedException
HeuristicRollbackException
SystemException

rollback

public void rollback()
Rollback the transaction.

Specified by:
rollback in interface Transaction

handleAlarm

public void handleAlarm(Alarm alarm)
Description copied from interface: AlarmListener
Handles a callback from an alarm.

Specified by:
handleAlarm in interface AlarmListener

close

public void close()
Close the transaction, rolling back everything and removing all enlisted resources.


toString

public java.lang.String toString()
Printable version of the transaction.

Overrides:
toString in class java.lang.Object