Top Description Methods
org.jooq

public Interface Binding<T, U>

extends Serializable
Known Direct Implementers
org.jooq.impl.AbstractBinding, org.jooq.impl.BlobBinding, org.jooq.impl.DateAsTimestampBinding, org.jooq.impl.AbstractVarcharBinding, org.jooq.impl.AbstractXMLBinding, org.jooq.impl.NClobBinding, org.jooq.impl.ChainedConverterBinding, org.jooq.impl.ClobBinding, org.jooq.impl.DefaultBinding, org.jooq.impl.DefaultBinding.InternalBinding, org.jooq.impl.LocalDateAsLocalDateTimeBinding
Type Parameters
<T>
The database type - i.e. any type available from SQLDataType
<U>
The user type
Imports
java.io.Serializable, java.sql.CallableStatement, .PreparedStatement, .ResultSet, .SQLException, .SQLInput, .SQLOutput, .Timestamp, java.util.function.Consumer, org.jooq.exception.DataAccessException, org.jooq.impl.DefaultBinding, .SQLDataType, org.jetbrains.annotations.NotNull

An SPI (Service Provider Interface) that exposes all low-level interactions with JDBC bind variables.

This SPI is used by jOOQ users to implement support for custom data types that would otherwise not be supported by jOOQ and/or JDBC. All of jOOQ's internal support for bind variable types is implemented in DefaultBinding.

Creating user defined DataTypes

jOOQ provides built in data types through SQLDataType. Users can define their own data types programmatically by calling DataType#asConvertedDataType(Converter) or DataType#asConvertedDataType(Binding), for example. Custom data types can also be defined on generated code using the <forcedType/> configuration, see the manual for more details

Author
Lukas Eder

Method Summary

Modifier and TypeMethod and Description
public @NotNull Converter<T, U>
converter()

A converter that can convert between the database type and the custom type.

public void
get(BindingGetResultSetContext<U>
The context object containing all argument objects.
ctx
)

Get a ResultSet's OUT value.

public void
get(BindingGetStatementContext<U>
The context object containing all argument objects.
ctx
)

Get a CallableStatement's OUT value.

public void
get(BindingGetSQLInputContext<U>
The context object containing all argument objects.
ctx
)

Get a SQLInput's OUT value.

public static <T, U> @NotNull Binding<T, U>
of(Converter<T, U> converter, Consumer<? super BindingSQLContext<U>> sqlContext, Consumer<? super BindingGetResultSetContext<U>> getResultSetContext, Consumer<? super BindingSetStatementContext<U>> setStatementContext)

Construct a binding from functions.

public static <T, U> @NotNull Binding<T, U>
of(Converter<T, U> converter, Consumer<? super BindingSQLContext<U>> sqlContext, Consumer<? super BindingGetResultSetContext<U>> getResultSetContext, Consumer<? super BindingSetStatementContext<U>> setStatementContext, Consumer<? super BindingRegisterContext<U>> registerContext, Consumer<? super BindingGetStatementContext<U>> getStatementContext)

Construct a binding from functions.

public static <T, U> @NotNull Binding<T, U>
of(Converter<T, U> converter, Consumer<? super BindingSQLContext<U>> sqlContext, Consumer<? super BindingGetResultSetContext<U>> getResultSetContext, Consumer<? super BindingSetStatementContext<U>> setStatementContext, Consumer<? super BindingRegisterContext<U>> registerContext, Consumer<? super BindingGetStatementContext<U>> getStatementContext, Consumer<? super BindingGetSQLInputContext<U>> getSqlInputContext, Consumer<? super BindingSetSQLOutputContext<U>> setSqlOutputContext)

Construct a binding from functions.

public void
register(BindingRegisterContext<U>
The context object containing all argument objects.
ctx
)

Register a CallableStatement's OUT parameter.

public void
set(BindingSetStatementContext<U>
The context object containing all argument objects.
ctx
)

Set a PreparedStatement's IN parameter.

public void
set(BindingSetSQLOutputContext<U>
The context object containing all argument objects.
ctx
)

Set a SQLOutput's IN parameter.

public void
sql(BindingSQLContext<U>
The context object containing all argument objects.
ctx
)

Generate SQL code for the bind variable.

Method Detail

converterback to summary
public @NotNull Converter<T, U> converter()

A converter that can convert between the database type and the custom type.

Annotations
@NotNull
getback to summary
public void get(BindingGetResultSetContext<U> ctx) throws SQLException

Get a ResultSet's OUT value.

Implementations are expected to produce a value by calling BindingGetResultSetContext#value(Object), passing the resulting value to the method.

Parameters
ctx:BindingGetResultSetContext<U>

The context object containing all argument objects.

Exceptions
SQLException:
Implementations are allowed to pass on all SQLExceptions to the caller to be wrapped in DataAccessExceptions.
getback to summary
public void get(BindingGetStatementContext<U> ctx) throws SQLException

Get a CallableStatement's OUT value.

Implementations are expected to produce a value by calling BindingGetStatementContext#value(Object), passing the resulting value to the method.

Parameters
ctx:BindingGetStatementContext<U>

The context object containing all argument objects.

Exceptions
SQLException:
Implementations are allowed to pass on all SQLExceptions to the caller to be wrapped in DataAccessExceptions.
getback to summary
public void get(BindingGetSQLInputContext<U> ctx) throws SQLException

Get a SQLInput's OUT value.

Implementations are expected to produce a value by calling BindingGetSQLInputContext#value(Object), passing the resulting value to the method.

Parameters
ctx:BindingGetSQLInputContext<U>

The context object containing all argument objects.

Exceptions
SQLException:
Implementations are allowed to pass on all SQLExceptions to the caller to be wrapped in DataAccessExceptions.
ofback to summary
public static <T, U> @NotNull Binding<T, U> of(Converter<T, U> converter, Consumer<? super BindingSQLContext<U>> sqlContext, Consumer<? super BindingGetResultSetContext<U>> getResultSetContext, Consumer<? super BindingSetStatementContext<U>> setStatementContext)

Construct a binding from functions.

Annotations
@NotNull
ofback to summary
public static <T, U> @NotNull Binding<T, U> of(Converter<T, U> converter, Consumer<? super BindingSQLContext<U>> sqlContext, Consumer<? super BindingGetResultSetContext<U>> getResultSetContext, Consumer<? super BindingSetStatementContext<U>> setStatementContext, Consumer<? super BindingRegisterContext<U>> registerContext, Consumer<? super BindingGetStatementContext<U>> getStatementContext)

Construct a binding from functions.

Annotations
@NotNull
ofback to summary
public static <T, U> @NotNull Binding<T, U> of(Converter<T, U> converter, Consumer<? super BindingSQLContext<U>> sqlContext, Consumer<? super BindingGetResultSetContext<U>> getResultSetContext, Consumer<? super BindingSetStatementContext<U>> setStatementContext, Consumer<? super BindingRegisterContext<U>> registerContext, Consumer<? super BindingGetStatementContext<U>> getStatementContext, Consumer<? super BindingGetSQLInputContext<U>> getSqlInputContext, Consumer<? super BindingSetSQLOutputContext<U>> setSqlOutputContext)

Construct a binding from functions.

Annotations
@NotNull
registerback to summary
public void register(BindingRegisterContext<U> ctx) throws SQLException

Register a CallableStatement's OUT parameter.

Parameters
ctx:BindingRegisterContext<U>

The context object containing all argument objects.

Exceptions
SQLException:
Implementations are allowed to pass on all SQLExceptions to the caller to be wrapped in DataAccessExceptions.
setback to summary
public void set(BindingSetStatementContext<U> ctx) throws SQLException

Set a PreparedStatement's IN parameter.

Parameters
ctx:BindingSetStatementContext<U>

The context object containing all argument objects.

Exceptions
SQLException:
Implementations are allowed to pass on all SQLExceptions to the caller to be wrapped in DataAccessExceptions.
setback to summary
public void set(BindingSetSQLOutputContext<U> ctx) throws SQLException

Set a SQLOutput's IN parameter.

Parameters
ctx:BindingSetSQLOutputContext<U>

The context object containing all argument objects.

Exceptions
SQLException:
Implementations are allowed to pass on all SQLExceptions to the caller to be wrapped in DataAccessExceptions.
sqlback to summary
public void sql(BindingSQLContext<U> ctx) throws SQLException

Generate SQL code for the bind variable.

Implementations should generate SQL code onto BindingSQLContext#render(), given the context's bind variable located at BindingSQLContext#value(). Examples of such SQL code are:

  • "?": Default implementations can simply generate a question mark.

  • "123": Implementations may choose to inline bind variables to influence execution plan generation.

    RenderContext#paramType() contains information whether inlined bind variables are expected in the current context.

  • "CAST(? AS DATE)": Cast a database to a more specific type. This can be useful in databases like Oracle, which map both DATE and TIMESTAMP SQL types to Timestamp.

    RenderContext#castMode() may contain some hints about whether casting is suggested in the current context.

  • "?::json": Vendor-specific bind variables can be supported, e.g. SQLDialect#POSTGRES's JSON data type.

Implementations must provide consistent behaviour between sql(BindingSQLContext) and set(BindingSetStatementContext), i.e. when bind variables are inlined, then they must not be bound to the PreparedStatement in set(BindingSetStatementContext)

Parameters
ctx:BindingSQLContext<U>

The context object containing all argument objects.

Exceptions
SQLException:
Implementations are allowed to pass on all SQLExceptions to the caller to be wrapped in DataAccessExceptions.