- All Superinterfaces:
EventListener
- All Known Implementing Classes:
CallbackVisitListener
,DefaultVisitListener
QueryPart
traversal events.
Users may want to centrally inject custom behaviour when rendering their
QueryPart
objects or when binding values to PreparedStatement
s. This service provider allows to hook in callback method implementations
before or after these events:
The following rules apply to visiting clauses and query parts:
- Clauses may "surround" a query part. See an example below.
- Not every query part is "surrounded" by a clause
An example is given here:
SELECT 1 FROM [A CROSS JOIN B]
The above example will create the following set of events:
Clause.SELECT
+-Clause.SELECT_SELECT
| +-Clause.FIELD
| +-val(1) +-Clause.SELECT_FROM
+-Clause.TABLE_JOIN
+-Clause.TABLE
| +-table("A") +-Clause.TABLE_JOIN_CROSS
+-Clause.TABLE
+-table("B")
Whatever is not a Clause
in the above example is a QueryPart
.
A remark about performance
Implementors of this SPI should be wary of performance implications of their
implementations. The below methods are called for every AST element of every
query, which produces a lot of calls throughout an application. What would
otherwise be premature optimisations may have great effect inside the
VisitListener
. For more details, please refer to this article:
https://blog.jooq.org/top-10-easy-performance-optimisations-in-
java/.
- Author:
- Lukas Eder
-
Method Summary
Modifier and TypeMethodDescriptiondefault void
clauseEnd
(VisitContext context) Called after leaving aClause
.default void
clauseStart
(VisitContext context) Called before entering aClause
.static CallbackVisitListener
onClauseEnd
(Consumer<? super VisitContext> onClauseEnd) Create aVisitListener
with aonClauseEnd(Consumer)
implementation.static CallbackVisitListener
onClauseStart
(Consumer<? super VisitContext> onClauseStart) Create aVisitListener
with aonClauseStart(Consumer)
implementation.static CallbackVisitListener
onVisitEnd
(Consumer<? super VisitContext> onVisitEnd) Create aVisitListener
with aonClauseStart(Consumer)
implementation.static CallbackVisitListener
onVisitStart
(Consumer<? super VisitContext> onVisitStart) Create aVisitListener
with aonVisitStart(Consumer)
implementation.default void
visitEnd
(VisitContext context) Called after visiting aQueryPart
.default void
visitStart
(VisitContext context) Called before visiting aQueryPart
.
-
Method Details
-
clauseStart
Called before entering aClause
.- Parameters:
context
- The context containing information about the traversal.- See Also:
-
clauseEnd
Called after leaving aClause
.- Parameters:
context
- The context containing information about the traversal.- See Also:
-
visitStart
Called before visiting aQueryPart
.Certain
VisitListener
implementations may chose to replace theQueryPart
contained in the argumentVisitContext
throughVisitContext.queryPart(QueryPart)
. This can be used for many use-cases, for example to add aCHECK OPTION
to an OracleINSERT
statement:
The above SQL transformation allows to prevent inserting new books for authors other than those with-- Original query INSERT INTO book (id, author_id, title) VALUES (10, 15, '1984') -- Transformed query INSERT INTO ( SELECT * FROM book WHERE author_id IN (1, 2, 3) WITH CHECK OPTION ) (id, author_id, title) VALUES (10, 15, '1984')
author_id IN (1, 2, 3)
- Parameters:
context
- The context containing information about the traversal.- See Also:
-
visitEnd
Called after visiting aQueryPart
.- Parameters:
context
- The context containing information about the traversal.- See Also:
-
onClauseStart
Create aVisitListener
with aonClauseStart(Consumer)
implementation. -
onClauseEnd
Create aVisitListener
with aonClauseEnd(Consumer)
implementation. -
onVisitStart
Create aVisitListener
with aonVisitStart(Consumer)
implementation. -
onVisitEnd
Create aVisitListener
with aonClauseStart(Consumer)
implementation.
-