FileDocCategorySizeDatePackage
JTATransactionController.javaAPI DocGlassfish v2 API11569Tue May 22 16:54:54 BST 2007oracle.toplink.essentials.transaction

JTATransactionController

public class JTATransactionController extends AbstractTransactionController

Purpose: TransactionController implementation for JTA 1.0

Description: Implements the required behaviour for controlling JTA 1.0 transactions. Specific JTA implementations may need to extend this class when special controller behavior is necessary.

The JTA TransactionManager must be obtained and set on the instance in order for a Synchronization listener to be registered against the transaction. This can be done either by extending this class and defining acquireTransactionManager() to return the manager for the server, or by using this class and explicitly calling the setTransactionManager() method on it after the fact. e.g. TransactionManager mgr = controller.jndiLookup("java:comp/TransactionManager"); controller.setTransactionManager(mgr);

If a different listener needs to be used for synchronization, the SynchronizationListenerFactory should be set on the controller instance. The listener subclass should implement the factory interface, so that setting the factory is simply a matter of assigning an instance of the listener. e.g. controller.setSynchronizationListenerFactory( new DifferentServerSynchronizationListener()); The default listener factory creates instances of JTATransactionListener.

see
JTASynchronizationListener
see
AbstractTransactionController

Fields Summary
protected TransactionManager
transactionManager
static String[]
codes
INTERNAL: Convert the status to a string for tracing.
Constructors Summary
public JTATransactionController()
PUBLIC: Return a new controller for use with a JTA 1.0 compliant TransactionManager.

        super();
        listenerFactory = (SynchronizationListenerFactory)new JTASynchronizationListener();
        try {
            transactionManager = acquireTransactionManager();
        } catch (Exception ex) {
            throw TransactionException.errorObtainingTransactionManager(ex);
        }
    
Methods Summary
protected javax.transaction.TransactionManageracquireTransactionManager()
INTERNAL: Obtain and return the JTA TransactionManager on this platform. By default do nothing. This method can be can be overridden by subclasses to obtain the transaction manager by whatever means is appropriate to the server. This method is invoked by the constructor to initialize the transaction manager at instance-creation time. Alternatively the transaction manager can be set directly on the controller instance using the setTransactionManager() method after the instance has been created.

return
The TransactionManager for the transaction system

        return null;
    
protected voidbeginTransaction_impl()
INTERNAL: Begin an external transaction.

        getTransactionManager().begin();
    
protected booleancanBeginTransaction_impl(java.lang.Object status)
INTERNAL: Return true if the status indicates that a transaction can be started. This would normally mean that no transaction is currently active.

param
status The current transaction status
return
true if the current state allows for a transaction to be started

        return getIntStatus(status) == Status.STATUS_NO_TRANSACTION;
    
protected booleancanCommitTransaction_impl(java.lang.Object status)
INTERNAL: Return true if the status indicates that a transaction can be committed. This would normally mean that a transaction is currently active.

param
status The current transaction status
return
true if the current state allows for a transaction to be committed

        return getIntStatus(status) == Status.STATUS_ACTIVE;
    
protected booleancanIssueSQLToDatabase_impl(java.lang.Object status)
INTERNAL: Return true if the status indicates that the SQL should be issued to the db. This would normally mean that a transaction was active.

param
status The current transaction status
return
true if the current state allows for the SQL to be sent to the database

        int stat = getIntStatus(status);
        return ((stat == Status.STATUS_ACTIVE) || (stat == Status.STATUS_PREPARING));
    
protected booleancanMergeUnitOfWork_impl(java.lang.Object status)
INTERNAL: Return true if the status indicates that the unit of work should be merged into the shared cache. This would normally mean that the transaction was committed successfully.

param
status The current transaction status
return
true if the current state dictates that the unit of work should be merged

        return getIntStatus(status) == Status.STATUS_COMMITTED;
    
protected booleancanRollbackTransaction_impl(java.lang.Object status)
INTERNAL: Return true if the status indicates that a transaction can be rolled back. This would normally mean that a transaction is currently active.

param
status The current transaction status
return
true if the current state allows for a transaction to be rolled back

        return getIntStatus(status) == Status.STATUS_ACTIVE;
    
protected voidcommitTransaction_impl()
INTERNAL: Commit the external transaction.

        getTransactionManager().commit();
    
protected intgetIntStatus(java.lang.Object status)
INTERNAL: Convenience method to return the int value of the transaction status. Assumes that the status object is an Integer.

        return ((Integer)status).intValue();
    
protected java.lang.ObjectgetTransactionKey_impl(java.lang.Object transaction)
INTERNAL: Return a key for the specified external transaction object. The key is just something that can be inserted into a hashtable (must support hashCode() and equals() methods).

param
transaction The transaction to which the returned key applies (may be null)
return
A key for the passed in transaction, or null if no transaction specified

        // Use the transaction itself as the key
        return transaction;
    
public javax.transaction.TransactionManagergetTransactionManager()
PUBLIC: Return the transaction manager used to control the JTA transactions.

return
The JTA TransactionManager that is used to obtain transaction state information and control the active transaction.

        return transactionManager;
    
protected java.lang.ObjectgetTransactionStatus_impl()
INTERNAL: Return the transaction status as an object. We will pass around Integers that wrap the int JTA status values.

return
The current transaction status

        return new Integer(getTransactionManager().getStatus());
    
protected java.lang.ObjectgetTransaction_impl()
INTERNAL: Return the active external transaction, or null if none is currently active for this thread.

return
The active transaction object or id, or null if no transaction is active

        return getTransactionManager().getTransaction();
    
public booleanisRolledBack_impl(java.lang.Object status)
INTERNAL: Return true if the transaction is rolled back.

        return getIntStatus(status) == Status.STATUS_ROLLEDBACK;
    
protected voidmarkTransactionForRollback_impl()
INTERNAL: Mark the external transaction for rollback.

        getTransactionManager().setRollbackOnly();
    
protected voidregisterSynchronization_impl(oracle.toplink.essentials.transaction.AbstractSynchronizationListener listener, java.lang.Object txn)
INTERNAL: Register the specified synchronization listener with the given active transaction.

param
listener The synchronization listener created for this transaction
param
txn The active transaction for which notification is being requested

        ((Transaction)txn).registerSynchronization((Synchronization)listener);
    
protected voidrollbackTransaction_impl()
INTERNAL: Roll back the external transaction.

        getTransactionManager().rollback();
    
public voidsetTransactionManager(javax.transaction.TransactionManager mgr)
PUBLIC: Set the transaction manager used to control the JTA transactions.

param
mgr A valid JTA TransactionManager that can be accessed by this controller to obtain transaction state information and control the active transaction.

        transactionManager = mgr;
    
protected java.lang.StringstatusToString_impl(java.lang.Object status)


        
        int statusCode = getIntStatus(status);
        return codes[statusCode];