Class UnitManager

java.lang.Object
ru.vyarus.guicey.jdbi3.unit.UnitManager
All Implemented Interfaces:
jakarta.inject.Provider<org.jdbi.v3.core.Handle>

@Singleton public class UnitManager extends Object implements jakarta.inject.Provider<org.jdbi.v3.core.Handle>
Manages JDBI Handle for current unit of work. This handle must be used by all JDBI proxies. Unit of work is thread-bound (all actions in one thread participate in one unit of work). It is not intended to be used directly (only in really rare cases when manual unit required without opening transaction).

Raw provider may be injected to obtain current handle: @Inject Provider<Handle>. In all other cases transaction annotation must be used to wrap code into unit of work using guice aop.

Since:
31.08.2018
See Also:
  • Constructor Details

    • UnitManager

      @Inject public UnitManager(org.jdbi.v3.core.Jdbi jdbi)
      Create a unit manager.
      Parameters:
      jdbi - jdbi instance
  • Method Details

    • get

      public org.jdbi.v3.core.Handle get()
      Specified by:
      get in interface jakarta.inject.Provider<org.jdbi.v3.core.Handle>
    • isUnitStarted

      public boolean isUnitStarted()
      Returns:
      true if unit of work started (and handle could be obtained), false otherwise
    • beginUnit

      public void beginUnit()
      Starts unit of work.
      Throws:
      IllegalStateException - if unit of work already started
    • endUnit

      public void endUnit()
      Finish unit of work. Note: does not commit transaction, but only close context handle.
      Throws:
      IllegalStateException - when no opened unit of work