net.sourceforge.hivetranse.transaction
Interface TransactionService

All Known Implementing Classes:
AbstractTransactionService, HibernateTransactionService, JdbcTransactionService

public interface TransactionService

General interface for a Transaction managing service. This service is used by Transaction Interceptors and is not intended to use directly by application code.

Author:
Jean-Francois Poilpret

Method Summary
 void addTransactionEventListener(TransactionEventListener listener)
          Adds a new listener to the list of TransactionEventListeners notified by this TransactionService upon transaction.
 void begin(TransactionDemarcation demarcation)
          Marks the beginning of a new transaction demarcation scope.
 void end()
          Marks the end of a transaction demarcation scope.
 java.lang.Object getCurrentTransaction()
          Get the current "transaction" context for the calling thread.
 void removeTransactionEventListener(TransactionEventListener listener)
          Removes a listener from the list of TransactionEventListeners notified by this TransactionService upon transaction.
 void setRollbackOnly()
          Marks the current transaction to be rolled back when it will end.
 

Method Detail

begin

void begin(TransactionDemarcation demarcation)
           throws TransactionException,
                  MandatoryTransactionException,
                  ForbiddenTransactionException
Marks the beginning of a new transaction demarcation scope. Depending on demarcation, the service may create a new transaction, throw an exception, or do nothing at all.

Parameters:
demarcation - transaction for the new beginning scope
Throws:
MandatoryTransactionException - if there is no current transaction and demarcation == Mandatory
ForbiddenTransactionException - in a transaction currently exists and demarcation == Never
TransactionException - in case of any problem preventing the creation of a new transaction (implementation-dependent)

end

void end()
         throws TransactionException
Marks the end of a transaction demarcation scope. Depending on the actual demarcation for this scope, the service may end the current transaction, throw an exception, or do nothing at all. The current transaction, if necessary, will be either committed or rolled back, depending on whether setRollbackOnly was called previously for this transaction. In addition, the method might activate a previously active transaction.

If there is no current transaction, this is not considered an error but an indication of scope-leaving, which lets the possibility of scope unfolding, in order to set the new current transaction context.

Throws:
TransactionException - in case of any problem preventing the commitment of the current transaction (implementation-dependent)

setRollbackOnly

void setRollbackOnly()
                     throws MandatoryTransactionException
Marks the current transaction to be rolled back when it will end. The transaction will not be rolled back at once. Once the current transaction has been marked for rollback, it is impossible to go backwards and commit it.

If there is no current transaction, calling this method is considered an error.

Throws:
MandatoryTransactionException - in case there is no transaction in the current call context.

getCurrentTransaction

java.lang.Object getCurrentTransaction()
Get the current "transaction" context for the calling thread. The actual class of the returned object depends on every implementation.

This method is for internal use (eg, by services proxying actual connections).

Returns:
the current transaction object for the current thread, or null if there is no transaction in the current context. Note that if there is a transaction in the current context, this object cannot be null, hence the method can be used to check if there is a pending transaction for the current context.

addTransactionEventListener

void addTransactionEventListener(TransactionEventListener listener)
Adds a new listener to the list of TransactionEventListeners notified by this TransactionService upon transaction.

Parameters:
listener - the listener to add to the list

removeTransactionEventListener

void removeTransactionEventListener(TransactionEventListener listener)
Removes a listener from the list of TransactionEventListeners notified by this TransactionService upon transaction.

Parameters:
listener - the listener to remove from the list