public interface VisitListener extends EventListener
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:
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
.
Note: [#2694] [#2695] As of jOOQ 3.2, VisitListener
receive events
only in the context of a RenderContext
, not of a BindContext
.
Modifier and Type | Method and Description |
---|---|
void |
clauseEnd(VisitContext context)
Called after leaving a
Clause . |
void |
clauseStart(VisitContext context)
Called before entering a
Clause . |
void |
visitEnd(VisitContext context)
Called after visiting a
QueryPart . |
void |
visitStart(VisitContext context)
Called before visiting a
QueryPart . |
void clauseStart(VisitContext context)
Clause
.Context.start(Clause)
void clauseEnd(VisitContext context)
Clause
.Context.end(Clause)
void visitStart(VisitContext context)
QueryPart
.
Certain VisitListener
implementations may chose to replace
the QueryPart
contained in the argument VisitContext
through VisitContext.queryPart(QueryPart)
. This can be used for
many use-cases, for example to add a CHECK OPTION
to an
Oracle INSERT
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)
Context.visit(QueryPart)
void visitEnd(VisitContext context)
QueryPart
.Context.visit(QueryPart)
Copyright © 2014. All Rights Reserved.