Class TransactionalRequest

java.lang.Object
io.jooby.hibernate.TransactionalRequest
All Implemented Interfaces:
io.jooby.Route.Aware, io.jooby.Route.Filter

public class TransactionalRequest extends Object implements io.jooby.Route.Filter
Attaches a Session and EntityManager to the current request via SessionRequest.

The route pipeline runs inside a transaction which is commit on success or rollback in case of exception.

Applies the SessionRequest decorator, so there is no need to use session request in addition to transactional request.

Usage:


 {

   install(new HikariModule());

   install(new HibernateModule());

   use(new TransactionalRequest());

   get("/handle", ctx -> {
     EntityManager handle = require(EntityManager.class);
     // work with handle.
   });
 }
 
Since:
2.0.0
Author:
edgar
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new transactional request and attach to the default/first session factory registered.
    Creates a new transactional request and attach the to a named session factory.
  • Method Summary

    Modifier and Type
    Method
    Description
    io.jooby.Route.Handler
    apply(io.jooby.Route.Handler next)
     
    enabledByDefault(boolean enabledByDefault)
    Sets whether all routes in the scope of this decorator instance should be transactional or not (true by default).

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface io.jooby.Route.Aware

    setRoute

    Methods inherited from interface io.jooby.Route.Filter

    then, then
  • Constructor Details

    • TransactionalRequest

      public TransactionalRequest(@NonNull String name)
      Creates a new transactional request and attach the to a named session factory.
      Parameters:
      name - Name of the session factory.
    • TransactionalRequest

      public TransactionalRequest()
      Creates a new transactional request and attach to the default/first session factory registered.
  • Method Details

    • enabledByDefault

      public TransactionalRequest enabledByDefault(boolean enabledByDefault)
      Sets whether all routes in the scope of this decorator instance should be transactional or not (true by default).

      You can use the Transactional annotation to override this option on a single route.

      Parameters:
      enabledByDefault - whether routes should be transactional by default
      Returns:
      this instance
      See Also:
      • Transactional
    • apply

      @NonNull public io.jooby.Route.Handler apply(@NonNull io.jooby.Route.Handler next)
      Specified by:
      apply in interface io.jooby.Route.Filter