Hi Lukas,
Thanks for the tips. I played around with putting my logic in different
overridden methods of *DefaultExecuteListener* .
By watching a live log on what the DB is doing I can see that I'm getting
the effect I want by overriding *prepareStart *( to add the param ) and
*executeEnd
*(the reset the param)
Your approach for configuring the *DSLContext* at the time of calling
*DSL.Using* wont work well for us because we do stuff like this.
public class AppDatabase implements Database
{
...
public <T> T withConnection(BiFunction<Connection, DSLContext, T> block) {
return db.withConnection(c -> {
return block.apply(c, DSL.using(c, SQLDialect.POSTGRES_9_4,
settings));
});
}
.
On Thursday, December 3, 2015 at 3:55:52 AM UTC-5, Lukas Eder wrote:
>
>
>
> 2015-12-02 18:59 GMT+01:00 Max Kremer <[email protected] <javascript:>>
> :
>
>> Ok Lukas I think I've figured it out - can you advise if I'm on the write
>> track:
>>
>> First think I did was create an *ExecuteListener* by extending
>> *DefaultExecuteListener*
>>
>
> Hmm, I suspect you might have side effects this way as the executeStart()
> event is triggered after the prepareXXX() events. I don't know if there are
> any side effects here as jOOQ will prepare the real statement already
> before you call "SET enable_sort TO TRUE"
>
> Also, do make sure that you don't run into any resource leaks. You should
> close your statement eagerly:
>
> try (Statement s = ctx.connection().createStatement()) {
> s.execute("...");
> }
>
>
>
>>
>> Then wherever I need to employ this execute listener I do:
>>
>>
>> dslContext.configuration().set(new DefaultExecuteListenerProvider(new
>> ParamsListener()));
>>
>> So here are a couple things I'm not sure of:
>> - Whats the lifecycle of DSLContext ? I'm assuming it gets reused
>>
>
> You define that. If it gets reused, then this approach will be wrong and
> not thread safe. A better solution would be:
>
> DSL.using(dslContext.configuration().derive(new
> DefaultExecuteListenerProvider(new ParamsListener())));
>
>
> - How do I set the DSLcontext configuration back to default?
>>
>
> I would just create two different Configurations / DSLContexts in your
> application for those purposes.
>
> Hope this helps,
> 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.