Class LocalTransactionManager

java.lang.Object
org.seasar.doma.jdbc.tx.LocalTransactionManager
All Implemented Interfaces:
TransactionManager

public class LocalTransactionManager extends Object implements TransactionManager
A transaction manager for local transactions.

This instance is thread safe.

  • Field Details

  • Constructor Details

  • Method Details

    • getTransaction

      public LocalTransaction getTransaction()
      Returns the transaction.

      This method is mainly used in test code.

      Returns:
      the transaction
    • required

      public void required(Runnable block)
      Description copied from interface: TransactionManager
      Executes the transaction whose attribute is REQUIRED.
      Specified by:
      required in interface TransactionManager
      Parameters:
      block - the code that is executed in the transaction
    • required

      public void required(TransactionIsolationLevel isolationLevel, Runnable block)
      Description copied from interface: TransactionManager
      Executes the transaction whose attribute is REQUIRED with the specified transaction isolation level.
      Specified by:
      required in interface TransactionManager
      Parameters:
      isolationLevel - the transaction isolation level
      block - the code that is executed in the transaction
    • required

      public <RESULT> RESULT required(Supplier<RESULT> supplier)
      Description copied from interface: TransactionManager
      Executes the transaction whose attribute is REQUIRED and returns the result.
      Specified by:
      required in interface TransactionManager
      Type Parameters:
      RESULT - the result type
      Parameters:
      supplier - the code that is executed in the transaction
      Returns:
      the result
    • required

      public <RESULT> RESULT required(TransactionIsolationLevel isolationLevel, Supplier<RESULT> supplier)
      Description copied from interface: TransactionManager
      Executes the transaction whose attribute is REQUIRED with the specified transaction isolation level and return the result.
      Specified by:
      required in interface TransactionManager
      Type Parameters:
      RESULT - the result type
      Parameters:
      isolationLevel - the transaction isolation level
      supplier - the code that is executed in the transaction
      Returns:
      the result
    • requiredInternal

      protected <RESULT> RESULT requiredInternal(TransactionIsolationLevel isolationLevel, Supplier<RESULT> supplier)
    • requiresNew

      public void requiresNew(Runnable block)
      Description copied from interface: TransactionManager
      Executes the transaction whose attribute is REQUIRES_NEW.
      Specified by:
      requiresNew in interface TransactionManager
      Parameters:
      block - the code that is executed in the transaction
    • requiresNew

      public void requiresNew(TransactionIsolationLevel isolationLevel, Runnable block)
      Description copied from interface: TransactionManager
      Executes the transaction whose attribute is REQUIRES_NEW with the specified transaction isolation level.
      Specified by:
      requiresNew in interface TransactionManager
      Parameters:
      isolationLevel - the transaction isolation level
      block - the code that is executed in the transaction
    • requiresNew

      public <RESULT> RESULT requiresNew(Supplier<RESULT> supplier)
      Description copied from interface: TransactionManager
      Executes the transaction whose attribute is REQUIRES_NEW and returns the result.
      Specified by:
      requiresNew in interface TransactionManager
      Type Parameters:
      RESULT - the result type
      Parameters:
      supplier - the code that is executed in the transaction
      Returns:
      the result
    • requiresNew

      public <RESULT> RESULT requiresNew(TransactionIsolationLevel isolationLevel, Supplier<RESULT> supplier)
      Description copied from interface: TransactionManager
      Executes the transaction whose attribute is REQUIRES_NEW with the specified transaction isolation level and return the result.
      Specified by:
      requiresNew in interface TransactionManager
      Type Parameters:
      RESULT - the result type
      Parameters:
      isolationLevel - the transaction isolation level
      supplier - the code that is executed in the transaction
      Returns:
      the result
    • requiresNewInternal

      protected <RESULT> RESULT requiresNewInternal(TransactionIsolationLevel isolationLevel, Supplier<RESULT> supplier)
    • notSupported

      public void notSupported(Runnable block)
      Description copied from interface: TransactionManager
      Executes the transaction whose attribute is NOT_SUPPORTED.
      Specified by:
      notSupported in interface TransactionManager
      Parameters:
      block - the code that is executed in the transaction
    • notSupported

      public void notSupported(TransactionIsolationLevel isolationLevel, Runnable block)
      Description copied from interface: TransactionManager
      Executes the transaction whose attribute is NOT_SUPPORTED with the specified transaction isolation level.
      Specified by:
      notSupported in interface TransactionManager
      Parameters:
      isolationLevel - the transaction isolation level
      block - the code that is executed in the transaction
    • notSupported

      public <RESULT> RESULT notSupported(Supplier<RESULT> supplier)
      Description copied from interface: TransactionManager
      Executes the transaction whose attribute is NOT_SUPPORTED and returns the result.
      Specified by:
      notSupported in interface TransactionManager
      Type Parameters:
      RESULT - the result type
      Parameters:
      supplier - the code that is executed in the transaction
      Returns:
      the result
    • notSupported

      public <RESULT> RESULT notSupported(TransactionIsolationLevel isolationLevel, Supplier<RESULT> supplier)
      Description copied from interface: TransactionManager
      Executes the transaction whose attribute is NOT_SUPPORTED with the specified transaction isolation level and return the result.
      Specified by:
      notSupported in interface TransactionManager
      Type Parameters:
      RESULT - the result type
      Parameters:
      isolationLevel - the transaction isolation level
      supplier - the code that is executed in the transaction
      Returns:
      the result
    • notSupportedInternal

      protected <RESULT> RESULT notSupportedInternal(TransactionIsolationLevel isolationLevel, Supplier<RESULT> supplier)
    • toSupplier

      protected Supplier<Void> toSupplier(Runnable block)
    • setRollbackOnly

      public void setRollbackOnly()
      Description copied from interface: TransactionManager
      Marks the current transaction to undo in the end of the transaction.
      Specified by:
      setRollbackOnly in interface TransactionManager
    • isRollbackOnly

      public boolean isRollbackOnly()
      Description copied from interface: TransactionManager
      Whether the current transaction is marked to be undone.
      Specified by:
      isRollbackOnly in interface TransactionManager
      Returns:
      true if the current transaction is marked.
    • executeInTransaction

      protected <RESULT> RESULT executeInTransaction(TransactionIsolationLevel isolationLevel, Supplier<RESULT> supplier)
    • setSavepoint

      public void setSavepoint(String savepointName)
      Description copied from interface: TransactionManager
      Creates a save point with the specified name.

      Begin a transaction before invoking this method.

      Specified by:
      setSavepoint in interface TransactionManager
      Parameters:
      savepointName - the name of the save point
    • hasSavepoint

      public boolean hasSavepoint(String savepointName)
      Description copied from interface: TransactionManager
      Whether the current transaction has the save point.

      Begin a transaction before invoking this method.

      Specified by:
      hasSavepoint in interface TransactionManager
      Parameters:
      savepointName - the name of the save point
      Returns:
      true if the transaction has the save point
    • releaseSavepoint

      public void releaseSavepoint(String savepointName)
      Description copied from interface: TransactionManager
      Removes the specified save point and subsequent save points from the current transaction.

      Begin a transaction before invoking this method.

      Specified by:
      releaseSavepoint in interface TransactionManager
      Parameters:
      savepointName - the name of the save point
    • rollback

      public void rollback(String savepointName)
      Description copied from interface: TransactionManager
      Undoes all changes made after the given save point.

      Begin a transaction before invoking this method.

      Specified by:
      rollback in interface TransactionManager
      Parameters:
      savepointName - the name of the save point