T - The database type - i.e. any type available from
SQLDataTypeU - The user typepublic interface Converter<T,U> extends Serializable
Converter for data types.
A general data type conversion interface that can be provided to jOOQ at
various places in order to perform custom data type conversion. Conversion is
directed, this means that the Converter is used
fromType() is the type as defined in the database.toType() is the user-defined type
Note: In order to avoid unwanted side-effects, it is highly recommended (yet
not required) for from(Object) and to(Object) to be
reciprocal. The two methods are reciprocal, if for all
X and Y, it can be said that
Y.equals(converter.from(X)), then
X.equals(converter.to(Y)).X.equals(converter.from(converter.to(X)))X.equals(converter.to(converter.from(X)))Furthermore, it is recommended (yet not required) that
converter.from(null) == nullconverter.to(null) == null
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
| Modifier and Type | Method and Description |
|---|---|
default <X> Converter<T,X> |
andThen(Converter<? super U,X> converter)
Chain a converter to this converter.
|
U |
from(T databaseObject)
Convert a database object to a user object
|
Class<T> |
fromType()
The database type
|
default Converter<U,T> |
inverse()
Inverse this converter.
|
static <T,U> Converter<T,U> |
of(Class<T> fromType,
Class<U> toType,
Function<? super T,? extends U> from,
Function<? super U,? extends T> to)
Construct a new converter from functions.
|
static <T,U> Converter<T,U> |
ofNullable(Class<T> fromType,
Class<U> toType,
Function<? super T,? extends U> from,
Function<? super U,? extends T> to)
Construct a new converter from functions.
|
T |
to(U userObject)
Convert a user object to a database object
|
Class<U> |
toType()
The user type
|
U from(T databaseObject)
databaseObject - The database objectT to(U userObject)
userObject - The user objectdefault <X> Converter<T,X> andThen(Converter<? super U,X> converter)
static <T,U> Converter<T,U> of(Class<T> fromType, Class<U> toType, Function<? super T,? extends U> from, Function<? super U,? extends T> to)
T - the database typeU - the user typefromType - The database typetoType - The user typefrom - A function converting from T to Uto - A function converting from U to TConverterstatic <T,U> Converter<T,U> ofNullable(Class<T> fromType, Class<U> toType, Function<? super T,? extends U> from, Function<? super U,? extends T> to)
This works like of(Class, Class, Function, Function),
except that both conversion Functions are decorated with a
function that always returns null for null
inputs.
Example:
Converter
T - the database typeU - the user typefromType - The database typetoType - The user typefrom - A function converting from T to Uto - A function converting from U to TConverterCopyright © 2019. All rights reserved.