Class UnitManager

  • All Implemented Interfaces:
    jakarta.inject.Provider<org.jdbi.v3.core.Handle>

    @Singleton
    public class UnitManager
    extends java.lang.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:
    for manual transaction definition
    • Constructor Summary

      Constructors 
      Constructor Description
      UnitManager​(org.jdbi.v3.core.Jdbi jdbi)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void beginUnit()
      Starts unit of work.
      void endUnit()
      Finish unit of work.
      org.jdbi.v3.core.Handle get()  
      boolean isUnitStarted()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • UnitManager

        @Inject
        public UnitManager​(org.jdbi.v3.core.Jdbi jdbi)
    • Method Detail

      • 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:
        java.lang.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:
        java.lang.IllegalStateException - when no opened unit of work