- Type Parameters:
- T- The database type - i.e. any type available from- SQLDataType
- U- 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.
 
When Binding is invoked
 
 A Binding is invoked whenever jOOQ interacts with JDBC's various
 types, including:
 
- get(BindingGetResultSetContext): To read from a JDBC- ResultSet
- get(BindingGetStatementContext): To read from a JDBC- CallableStatement(- OUTparameters).- register(BindingRegisterContext)may be needed to declare- OUTparameters beforehand.
- get(BindingGetSQLInputContext): To read from a JDBC- SQLInput(UDT attributes)
- set(BindingSetStatementContext): To write to a JDBC- PreparedStatement(- sql(BindingSQLContext)may be needed to specify the bind value syntax)
- set(BindingSetSQLOutputContext): To read from a JDBC- SQLOutput(UDT attributes)
 Unlike a Converter, a Binding applies only to
 JDBC interactions. It does not influence how nested data structures (such as
 DSL.multiset(TableLike) or DSL.row(SelectField...)) are
 mapped to Java objects, for example.
 
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.
 
 Ad-hoc
 converters allow for attaching a converter directly to a SQL expression
 in order to keep related logic close together, see the Converter
 Javadoc for more details.
- Author:
- Lukas Eder
- 
Method SummaryModifier 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- 
converterA converter that can convert between the database type and the custom type.While the Converterproperty of a binding is not optional (Converter.fromType()andConverter.toType()are needed by jOOQ's internals), the conversion implementation (i.e.Converter.from(Object)andConverter.to(Object)) isn't strictly required if implementations don't rely on it. If these conversion implementations are non-functional, it is advised to hint at this fact inConverter.fromSupported()andConverter.toSupported().
- 
sqlGenerate 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 both- DATEand- TIMESTAMPSQL types to- Timestamp.
 
 - 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 all- SQLExceptions to the caller to be wrapped in- DataAccessExceptions.
 
- 
registerRegister aCallableStatement'sOUTparameter.- Parameters:
- ctx- The context object containing all argument objects.
- Throws:
- SQLException- Implementations are allowed to pass on all- SQLExceptions to the caller to be wrapped in- DataAccessExceptions.
 
- 
setSet aPreparedStatement'sINparameter.- Parameters:
- ctx- The context object containing all argument objects.
- Throws:
- SQLException- Implementations are allowed to pass on all- SQLExceptions to the caller to be wrapped in- DataAccessExceptions.
 
- 
setSet aSQLOutput'sINparameter.- Parameters:
- ctx- The context object containing all argument objects.
- Throws:
- SQLException- Implementations are allowed to pass on all- SQLExceptions to the caller to be wrapped in- DataAccessExceptions.
 
- 
getGet 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 all- SQLExceptions to the caller to be wrapped in- DataAccessExceptions.
 
- 
getGet 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 all- SQLExceptions to the caller to be wrapped in- DataAccessExceptions.
 
- 
getGet 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 all- SQLExceptions to the caller to be wrapped in- DataAccessExceptions.
 
- 
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.
 
-