-
- Type Parameters:
T
- The database type - i.e. any type available fromSQLDataType
U
- The user type
- All Superinterfaces:
Serializable
- All Known Implementing Classes:
AbstractBinding
,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
DataType
sjOOQ 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 @NotNull Converter<T,U>
converter()
A converter that can convert between the database type and the custom type.void
get(BindingGetResultSetContext<U> ctx)
Get aResultSet
'sOUT
value.void
get(BindingGetSQLInputContext<U> ctx)
Get aSQLInput
'sOUT
value.void
get(BindingGetStatementContext<U> ctx)
Get aCallableStatement
'sOUT
value.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.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.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.void
register(BindingRegisterContext<U> ctx)
Register aCallableStatement
'sOUT
parameter.void
set(BindingSetSQLOutputContext<U> ctx)
Set aSQLOutput
'sIN
parameter.void
set(BindingSetStatementContext<U> ctx)
Set aPreparedStatement
'sIN
parameter.void
sql(BindingSQLContext<U> ctx)
Generate SQL code for the bind variable.
-
-
-
Method Detail
-
converter
@NotNull @NotNull 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.
Context.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 bothDATE
andTIMESTAMP
SQL types toTimestamp
.
Context.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 thePreparedStatement
inset(BindingSetStatementContext)
- Parameters:
ctx
- The context object containing all argument objects.- Throws:
SQLException
- Implementations are allowed to pass on allSQLException
s to the caller to be wrapped inDataAccessException
s.
-
register
void register(BindingRegisterContext<U> ctx) throws SQLException
Register aCallableStatement
'sOUT
parameter.- Parameters:
ctx
- The context object containing all argument objects.- Throws:
SQLException
- Implementations are allowed to pass on allSQLException
s to the caller to be wrapped inDataAccessException
s.
-
set
void set(BindingSetStatementContext<U> ctx) throws SQLException
Set aPreparedStatement
'sIN
parameter.- Parameters:
ctx
- The context object containing all argument objects.- Throws:
SQLException
- Implementations are allowed to pass on allSQLException
s to the caller to be wrapped inDataAccessException
s.
-
set
void set(BindingSetSQLOutputContext<U> ctx) throws SQLException
Set aSQLOutput
'sIN
parameter.- Parameters:
ctx
- The context object containing all argument objects.- Throws:
SQLException
- Implementations are allowed to pass on allSQLException
s to the caller to be wrapped inDataAccessException
s.
-
get
void get(BindingGetResultSetContext<U> ctx) throws SQLException
Get aResultSet
'sOUT
value.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 allSQLException
s to the caller to be wrapped inDataAccessException
s.
-
get
void get(BindingGetStatementContext<U> ctx) throws SQLException
Get aCallableStatement
'sOUT
value.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 allSQLException
s to the caller to be wrapped inDataAccessException
s.
-
get
void get(BindingGetSQLInputContext<U> ctx) throws SQLException
Get aSQLInput
'sOUT
value.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 allSQLException
s to the caller to be wrapped inDataAccessException
s.
-
of
@NotNull 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.
-
of
@NotNull 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.
-
of
@NotNull 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.
-
-