-
- Type Parameters:
T- The database type - i.e. any type available fromSQLDataTypeU- The user type
- All Superinterfaces:
Serializable
- All Known Implementing Classes:
AbstractXMLasObjectBinding,BlobBinding,ClobBinding,DateAsTimestampBinding,DefaultBinding,LocalDateAsLocalDateTimeBinding,XMLasDOMBinding
public interface Binding<T,U> extends Serializable
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
DataTypesjOOQ provides built in data types through
SQLDataType. Users can define their own data types programmatically by callingDataType.asConvertedDataType(Converter)orDataType.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
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description Converter<T,U>converter()A converter that can convert between the database type and the custom type.voidget(BindingGetResultSetContext<U> ctx)Get aResultSet'sOUTvalue.voidget(BindingGetSQLInputContext<U> ctx)Get aSQLInput'sOUTvalue.voidget(BindingGetStatementContext<U> ctx)Get aCallableStatement'sOUTvalue.static <T,U>
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.static <T,U>
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.static <T,U>
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.voidregister(BindingRegisterContext<U> ctx)Register aCallableStatement'sOUTparameter.voidset(BindingSetSQLOutputContext<U> ctx)Set aSQLOutput'sINparameter.voidset(BindingSetStatementContext<U> ctx)Set aPreparedStatement'sINparameter.voidsql(BindingSQLContext<U> ctx)Generate SQL code for the bind variable.
-
-
-
Method Detail
-
converter
Converter<T,U> converter()
A converter that can convert between the database type and the custom type.
-
sql
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 atBindingSQLContext.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 bothDATEandTIMESTAMPSQL types toTimestamp.
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)andset(BindingSetStatementContext), i.e. when bind variables are inlined, then they must not be bound to thePreparedStatementinset(BindingSetStatementContext)- Parameters:
ctx- The context object containing all argument objects.- Throws:
SQLException- Implementations are allowed to pass on allSQLExceptions to the caller to be wrapped inDataAccessExceptions.
-
register
void register(BindingRegisterContext<U> ctx) throws SQLException
Register aCallableStatement'sOUTparameter.- Parameters:
ctx- The context object containing all argument objects.- Throws:
SQLException- Implementations are allowed to pass on allSQLExceptions to the caller to be wrapped inDataAccessExceptions.
-
set
void set(BindingSetStatementContext<U> ctx) throws SQLException
Set aPreparedStatement'sINparameter.- Parameters:
ctx- The context object containing all argument objects.- Throws:
SQLException- Implementations are allowed to pass on allSQLExceptions to the caller to be wrapped inDataAccessExceptions.
-
set
void set(BindingSetSQLOutputContext<U> ctx) throws SQLException
Set aSQLOutput'sINparameter.- Parameters:
ctx- The context object containing all argument objects.- Throws:
SQLException- Implementations are allowed to pass on allSQLExceptions to the caller to be wrapped inDataAccessExceptions.
-
get
void get(BindingGetResultSetContext<U> ctx) throws SQLException
Get aResultSet'sOUTvalue.Implementations are expected to produce a value by calling
BindingGetResultSetContext.value(Object), passing the resulting value to the method.- Parameters:
ctx- The context object containing all argument objects.- Throws:
SQLException- Implementations are allowed to pass on allSQLExceptions to the caller to be wrapped inDataAccessExceptions.
-
get
void get(BindingGetStatementContext<U> ctx) throws SQLException
Get aCallableStatement'sOUTvalue.Implementations are expected to produce a value by calling
BindingGetStatementContext.value(Object), passing the resulting value to the method.- Parameters:
ctx- The context object containing all argument objects.- Throws:
SQLException- Implementations are allowed to pass on allSQLExceptions to the caller to be wrapped inDataAccessExceptions.
-
get
void get(BindingGetSQLInputContext<U> ctx) throws SQLException
Get aSQLInput'sOUTvalue.Implementations are expected to produce a value by calling
BindingGetSQLInputContext.value(Object), passing the resulting value to the method.- Parameters:
ctx- The context object containing all argument objects.- Throws:
SQLException- Implementations are allowed to pass on allSQLExceptions to the caller to be wrapped inDataAccessExceptions.
-
of
static <T,U> 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.
-
of
static <T,U> 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.
-
of
static <T,U> 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.
-
-