Two DataSources
Hi @witoldsz!
I've been playing with ultm for a while.
I've noticed that when I don't want run SQL operation inside transaction I have to use different DataSource (not provided by ULTM::getManagedDataSource() ) for that.
The question is:
Will it be (in some next releases) possible to use managedDataSource for transactional and non transactional operations?
Hi Krzysztof! Sure, I am open for enhancements! What kind of non transactional operations you need, the auto-commit one, or rather a new transaction which suspends the outer one and then let you do commit and go back? How would you like the API to support this?
From my point of view, it's more about behaviour, not about API itself.
As a jOOQ user, I want use same instance of DSLContext (DSLContext need DataSource in constructor) for both transactional and non-transactional operations.
Right now I have to have two different DSLContext because it is not possible to use DataSource provided by ULTM::getManagedDataSource() without wrapping it with TXManager::tx().
To expand on this a little - I think the expected use-case for ULTM + JOOQ is that
- You would setup ULTM with your ordinary PooledDataSource
- You would configure jOOQ with ULTM's ManagedDataSource
- Use jOOQ to operate on the db via
DSL.using(jooq).xyz. This will ask the ManagedDataSource for a connection... and release it! - Sometimes use jOOQ within a ULTM transactional context
Currently 3. (which in my case and I assume many others is the most common case) does not work because of this: https://github.com/witoldsz/ultm/blob/master/src/main/java/com/github/witoldsz/ultm/internal/ThreadLocalTxManager.java#L40
FTR this is how you would configure a typical dropwizard application with jooq and ultm:
public void run(AppConfiguration appConfig, Environment env ) {
// Likely this is a pooled data-source factory
DataSourceFactory ds = appConfig.getDataSourceFactory();
// This allows the pool to do some initialization (like connect to the db + setup initial pool-size number of connections)
ManagedDataSource dropWizardManagedDS = ds.build(env.metrics(), "jooq");
env.lifecycle().manage(dropWizardManagedDS);
ULTM ultm = new ULTM(dropWizardManagedDS);
// now any time you use DSL.using(jooq), jooq will ask the ultm-managed DS for a connection
Configuration jooq = new DefaultConfiguration();
jooq.set(ultm.getManagedDataSource());
}