Hi Ben,

Thanks a lot for your feedback. I will comment inline

2016-01-04 1:25 GMT+01:00 Ben Hood <[email protected]>:

> >> If that is the case I would like to see less assumptions being
> >> made by the JOOQ runtime about how an app wants to interact with the
> >> DB with a transaction. But in fairness, my comment is a bit off topic
> >> - this thread is about the code generator, not the runtime.
> >
> >
> > Yes, the thread will become a bit confusing, but I'm curious about your
> > feedback anyway. Perhaps start a new thread? I think we still have some
> > spare threads left on Google Groups ;-)
>
> On reflection, I think that part of my observation was down to the way
> that that I've abstracted my use of JOOQ, which isn't necessary the
> best way to do things.
>
> So I've got a utility function that wraps a fluent DSL callback,
> injects a pooled connection into it and handles all of the
> commit/rollback/blow up scenarios generically:
>

May I ask what kept you from using DataSourceConnectionProvider (to inject
the pooled connection) together with DSLContext.transaction() here?
Perhaps, there's some quick win that we could improve, here.


> public <T> T execute(Function<DSLContext,T> fun) {
>
>   T result = null;
>
>   // ... get a connection from the pool
>   // ... build a JOOQ context
>
>   try {
>
>     result = fun.apply(ctx);
>
>   }
>
>   // lots of failure handling here
>
>   finally {
>   // ... release connection
>   }
>
>   return result;
> }
>
> So I think maybe the issue I'm having in a few cases is that I'd like
> access to the JDBC connection or the current statement, but I can't
> necessarily get it from the DSLContext.


You can, with jOOQ 3.7+:
http://www.jooq.org/javadoc/latest/org/jooq/DSLContext.html#connection-org.jooq.ConnectionRunnable-

The API is similar to the transaction API:


DSLContext ctx = ...

ctx.connection(c -> {
    // Implicit ConnectionProvider.acquire() at the beginning

    try (Statement s = c.createStatement()) {
        s.executeUpdate("DROP ...");
    }

    // Implicit ConnectionProvider.release() at the end
});


Does this help? Or is there any other feature that you might be missing
here?

In particular, I'm not quite sure what you mean by getting access to the
"current statement"... Do you mean to be able to create your own statements
from such a Connection? Or do you mean to access the statement of an
org.jooq.Query?

Best Regards,
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to