javax.transaction
Interface UserTransaction


public abstract interface UserTransaction

The UserTransaction interface defines the methods that allow an application to explicitly manage transaction boundaries.


Field Summary
static int STATUS_ACTIVE
          A transaction is associated with the target object and it is in the active state.
static int STATUS_COMMITTED
          A transaction is associated with the target object and it has been committed.
static int STATUS_COMMITTING
          A transaction is associated with the target object and it is in the process of committing.
static int STATUS_MARKED_ROLLBACK
          A transaction is associated with the target object and it has been marked for rollback, perhaps as a result of a setRollbackOnly operation.
static int STATUS_NO_TRANSACTION
          No transaction is currently associated with the target object.
static int STATUS_PREPARED
          A transaction is associated with the target object and it has been prepared, i.e.
static int STATUS_PREPARING
          A transaction is associated with the target object and it is in the process of preparing.
static int STATUS_ROLLEDBACK
          A transaction is associated with the target object and the outcome has been determined as rollback.
static int STATUS_ROLLING_BACK
          A transaction is associated with the target object and it is in the process of rolling back.
static int STATUS_UNKNOWN
          A transaction is associated with the target object but its current status cannot be determined.
 
Method Summary
 void begin()
          Create a new transaction and associate it with the current thread.
 void commit()
          Complete the transaction associated with the current thread.
 int getStatus()
          Obtain the status of the transaction associated with the current thread.
 void rollback()
          Roll back the transaction associated with the current thread.
 void setRollbackOnly()
          Modify the transaction associated with the current thread such that the only possible outcome of the transaction is to roll back the transaction.
 void setTransactionTimeout(int seconds)
          Modify the value of the timeout value that is associated with the transactions started by the current thread with the begin method.
 

Field Detail

STATUS_ACTIVE

public static final int STATUS_ACTIVE
A transaction is associated with the target object and it is in the active state. An implementation returns this status after a transaction has been started and prior to a Coordinator issuing any prepares unless the transaction has been marked for rollback.

STATUS_MARKED_ROLLBACK

public static final int STATUS_MARKED_ROLLBACK
A transaction is associated with the target object and it has been marked for rollback, perhaps as a result of a setRollbackOnly operation.

STATUS_PREPARED

public static final int STATUS_PREPARED
A transaction is associated with the target object and it has been prepared, i.e. all subordinates have responded Vote.Commit. The target object may be waiting for a superior's instruction as how to proceed.

STATUS_COMMITTED

public static final int STATUS_COMMITTED
A transaction is associated with the target object and it has been committed. It is likely that heuristics exists, otherwise the transaction would have been destroyed and NoTransaction returned.

STATUS_ROLLEDBACK

public static final int STATUS_ROLLEDBACK
A transaction is associated with the target object and the outcome has been determined as rollback. It is likely that heuristics exist, otherwise the transaction would have been destroyed and NoTransaction returned.

STATUS_UNKNOWN

public static final int STATUS_UNKNOWN
A transaction is associated with the target object but its current status cannot be determined. This is a transient condition and a subsequent invocation will ultimately return a different status.

STATUS_NO_TRANSACTION

public static final int STATUS_NO_TRANSACTION
No transaction is currently associated with the target object. This will occur after a transaction has completed.

STATUS_PREPARING

public static final int STATUS_PREPARING
A transaction is associated with the target object and it is in the process of preparing. An implementation returns this status if it has started preparing, but has not yet completed the process, probably because it is waiting for responses to prepare from one or more Resources.

STATUS_COMMITTING

public static final int STATUS_COMMITTING
A transaction is associated with the target object and it is in the process of committing. An implementation returns this status if it has decided to commit, but has not yet completed the process, probably because it is waiting for responses from one or more Resources.

STATUS_ROLLING_BACK

public static final int STATUS_ROLLING_BACK
A transaction is associated with the target object and it is in the process of rolling back. An implementation returns this status if it has decided to rollback, but has not yet completed the process, probably because it is waiting for responses from one or more Resources.
Method Detail

begin

public void begin()
           throws java.lang.IllegalStateException
Create a new transaction and associate it with the current thread.
Throws:
java.lang.IllegalStateException - Thrown if the thread is already associated with a transaction.

commit

public void commit()
            throws TransactionRolledbackException,
                   HeuristicMixedException,
                   HeuristicRollbackException,
                   java.lang.SecurityException,
                   java.lang.IllegalStateException
Complete the transaction associated with the current thread. When this method completes, the thread becomes associated with no transaction.
Throws:
TransactionRolledbackException - Thrown to indicate that the transaction has been rolled back rather than committed.
HeuristicMixedException - Thrown to indicate that a heuristic decision was made and that some relevant updates have been committed while others have been rolled back.
HeuristicRollbackException - Thrown to indicate that a heuristic decision was made and that some relevant updates have been rolled back.
java.lang.SecurityException - Thrown to indicate that the thread is not allowed to commit the transaction.
java.lang.IllegalStateException - Thrown if the current thread is not associated with a transaction.

rollback

public void rollback()
              throws java.lang.IllegalStateException,
                     java.lang.SecurityException
Roll back the transaction associated with the current thread. When this method completes, the thread becomes associated with no transaction.
Throws:
java.lang.SecurityException - Thrown to indicate that the thread is not allowed to roll back the transaction.
java.lang.IllegalStateException - Thrown if the current thread is not associated with a transaction.

setRollbackOnly

public void setRollbackOnly()
                     throws java.lang.IllegalStateException
Modify the transaction associated with the current thread such that the only possible outcome of the transaction is to roll back the transaction.
Throws:
java.lang.IllegalStateException - Thrown if the current thread is not associated with a transaction.

getStatus

public int getStatus()
Obtain the status of the transaction associated with the current thread.
Returns:
The transaction status. If no transaction is associated with the current thread, this method returns the Status.NoTransaction value.

setTransactionTimeout

public void setTransactionTimeout(int seconds)
Modify the value of the timeout value that is associated with the transactions started by the current thread with the begin method.

If an application has not called this method, the transaction service uses some default value for the transaction timeout.

Parameters:
seconds - The value of the timeout in seconds. If the value is zero, the transaction service restores the default value.