Interface TransactionHandler<T>

  • Type Parameters:
    T - The transaction object if any, object otherwise

    public interface TransactionHandler<T>
    Classes implementing this interface can be used by a SeedStack transaction manager to handle a specific kind of transaction (e.g. JPA, JMS, ...). Any of the do*() methods can be implemented with an empty body if they are not applicable in this kind of transaction context.
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      void doBeginTransaction​(T currentTransaction)
      This method is called on transaction startup and marks the beginning of the transaction.
      void doCleanup()
      This method is invoked after transaction has ended (either successfully or not) and is responsible to clean anything initialized by the doInitialize() method.
      void doCommitTransaction​(T currentTransaction)
      This method is called when the transaction needs to be committed according to the policy specified by the transaction metadata.
      T doCreateTransaction()
      This method is called on transaction creation and is responsible to return the object instance representing the new transaction.
      void doInitialize​(TransactionMetadata transactionMetadata)
      This method is called before the transaction creation and is responsible to execution any initialization code necessary to the underlying implementation.
      void doJoinGlobalTransaction()
      This method is called when joining a global transaction is required by the transaction manager.
      void doMarkTransactionAsRollbackOnly​(T currentTransaction)
      This method is called when the transaction needs to be marked as rollback only according to the policy specified by the transaction metadata.
      void doReleaseTransaction​(T currentTransaction)
      This method is called on transaction end to release the transaction object if needed.
      void doRollbackTransaction​(T currentTransaction)
      This method is called when the transaction needs to be rollbacked according to the policy specified by the transaction metadata.
      T getCurrentTransaction()
      This method is invoked before transaction initialization to check if a transaction already exists and can eventually be reused.
    • Method Detail

      • doInitialize

        void doInitialize​(TransactionMetadata transactionMetadata)
        This method is called before the transaction creation and is responsible to execution any initialization code necessary to the underlying implementation. If this method fails, no cleanup is performed so implementations must ensure that its behavior is atomic (all or nothing).

        The transactionMetadata is given by the TransactionManager.

        Parameters:
        transactionMetadata - The associated transaction metadata.
      • doCreateTransaction

        T doCreateTransaction()
        This method is called on transaction creation and is responsible to return the object instance representing the new transaction.
        Returns:
        the new transaction object, null if none.
      • doJoinGlobalTransaction

        void doJoinGlobalTransaction()
        This method is called when joining a global transaction is required by the transaction manager.
      • doBeginTransaction

        void doBeginTransaction​(T currentTransaction)
        This method is called on transaction startup and marks the beginning of the transaction.
        Parameters:
        currentTransaction - The transaction object as returned by doCreateTransaction(), null if none.
      • doCommitTransaction

        void doCommitTransaction​(T currentTransaction)
        This method is called when the transaction needs to be committed according to the policy specified by the transaction metadata.
        Parameters:
        currentTransaction - The transaction object as returned by doCreateTransaction(), null if none.
      • doMarkTransactionAsRollbackOnly

        void doMarkTransactionAsRollbackOnly​(T currentTransaction)
        This method is called when the transaction needs to be marked as rollback only according to the policy specified by the transaction metadata.
        Parameters:
        currentTransaction - The transaction object as returned by doCreateTransaction(), null if none.
      • doRollbackTransaction

        void doRollbackTransaction​(T currentTransaction)
        This method is called when the transaction needs to be rollbacked according to the policy specified by the transaction metadata.
        Parameters:
        currentTransaction - The transaction object as returned by doCreateTransaction(), null if none.
      • doReleaseTransaction

        void doReleaseTransaction​(T currentTransaction)
        This method is called on transaction end to release the transaction object if needed. Note that it is called even if the transaction failed to begin.
        Parameters:
        currentTransaction - The transaction object as returned by doCreateTransaction(), null if none.
      • doCleanup

        void doCleanup()
        This method is invoked after transaction has ended (either successfully or not) and is responsible to clean anything initialized by the doInitialize() method.
      • getCurrentTransaction

        T getCurrentTransaction()
        This method is invoked before transaction initialization to check if a transaction already exists and can eventually be reused.
        Returns:
        the transaction object.