How do I wrap brackets around parameter values when using jOOq?

617 Views Asked by At

I am using jOOq to write queries except I am using a vendor specific type of SQL... to be specific flexible search. The main difference between SQL and flexiSearch is that parameter values are enclosed in a curly bracket. e.g.

SELECT * FROM {Product} WHERE {code} LIKE ‘%al%’

So what I'm trying to do is to get jOOq to automatically intercept the query building procedure to include the brackets.

Looking through the docs, it seems that I should implement some kind of execute listener? But I am not sure what to do after that. Thanks

1

There are 1 best solutions below

2
On

You could indeed implement an ExecuteListener that replaces

  • every odd " by a { and every even " by a } using any dialect (be careful of syntactic ambiguities)
  • every odd ` by a { and every even ` by a } using MySQL dialect
  • every [ by a { and every ] by a } using SQL Server dialect

But from what I can tell, that won't be the only thing you'll be patching in generated SQL, so you might as well fork the jOOQ Open Source Edition and patch the relevant code yourself.

Beware, jOOQ doesn't really support this particular dialect. This will not be the only thing you'll run into. For example, you could try to pattern match subqueries in an ExecuteListener and wrap them in {{ ... }}, but that, too, would be much easier to achieve by patching jOOQ directly.