2014-12-02 19:16 GMT+01:00 <[email protected]>:

> I'm not sure how I see the ExecuteContext + ExecuteListener helping as the
> issue is not global instrumenting but rather tagging specific SQL calls.
>

You can derive new Configurations from your existing one, which contain the
ExecuteListener. Or you can derive new Configurations that contain elements
in the data() Map:
http://www.jooq.org/javadoc/latest/org/jooq/Configuration.html#data--

You can then use such a derived Configuration on a per-query basis. jOOQ
doesn't make any assumptions about the lifecycle of your Configuration...


> The only way I see this working ostensibly (given that DSL has no way to
> pass down adhoc data) regardless of whether or not I use an ExecuteListener
> is to use nasty threadlocals.
>

That's another option, of course. If you're using Java 8, you could
implement this quite nicely as such:

Comments.comment("My Comment", () -> {
    // jOOQ query here
    // jOOQ query here
});


The comment() method would set and cleanup the ThreadLocal before executing
the Runnable lambda, and an ExecuteListener would patch all generated SQL
for the time being.

That is store the metric name I want with a static utility method that sets
> the metric in a threadlocal before I call jOOQ and then have my
> spy/ExecuteListener use the threadlocal and clean it up.
>
> While I can do this I still find it unusual that a tool that can generate
> SQL programmatically not allow me to generate SQL comments.
>

It has been mentioned only once on this user group so far... Besides, you
*can* generate SQL comments. In various ways :)


> Perhaps a comment method should be added to the DSL as a feature? For all
> SQL you could provide
> public CHAIN __(String comment) that does "-- comments" and then a dialect
> specific one for providing "/* */" as I believe the C style is not in the
> SQL standard.
> However given the nature of the DSL fluent return value chaining this is
> probably a rather massive change as it would be needed on every SQL step.
>

That discussion I mentioned asked for comments at arbitrary positions (
https://github.com/jOOQ/jOOQ/issues/2543). I'm still not 100% convinced
that we should make this heavy change for the little gain that we get...

That being said adding SQL comments has been even useful for non metric
> reasons as the comment provides reference when looking into database logs.
>
> For now I will threadlocal and ask for forgiveness later :)
>

You're forgiven :-)

-- 
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