java.lang.Object
io.jooby.jdbi.TransactionalRequest
- All Implemented Interfaces:
Route.Aware
,Route.Filter
Attach
Handle
to the current request. The route pipeline runs inside a transaction which
is commit on success or rollback in case of exception.
Once route pipeline is executed the handle is detached from current request and closed it.
Usage:
{
install(new HikariModule());
install(new JdbiModule());
use(new TransactionalRequest());
get("/handle", ctx -> {
Handle handle = require(Handle.class);
// work with handle.
});
}
The Handle
should NOT be closed it by application code.
SQL Objects example:
{
install(new HikariModule());
install(new JdbiModule()
.sqlObjects(UserDAO.class)
);
use(new TransactionalRequest());
get("/handle", ctx -> {
UserDAO dao = require(UserDAO.class);
// work with user dao
});
}
The UserDAO
sql object is attached to the current/request attached Handle
.- Since:
- 2.0.0
- Author:
- edgar
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a transactional request.TransactionalRequest
(String name) Creates a transactional request. -
Method Summary
Modifier and TypeMethodDescriptionapply
(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
Creates a transactional request. A jdbi with the given name must be available in the service registry.This constructor should be used only if you have multiple Jdbi installations.
- Parameters:
name
- Jdbi service name.
-
TransactionalRequest
public TransactionalRequest()Creates a transactional request.
-
-
Method Details
-
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:
-
apply
- Specified by:
apply
in interfaceRoute.Filter
-