Package com.gruelbox.transactionoutbox
Interface JooqTransactionManager
- All Superinterfaces:
TransactionManager
Transaction manager which uses jOOQ's transaction management. In order to wire into JOOQ's
transaction lifecycle, a slightly convoluted construction process is required which involves
first creating a
JooqTransactionListener
, including it in the JOOQ Configuration
while constructing the root DSLContext
, and then finally linking
the listener to the new JooqTransactionManager
:
DataSourceConnectionProvider connectionProvider = new DataSourceConnectionProvider(dataSource); DefaultConfiguration configuration = new DefaultConfiguration(); configuration.setConnectionProvider(connectionProvider); configuration.setSQLDialect(SQLDialect.H2); configuration.setTransactionProvider(new ThreadLocalTransactionProvider(connectionProvider)); JooqTransactionListener listener = JooqTransactionManager.createListener(); configuration.set(listener); DSLContext dsl = DSL.using(configuration); return JooqTransactionManager.create(dsl, listener);
-
Method Summary
Static MethodsModifier and TypeMethodDescriptionstatic ParameterContextTransactionManager<org.jooq.Configuration>
create
(org.jooq.DSLContext dslContext) Creates a transaction manager which uses explicitly-passed context, allowing multiple active contexts in the current thread and contexts which are passed between threads.create
(org.jooq.DSLContext dslContext, JooqTransactionListener listener) Creates a transaction manager which uses thread-local context.static JooqTransactionListener
Creates theTransactionListener
to wire into theDSLContext
.Methods inherited from interface com.gruelbox.transactionoutbox.TransactionManager
extractTransaction, injectTransaction, inTransaction, inTransaction, inTransactionReturns, inTransactionReturnsThrows, inTransactionThrows
-
Method Details
-
createListener
Creates theTransactionListener
to wire into theDSLContext
. See class-level documentation for more detail.- Returns:
- The transaction listener.
-
create
static ThreadLocalContextTransactionManager create(org.jooq.DSLContext dslContext, JooqTransactionListener listener) Creates a transaction manager which uses thread-local context. Attaches to the suppliedJooqTransactionListener
to receive notifications of transactions starting and finishing on the local thread so thatTransactionOutbox.schedule(Class)
can be called for methods that don't explicitly inject aConfiguration
, e.g.:dsl.transaction(() -> outbox.schedule(Foo.class).process("bar"));
- Parameters:
dslContext
- The DSL context.listener
- The listener, linked to the DSL context.- Returns:
- The transaction manager.
-
create
@Beta static ParameterContextTransactionManager<org.jooq.Configuration> create(org.jooq.DSLContext dslContext) Creates a transaction manager which uses explicitly-passed context, allowing multiple active contexts in the current thread and contexts which are passed between threads. Requires aConfiguration
for the transaction context or aTransaction
to be used to be passed any method called viaTransactionOutbox.schedule(Class)
. Example:void doSchedule() { // ctx1 is used to write the request to the DB dsl.transaction(ctx1 -> outbox.schedule(getClass()).process("bar", ctx1)); } // ctx2 is injected at run time void process(String arg, org.jooq.Configuration ctx2) { ... }
Or:
void doSchedule() { // tx1 is used to write the request to the DB transactionManager.inTransaction(tx1 -> outbox.schedule(getClass()).process("bar", tx1)); } // tx2 is injected at run time void process(String arg, Transaction tx2) { ... }
- Parameters:
dslContext
- The DSL context.- Returns:
- The transaction manager.
-