Type Parameters:
UOW - the UnitOfWork sub-type returned by the UnitOfWorkFactory
All Known Subinterfaces:
HandleAwareUnitOfWorkFactory<UOW>
All Known Implementing Classes:
GenericHandleAwareUnitOfWorkFactory, JdbiUnitOfWorkFactory, SpringMongoTransactionAwareUnitOfWorkFactory, SpringTransactionAwareJdbiUnitOfWorkFactory, SpringTransactionAwareUnitOfWorkFactory

public interface UnitOfWorkFactory<UOW extends UnitOfWork>
This interface creates a UnitOfWork
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final org.slf4j.Logger
     
  • Method Summary

    Modifier and Type
    Method
    Description
    Get the currently active UnitOfWork
    Get the currently active UnitOfWork or create a new UnitOfWork if one is missing
    Get a required active UnitOfWork
    default void
    usingUnitOfWork(dk.cloudcreate.essentials.shared.functional.CheckedConsumer<UOW> unitOfWorkConsumer)
    Run the unitOfWorkConsumer in a UnitOfWork
    It works in two different ways:
    1.
    If no existing UnitOfWork then a new UnitOfWork is created and started, the unitOfWorkConsumer is called with this UnitOfWork
    When the unitOfWorkConsumer has completed, without throwing an exception, then the created UnitOfWork is committed.
    In case an exception was thrown then the created UnitOfWork is rolledback.

    2.
    If there's already an existing UnitOfWork then the unitOfWorkConsumer joins in with existing UnitOfWork and the unitOfWorkConsumer is called with the existing UnitOfWork
    When the unitOfWorkConsumer has completed, without throwing an exception, then the existing UnitOfWork is NOT committed, this is instead left to the original creator of the UnitOfWork to do
    In case an exception was thrown then the existing UnitOfWork is marked as rollback only.
    default void
    usingUnitOfWork(dk.cloudcreate.essentials.shared.functional.CheckedRunnable action)
    Works just like usingUnitOfWork(CheckedConsumer) except the action isn't provided an instance of the UnitOfWork
    The code in the action can always access the UnitOfWork by calling getRequiredUnitOfWork()
    default <R> R
    withUnitOfWork(dk.cloudcreate.essentials.shared.functional.CheckedFunction<UOW,R> unitOfWorkFunction)
    Run the unitOfWorkFunction in a UnitOfWork
    It works in two different ways:
    1.
    If no existing UnitOfWork then a new UnitOfWork is created and started, the unitOfWorkFunction is called with this UnitOfWork
    When the unitOfWorkFunction has completed, without throwing an exception, then the created UnitOfWork is committed.
    In case an exception was thrown then the created UnitOfWork is rolledback.

    2.
    If there's already an existing UnitOfWork then the unitOfWorkFunction joins in with existing UnitOfWork and the unitOfWorkFunction is called with the existing UnitOfWork
    When the unitOfWorkFunction has completed, without throwing an exception, then the existing UnitOfWork is NOT committed, this is instead left to the original creator of the UnitOfWork to do
    In case an exception was thrown then the existing UnitOfWork is marked as rollback only.
    default <R> R
    withUnitOfWork(dk.cloudcreate.essentials.shared.functional.CheckedSupplier<R> action)
    Works just like withUnitOfWork(CheckedFunction) except the action isn't provided an instance of the UnitOfWork
    The code in the action can always access the UnitOfWork by calling getRequiredUnitOfWork()
  • Field Details

    • unitOfWorkLog

      static final org.slf4j.Logger unitOfWorkLog
  • Method Details

    • getRequiredUnitOfWork

      UOW getRequiredUnitOfWork()
      Get a required active UnitOfWork
      Returns:
      the active UnitOfWork
      Throws:
      NoActiveUnitOfWorkException - if the is no active UnitOfWork
    • getOrCreateNewUnitOfWork

      UOW getOrCreateNewUnitOfWork()
      Get the currently active UnitOfWork or create a new UnitOfWork if one is missing
      Returns:
      a UnitOfWork
    • usingUnitOfWork

      default void usingUnitOfWork(dk.cloudcreate.essentials.shared.functional.CheckedRunnable action)
      Works just like usingUnitOfWork(CheckedConsumer) except the action isn't provided an instance of the UnitOfWork
      The code in the action can always access the UnitOfWork by calling getRequiredUnitOfWork()
      Parameters:
      action - the action that's performed in a UnitOfWork
    • withUnitOfWork

      default <R> R withUnitOfWork(dk.cloudcreate.essentials.shared.functional.CheckedSupplier<R> action)
      Works just like withUnitOfWork(CheckedFunction) except the action isn't provided an instance of the UnitOfWork
      The code in the action can always access the UnitOfWork by calling getRequiredUnitOfWork()
      Type Parameters:
      R - the return type from the action
      Parameters:
      action - the action that's performed in a UnitOfWork
      Returns:
      the result of running the action in a UnitOfWork
    • usingUnitOfWork

      default void usingUnitOfWork(dk.cloudcreate.essentials.shared.functional.CheckedConsumer<UOW> unitOfWorkConsumer)
      Run the unitOfWorkConsumer in a UnitOfWork
      It works in two different ways:
      1.
      If no existing UnitOfWork then a new UnitOfWork is created and started, the unitOfWorkConsumer is called with this UnitOfWork
      When the unitOfWorkConsumer has completed, without throwing an exception, then the created UnitOfWork is committed.
      In case an exception was thrown then the created UnitOfWork is rolledback.

      2.
      If there's already an existing UnitOfWork then the unitOfWorkConsumer joins in with existing UnitOfWork and the unitOfWorkConsumer is called with the existing UnitOfWork
      When the unitOfWorkConsumer has completed, without throwing an exception, then the existing UnitOfWork is NOT committed, this is instead left to the original creator of the UnitOfWork to do
      In case an exception was thrown then the existing UnitOfWork is marked as rollback only.
      Parameters:
      unitOfWorkConsumer - the consumer that's called with a UnitOfWork
    • withUnitOfWork

      default <R> R withUnitOfWork(dk.cloudcreate.essentials.shared.functional.CheckedFunction<UOW,R> unitOfWorkFunction)
      Run the unitOfWorkFunction in a UnitOfWork
      It works in two different ways:
      1.
      If no existing UnitOfWork then a new UnitOfWork is created and started, the unitOfWorkFunction is called with this UnitOfWork
      When the unitOfWorkFunction has completed, without throwing an exception, then the created UnitOfWork is committed.
      In case an exception was thrown then the created UnitOfWork is rolledback.

      2.
      If there's already an existing UnitOfWork then the unitOfWorkFunction joins in with existing UnitOfWork and the unitOfWorkFunction is called with the existing UnitOfWork
      When the unitOfWorkFunction has completed, without throwing an exception, then the existing UnitOfWork is NOT committed, this is instead left to the original creator of the UnitOfWork to do
      In case an exception was thrown then the existing UnitOfWork is marked as rollback only.
      Parameters:
      unitOfWorkFunction - the consumer that's called with a UnitOfWork
    • getCurrentUnitOfWork

      Optional<UOW> getCurrentUnitOfWork()
      Get the currently active UnitOfWork
      Returns:
      the currently active UnitOfWork wrapped in an Optional or Optional.empty() in case there isn't a currently active UnitOfWork