jOOQ supports Oracle-style hints, which are comments. Granted, those hints
are not placed at the beginning of a SELECT, they would be here:
select /* com.snaphop.data.campaign.SELECT */ * from campaign where ....
You can do the above as such:
DSL.using(...)
.select()
.hint("/* com.snaphop.data.campaign.SELECT */")
.from(CAMPAIGN)
If you need the comments to be placed at the beginning, an ExecuteListener
might be a better choice and the most idiomatic one for jOOQ in general:
http://www.jooq.org/doc/latest/manual/sql-execution/execute-listeners/
It would probably look like this:
public class AddMetricsListener extends DefaultExecuteListener {
@Override
public void renderEnd(ExecuteContext ctx) {
if (somePredicate) { ctx.sql("/*
com.snaphop.data.campaign.SELECT */ " + ctx.sql());
}
}}
Another option would be to embed your SELECT statement in plain SQL,
although that might not be as elegant, as you would be losing type safety:
DSL.using(...)
.fetch("/* com.snaphop.data.campaign.SELECT */ {0}", theOriginalSelect);
Of course, if you're running all your queries via jOOQ, then why not just
implement your magical JDBC spy wrapper as a jOOQ ExecuteListener? In that
case, you wouldn't even need the comment trick, you could simply add some
custom elements to your ExecuteContext's data() object...
Hope this helps,
Lukas
2014-12-01 22:50 GMT+01:00 <[email protected]>:
> We use codehale metrics to instrument our JDBC and have a special JDBC
> wrapper driver that looks to see if the SQL has a comment.
> This comment is used for the metric name.
>
> For example we might have SQL that looks like:
>
> /* com.snaphop.data.campaign.SELECT */ select * from campaign where ....
>
> Now through our magical JDBC spy wrapper we get a metric named
> "com.snaphop.data.campaign.SELECT" with the execution time and various
> other metrics like how many times per second etc..
> This has worked amazingly well for us since Hibernate will auto prefix SQL
> with comments as an option and our developers can also create their own
> metrics even using plain JDBC.
>
> The problem is that it seems the jOOQ DSL does not allow you to enter
> adhoc SQL comments.
>
> Any thoughts on how we can do this?
>
> --
> 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.
>
--
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.