jrochette
jrochette

Reputation: 1117

How to inject a condition in all SQL queries using jOOQ

I am using jOOQ to generate my SQL queries and I was wondering if there is a way to inject a condition in all the queries that my application does.

For example, I would like to have something like account = {accountNameHere} in all the SELECT that the application does. Since I already have a a high number of different queries, I would like to do that without manually adding the condition to each statement.

Is there a way to do that easily using jOOQ ? Maybe using the VisitListener ?

Upvotes: 1

Views: 749

Answers (1)

Lukas Eder
Lukas Eder

Reputation: 220762

Yes, a VisitListener will be the most thorough way to inject a custom predicate into all of your SELECT statements (including subqueries, of course). In fact, what you're looking for is sometimes referred to as "row level security" (natively supported in RDBMS like Oracle or SQL Server).

The following blog post explains how to achieve this via a VisitListener:

http://blog.jooq.org/2015/06/17/implementing-client-side-row-level-security-with-jooq

Upvotes: 1

Related Questions