- All Implemented Interfaces:
Serializable
,QueryPart
,QueryPartInternal
QueryPart
implementations in client code.
Client code may provide proper Condition
implementations extending
this useful base class. All necessary parts of the Condition
interface are already implemented. Only this method needs further
implementation: accept(Context)
.
Refer to that methods' Javadoc for further details about their expected behaviour.
Such custom QueryPart
implementations can be useful in any of
these scenarios:
- When reusing a custom
QueryPart
in other customQueryPart
s, e.g. inCustomCondition
,CustomField
,CustomTable
, etc. - When inlining a custom
QueryPart
in plain SQL methods, such asDSL.condition(String, QueryPart...)
,DSL.field(String, QueryPart...)
,DSL.table(String, QueryPart...)
- Author:
- Lukas Eder
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptiondefault QueryPart
Traverse aQueryPart
hierarchy and recursively replace its elements by alternatives.default <R> R
abstract void
Subclasses must implement this method.final Clause[]
TheClause
s that are represented by this query part.protected final DSLContext
create()
Deprecated.protected final DSLContext
create
(Configuration configuration) Deprecated.- 3.11.0 - [#6722] - UseAttachable.configuration()
andConfiguration.dsl()
instead.protected final DSLContext
Deprecated.- 3.11.0 - [#6722] - UseAttachable.configuration()
andConfiguration.dsl()
instead.boolean
Subclasses may override thisfinal boolean
Subclasses may override thisboolean
Subclasses may override thisfinal boolean
Subclasses may override thisboolean
Subclasses may override thisboolean
Check whether thisQueryPart
can be considered equal to anotherQueryPart
.boolean
Subclasses may override thisint
hashCode()
Generate a hash code from thisQueryPart
.static final CustomQueryPart
Create aCustomQueryPart
from a lambda expression.boolean
rendersContent
(Context<?> ctx) Subclasses may override thistoString()
Render a SQL string representation of thisQueryPart
.protected final DataAccessException
translate
(String sql, SQLException e) Internal convenience method
-
Constructor Details
-
CustomQueryPart
protected CustomQueryPart()
-
-
Method Details
-
of
Create aCustomQueryPart
from a lambda expression. -
accept
Subclasses must implement this method.
ThisQueryPart
canaccept
aContext
object in order to render a SQL string or to bind its variables.- Specified by:
accept
in interfaceQueryPartInternal
-
clauses
Description copied from interface:QueryPartInternal
TheClause
s that are represented by this query part.QueryPart
s can specify severalClause
s for which an event will be emittedbefore
(in forward order) andafter
(in reverse order) visiting the the query part throughContext.visit(QueryPart)
This method is for JOOQ INTERNAL USE only. Do not reference directly
- Specified by:
clauses
in interfaceQueryPartInternal
- Returns:
- The
Clause
s represented by this query part ornull
or an empty array if this query part does not represent a clause.
-
declaresFields
public final boolean declaresFields()Subclasses may override this- Specified by:
declaresFields
in interfaceQueryPartInternal
-
declaresTables
public final boolean declaresTables()Subclasses may override this- Specified by:
declaresTables
in interfaceQueryPartInternal
-
$traverse
Description copied from interface:QueryPart
Traverser thisQueryPart
expression tree using a composableTraverser
, producing a result.This offers a generic way to traverse expression trees to translate the tree to arbitrary other data structures. The simplest traversal would just count all the tree elements:
int count = CUSTOMER.NAME.eq(1).$traverse(0, (i, p) -> i + 1);
The same can be achieved by translating the JDK
Collector
API to theTraverser
API usingTraversers.collecting(Collector)
.CUSTOMER.NAME.eq(1).$traverse(Traversers.collecting(Collectors.counting()));
Unlike a
Collector
, aTraverser
is optimised for tree traversal, not stream traversal:- Is not designed for parallelism
- It can
Traverser.abort()
traversal early when the result can be produced early (e.g. when runningTraversers.containing(QueryPart)
, and a result has been found). - It can decide whether to
Traverser.recurse()
into aQueryPart
subtree, or whether that is not necessary or even undesirable, e.g. to prevent entering new subquery scopes. - Unlike a Collector, which can use its
Collector.accumulator()
to accumulate each element only once, in tree traversal, it's desirable to be able to distinguish between accumulating an itemTraverser.before()
orTraverser.after()
recursing into it. This is useful e.g. to wrap each tree node in XML opening and closing tags.
This is a commercial jOOQ edition only feature.
-
$replace
Description copied from interface:QueryPart
-
rendersContent
Subclasses may override this- Specified by:
rendersContent
in interfaceQueryPartInternal
-
declaresWindows
public boolean declaresWindows()Subclasses may override this- Specified by:
declaresWindows
in interfaceQueryPartInternal
-
declaresCTE
public boolean declaresCTE()Subclasses may override this- Specified by:
declaresCTE
in interfaceQueryPartInternal
-
declaresParameters
Subclasses may override this- Specified by:
declaresParameters
in interfaceQueryPartInternal
-
generatesCast
public boolean generatesCast()Subclasses may override this- Specified by:
generatesCast
in interfaceQueryPartInternal
-
equals
Description copied from interface:QueryPart
Check whether thisQueryPart
can be considered equal to anotherQueryPart
.In general,
QueryPart
equality is defined in terms ofQueryPart.toString()
equality. In other words, two query parts are considered equal if their rendered SQL (with inlined bind variables) is equal. This means that the two query parts do not necessarily have to be of the same type.Some
QueryPart
implementations may choose to override this behaviour for improved performance, asQueryPart.toString()
is an expensive operation, if called many times. -
hashCode
public int hashCode()Description copied from interface:QueryPart
Generate a hash code from thisQueryPart
.In general,
QueryPart
hash codes are the same as the hash codes generated fromQueryPart.toString()
. This guarantees consistent behaviour withQueryPart.equals(Object)
Some
QueryPart
implementations may choose to override this behaviour for improved performance, asQueryPart.toString()
is an expensive operation, if called many times. -
toString
Description copied from interface:QueryPart
Render a SQL string representation of thisQueryPart
.For improved debugging, this renders a SQL string of this
QueryPart
with inlined bind variables. If thisQueryPart
isAttachable
, then the attachedConfiguration
may be used for rendering the SQL string, includingSQLDialect
andSettings
. Do note that mostQueryPart
instances are not attached to aConfiguration
, and thus there is no guarantee that the SQL string will make sense in the context of a specific database. -
create
Deprecated.- 3.11.0 - [#6722] - UseAttachable.configuration()
andConfiguration.dsl()
instead.Internal convenience method -
create
Deprecated.- 3.11.0 - [#6722] - UseAttachable.configuration()
andConfiguration.dsl()
instead.Internal convenience method -
create
Deprecated.- 3.11.0 - [#6722] - UseAttachable.configuration()
andConfiguration.dsl()
instead.Internal convenience method -
translate
Internal convenience method
-
Attachable.configuration()
andConfiguration.dsl()
instead.