The transactional-jersey module provides transactional interceptors for kwery with Jersey 2.
Note: the use of this module is discouraged as it may be removed - using a ThreadLocalSession
with
transaction blocks is preferred as they work without interceptor
configuration.
Registering TransactionListener
as a Jersey provider allows the transactional
attribute to declare resource classes (or methods) as transactional.
Any ManagedThreadLocalSessions
will then automatically participate in a transaction. Transactions will
be rolled back automatically if the status of the method is not successful.
val session = ManagedThreadLocalSession(dataSource, HsqlDialect())
Path("/films")
transactional class FilmResource(session: Session) : Resource {
GET fun find(): List<Film> {
session.select(...)
}
}
The transaction
annotation accepts 2 parameters:
manual
. If true, a session will be initialised but no transaction will be started. This allows the use ofSession's
transactional methods to manually control transaction boundaries.name
. Multiple datasources can be supported via thename
attribute (name underlyingManagedThreadLocalSessions
to match).