- Type Parameters:
T- The database type - i.e. any type available fromSQLDataTypeU- The user type
- All Superinterfaces:
Serializable
- All Known Implementing Classes:
AbstractBinding,AbstractXMLasObjectBinding,BlobBinding,ClobBinding,DateAsTimestampBinding,DefaultBinding,LocalDateAsLocalDateTimeBinding,NClobBinding,XMLasDOMBinding
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 TypeMethodDescriptionA 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> @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.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 Details
-
converter
A converter that can convert between the database type and the custom type. -
sql
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 bothDATEandTIMESTAMPSQL 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 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
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
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
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
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
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
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
@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.
-