Hi Ed,

2018-02-23 1:27 GMT+01:00 Ed Erwin <enwi...@gmail.com>:

> I'm struggling to try to find the right way to pass context (or
> configuration or transaction or connection) around between multiple
> separate methods of my classes.
>
> Suppose I have a method like this, and I want to call it perhaps sometimes
> inside a transaction and sometimes not inside a transaction:
> public void updateBook(int bookId, int authorId) {}
>
> Which of these alternative would be best, and is there an even better way?
>
> public void updateBook(DSLContext context, int bookId, int authorId) {}
> public void updateBook(Configuration configuration, int bookId, int
> authorId) {}
>

These two are equivalent as DSLContext is just a wrapper for a
Configuration, which can be obtained either by calling
DSL.using(configuration) or configuration.dsl() since jOOQ 3.10:
https://www.jooq.org/javadoc/latest/org/jooq/Configuration.html#dsl--


> public void updateBook(Connection connection, int bookId, int authorId) {}
>

This one, I wouldn't recommend. After all, a jOOQ Configuration has more
configuration information than just the JDBC Connection, including Settings
(things like formatting, schema mapping, etc.) and all the other SPIs, like
ExecuteListener. Also, if you decide to implement your own
TransactionListener, then you will want that to be passed to your
updateBook method through the Configuration.


> You comments here indicate that passing the DSLContext is not good, but
> which object should I pass?
>

That comment you're referring to explained why the TransactionalRunnable
doesn't pass the DSLContext to its transactional body:
https://www.jooq.org/javadoc/latest/org/jooq/TransactionalRunnable.html#run-org.jooq.Configuration-

I.e. it explains the rational of the library API.

You, on the other hand are free to do whatever you feel is most suitable.
If you prefer working with the DSLContext type, you can pass that instead.
>From a user perspective, DSLContext and Configuration are equivalent types.


> Also, is there any difference between calling DSL.using(configuration)
> compared to configuration.dsl() ?
>

No. The latter was introduced merely for convenience:
https://github.com/jOOQ/jOOQ/issues/6372

... mostly because most people prefer working with DSLContext rather than
Configuration, and found accessing the DSLContext type from within a
TransactionalRunnable a bit tedious :-)

I hope this clarifies the questions,
Lukas

-- 
You received this message because you are subscribed to the Google Groups "jOOQ 
User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jooq-user+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to