-
- Type Parameters:
T- The Java type associated with this SQL data type
- All Superinterfaces:
Named,QueryPart,Serializable
- All Known Implementing Classes:
DefaultDataType
public interface DataType<T> extends Named
A common interface to all dialect-specific data types.jOOQ provides built in data types through
SQLDataType. Users can define their own data types programmatically by callingasConvertedDataType(Converter)orasConvertedDataType(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 Instance Methods Abstract Methods Default Methods Deprecated Methods Modifier and Type Method Description <A extends ArrayRecord<?>>
@NotNull DataType<A>asArrayDataType(Class<A> arrayDataType)Retrieve the data type for an Oracle-style ARRAY of this data type.default <U> @NotNull DataType<U>asConvertedDataType(Class<U> toType, Function<? super T,? extends U> from, Function<? super U,? extends T> to)Convenience method for converting this type usingConverter.of(Class, Class, Function, Function).<U> @NotNull DataType<U>asConvertedDataType(Binding<? super T,U> binding)Retrieve the data type for a given binding.<U> @NotNull DataType<U>asConvertedDataType(Converter<? super T,U> converter)Retrieve the data type for a given converter.<E extends EnumType>
@NotNull DataType<E>asEnumDataType(Class<E> enumDataType)Retrieve the data type for a given enum data type.@Nullable CharacterSetcharacterSet()Get the character set of this data type, ornullif there is no character set, or if the default character set applies.@NotNull DataType<T>characterSet(CharacterSet characterSet)Return a new data type like this, with a new character set.@Nullable Collationcollation()Get the collation of this data type, ornullif there is no collation, or if the default collation applies.@NotNull DataType<T>collation(Collation collation)Return a new data type like this, with a new collation.Tconvert(Object object)Convert an arbitrary object into<T>.@NotNull T[]convert(Object... objects)Convert an arbitrary set of objects into<T>.@NotNull List<T>convert(Collection<?> objects)Convert an arbitrary set of objects into<T>.@Nullable Field<T>default_()The expression to be applied as theDEFAULTvalue for this data type.@NotNull DataType<T>default_(Field<T> defaultValue)Specify an expression to be applied as theDEFAULTvalue for this data type.@NotNull DataType<T>default_(T defaultValue)Specify an expression to be applied as theDEFAULTvalue for this data type.booleandefaulted()Get the defaultability of this data type.@NotNull DataType<T>defaulted(boolean defaulted)Deprecated.- [#3852] - 3.8.0 - UsedefaultValue(Field)instead.@Nullable Field<T>defaultValue()The expression to be applied as theDEFAULTvalue for this data type.@NotNull DataType<T>defaultValue(Field<T> defaultValue)Specify an expression to be applied as theDEFAULTvalue for this data type.@NotNull DataType<T>defaultValue(T defaultValue)Specify an expression to be applied as theDEFAULTvalue for this data type.@Nullable DataType<?>getArrayComponentDataType()Retrieve the Java component data type if this is an ARRAY type, ornull, otherwise.@Nullable Class<?>getArrayComponentType()Retrieve the Java component type if this is an ARRAY type, ornull, otherwise.@NotNull DataType<T[]>getArrayDataType()Retrieve the data type for an ARRAY of this data type.@NotNull Class<T[]>getArrayType()Retrieve the Java type associated with ARRAYs of this data type.@NotNull Binding<?,T>getBinding()Get the data type binding associated with this data type.@NotNull StringgetCastTypeName()Retrieve the dialect-specific type name associated with this data type used for casting.@NotNull StringgetCastTypeName(Configuration configuration)Retrieve the dialect-specific type name associated with this data type used for casting.@NotNull Converter<?,T>getConverter()Get the converter associated with this data type.@NotNull DataType<T>getDataType(Configuration configuration)The dialect-specific data type representing this data type.@Nullable SQLDialectgetDialect()Retrieve the underlyingSQLDialect.@Nullable Domain<T>getDomain()Get the defining DOMAIN type orNULLif there is no such type.@Nullable DataType<T>getSQLDataType()Get the standard SQL data type of this (dialect-specific) data type if available.intgetSQLType()Get JDBCTypesvalue.intgetSQLType(Configuration configuration)Get the dialect-specific JDBCTypesvalue.@NotNull Class<T>getType()Retrieve the Java type associated with this data type.@NotNull StringgetTypeName()Retrieve the dialect-specific type name associated with this data type.@NotNull StringgetTypeName(Configuration configuration)Retrieve the dialect-specific type name associated with this data type.booleanhasLength()Whether this data type has a length.booleanhasPrecision()Whether this data type has a precision.booleanhasScale()Whether this data type has a scale.booleanidentity()Get the identity flag of this data type.@NotNull DataType<T>identity(boolean identity)Return a new data type like this, with a new identity flag.booleanisArray()Whether this data type is an array type.booleanisBinary()Whether this data type is any binary type.booleanisDate()Whether this data type is any date type.booleanisDateTime()Whether this data type is any date or time type.booleanisEmbeddable()Whether this data type is an embeddable type.booleanisEnum()Whether this data type is an enum type.booleanisInteger()Whether this data type is any integer data type.booleanisInterval()Whether this data type is any interval type.booleanisJSON()Whether this data type is a JSON type.booleanisLob()Whether this data type is best deserialised as aLOB.booleanisNString()Whether this data type is any national character data type.booleanisNumeric()Whether this data type is any numeric data type.booleanisString()Whether this data type is any character data type.booleanisTemporal()Whether this data type is any date or time type.booleanisTime()Whether this data type is any time type.booleanisTimestamp()Whether this data type is any timestamp type.booleanisUDT()Whether this data type is a UDT type.booleanisXML()Whether this data type is an XML type.intlength()Get the length of this data type.@NotNull DataType<T>length(int length)Return a new data type like this, with a new length value.booleanlengthDefined()Whether the precision returned bylength()is defined.@NotNull Nullabilitynullability()Get the nullability of this data type.@NotNull DataType<T>nullability(Nullability nullability)Return a new data type like this, with a new nullability.booleannullable()Get the nullability of this data type.@NotNull DataType<T>nullable(boolean nullable)Return a new data type like this, with a new nullability.intprecision()Get the precision of this data type.@NotNull DataType<T>precision(int precision)Return a new data type like this, with a new precision value.@NotNull DataType<T>precision(int precision, int scale)Return a new data type like this, with a new precision and scale value.booleanprecisionDefined()Whether the precision returned byprecision()is defined.intscale()Get the scale of this data type.@NotNull DataType<T>scale(int scale)Return a new data type like this, with a new scale value.booleanscaleDefined()Whether the precision returned byscale()is defined.-
Methods inherited from interface org.jooq.Named
getComment, getCommentPart, getName, getQualifiedName, getUnqualifiedName
-
-
-
-
Method Detail
-
getSQLDataType
@Nullable @Nullable DataType<T> getSQLDataType()
Get the standard SQL data type of this (dialect-specific) data type if available.
-
getDataType
@NotNull @NotNull DataType<T> getDataType(Configuration configuration)
The dialect-specific data type representing this data type.
-
getSQLType
int getSQLType()
Get JDBCTypesvalue.
-
getSQLType
int getSQLType(Configuration configuration)
Get the dialect-specific JDBCTypesvalue.
-
getBinding
@NotNull @NotNull Binding<?,T> getBinding()
Get the data type binding associated with this data type.
-
getConverter
@NotNull @NotNull Converter<?,T> getConverter()
Get the converter associated with this data type.
-
getDomain
@Nullable @Nullable Domain<T> getDomain()
Get the defining DOMAIN type orNULLif there is no such type.
-
getArrayType
@NotNull @NotNull Class<T[]> getArrayType()
Retrieve the Java type associated with ARRAYs of this data type.
-
getArrayDataType
@NotNull @NotNull DataType<T[]> getArrayDataType()
Retrieve the data type for an ARRAY of this data type.
-
getArrayComponentType
@Nullable @Nullable Class<?> getArrayComponentType()
Retrieve the Java component type if this is an ARRAY type, ornull, otherwise.
-
getArrayComponentDataType
@Nullable @Nullable DataType<?> getArrayComponentDataType()
Retrieve the Java component data type if this is an ARRAY type, ornull, otherwise.
-
asArrayDataType
@NotNull @Pro <A extends ArrayRecord<?>> @NotNull DataType<A> asArrayDataType(Class<A> arrayDataType)
Retrieve the data type for an Oracle-style ARRAY of this data type.
-
asEnumDataType
@NotNull <E extends EnumType> @NotNull DataType<E> asEnumDataType(Class<E> enumDataType)
Retrieve the data type for a given enum data type.
-
asConvertedDataType
@NotNull <U> @NotNull DataType<U> asConvertedDataType(Converter<? super T,U> converter)
Retrieve the data type for a given converter.
-
asConvertedDataType
@NotNull default <U> @NotNull DataType<U> asConvertedDataType(Class<U> toType, Function<? super T,? extends U> from, Function<? super U,? extends T> to)
Convenience method for converting this type usingConverter.of(Class, Class, Function, Function).
-
asConvertedDataType
@NotNull <U> @NotNull DataType<U> asConvertedDataType(Binding<? super T,U> binding)
Retrieve the data type for a given binding.
-
getTypeName
@NotNull @NotNull String getTypeName()
Retrieve the dialect-specific type name associated with this data type.
-
getTypeName
@NotNull @NotNull String getTypeName(Configuration configuration)
Retrieve the dialect-specific type name associated with this data type.
-
getCastTypeName
@NotNull @NotNull String getCastTypeName()
Retrieve the dialect-specific type name associated with this data type used for casting.This is useful for some dialects that have specialised type names for cast expressions. Other dialects require type-length binding when casting, (e.g. VARCHAR(32767))
-
getCastTypeName
@NotNull @NotNull String getCastTypeName(Configuration configuration)
Retrieve the dialect-specific type name associated with this data type used for casting.This is useful for some dialects that have specialised type names for cast expressions. Other dialects require type-length binding when casting, (e.g. VARCHAR(32767))
-
getDialect
@Nullable @Nullable SQLDialect getDialect()
Retrieve the underlyingSQLDialect.
-
convert
T convert(Object object)
Convert an arbitrary object into<T>.See
Convert.convert(Object, Class)for details about conversion rules. Notice this does not pass through anyConfiguration.converterProvider().- Parameters:
object- The object to be converted- Returns:
- The converted object
- Throws:
DataTypeException- If conversion fails.
-
convert
@NotNull @NotNull T[] convert(Object... objects)
Convert an arbitrary set of objects into<T>.See
Convert.convert(Object, Class)for details about conversion rules. Notice this does not pass through anyConfiguration.converterProvider().- Parameters:
objects- The objects to be converted- Returns:
- The converted objects
- Throws:
DataTypeException- If conversion fails.
-
convert
@NotNull @NotNull List<T> convert(Collection<?> objects)
Convert an arbitrary set of objects into<T>.See
Convert.convert(Object, Class)for details about conversion rules. Notice this does not pass through anyConfiguration.converterProvider().- Parameters:
objects- The objects to be converted- Returns:
- The converted objects
- Throws:
DataTypeException- If conversion fails.
-
nullability
@NotNull @Support @NotNull DataType<T> nullability(Nullability nullability)
Return a new data type like this, with a new nullability.[#5709] A
nullablecolumn cannot have anidentity().- Parameters:
nullability- The new nullability- Returns:
- The new data type
-
nullability
@NotNull @NotNull Nullability nullability()
Get the nullability of this data type.- Returns:
- The nullability
-
nullable
@NotNull @Support @NotNull DataType<T> nullable(boolean nullable)
Return a new data type like this, with a new nullability.This is the same as calling
nullability(Nullability)with any ofNullability.NULLorNullability.NOT_NULLas an argument.[#5709] A
nullablecolumn cannot have anidentity().- Parameters:
nullable- The new nullability- Returns:
- The new data type
-
nullable
boolean nullable()
Get the nullability of this data type.This returns
trueby default, i.e. ifnullability()isNullability.DEFAULT.- Returns:
- The nullability
-
collation
@NotNull @Support({AURORA_MYSQL,AURORA_POSTGRES,COCKROACHDB,HSQLDB,MARIADB,MEMSQL,MYSQL,ORACLE,POSTGRES,SQLDATAWAREHOUSE,SQLITE,SQLSERVER}) @NotNull DataType<T> collation(Collation collation)
Return a new data type like this, with a new collation.
-
collation
@Nullable @Nullable Collation collation()
Get the collation of this data type, ornullif there is no collation, or if the default collation applies.
-
characterSet
@NotNull @Support({AURORA_MYSQL,MARIADB,MEMSQL,MYSQL}) @NotNull DataType<T> characterSet(CharacterSet characterSet)
Return a new data type like this, with a new character set.
-
characterSet
@Nullable @Nullable CharacterSet characterSet()
Get the character set of this data type, ornullif there is no character set, or if the default character set applies.
-
identity
@NotNull @Support @NotNull DataType<T> identity(boolean identity)
Return a new data type like this, with a new identity flag.[#5709] The IDENTITY flag imposes a NOT NULL constraint, and removes all DEFAULT values.
- Parameters:
identity- The new identity flag- Returns:
- The new data type
-
identity
boolean identity()
Get the identity flag of this data type.- Returns:
- The identity flag.
-
defaultValue
@NotNull @Support @NotNull DataType<T> defaultValue(T defaultValue)
Specify an expression to be applied as theDEFAULTvalue for this data type.[#5709] A
defaultedcolumn cannot have anidentity().This is an alias for
default_(Object).- See Also:
defaultValue(Field)
-
defaultValue
@NotNull @Support @NotNull DataType<T> defaultValue(Field<T> defaultValue)
Specify an expression to be applied as theDEFAULTvalue for this data type.A default value of a data type applies to DDL statements, such as
CREATE TABLEALTER TABLE
The distinct types of possible
DEFAULTexpressions is defined by the underlying database. Please refer to your database manual to learn what expressions are possible.This is an alias for
default_(Field).
-
defaultValue
@Nullable @Nullable Field<T> defaultValue()
The expression to be applied as theDEFAULTvalue for this data type.This is an alias for
default_().- Returns:
- The default value if present, or
nullif no default value is specified for this data type. - See Also:
defaultValue(Field)
-
default_
@NotNull @Support @NotNull DataType<T> default_(T defaultValue)
Specify an expression to be applied as theDEFAULTvalue for this data type.[#5709] A
defaultedcolumn cannot have anidentity().- See Also:
defaultValue(Field)
-
default_
@NotNull @Support @NotNull DataType<T> default_(Field<T> defaultValue)
Specify an expression to be applied as theDEFAULTvalue for this data type.A default value of a data type applies to DDL statements, such as
CREATE TABLEALTER TABLE
The distinct types of possible
DEFAULTexpressions is defined by the underlying database. Please refer to your database manual to learn what expressions are possible.
-
default_
@Nullable @Nullable Field<T> default_()
The expression to be applied as theDEFAULTvalue for this data type.- Returns:
- The default value if present, or
nullif no default value is specified for this data type. - See Also:
defaultValue(Field)
-
defaulted
@NotNull @Deprecated @NotNull DataType<T> defaulted(boolean defaulted)
Deprecated.- [#3852] - 3.8.0 - UsedefaultValue(Field)instead.Return a new data type like this, with a new defaultability.- Parameters:
defaulted- The new defaultability- Returns:
- The new data type
-
defaulted
boolean defaulted()
Get the defaultability of this data type.- Returns:
- The defaultability
-
precision
@NotNull @Support @NotNull DataType<T> precision(int precision)
Return a new data type like this, with a new precision value.This will have no effect if
hasPrecision()isfalseThis is the same as calling
precision(int, int)withscale == 0- Parameters:
precision- The new precision value- Returns:
- The new data type
-
precision
@NotNull @Support @NotNull DataType<T> precision(int precision, int scale)
Return a new data type like this, with a new precision and scale value.This will have no effect if
hasPrecision()isfalse, or ifscale > 0andhasScale()isfalse- Parameters:
precision- The new precision valuescale- The new scale value- Returns:
- The new data type
-
precision
int precision()
Get the precision of this data type.- Returns:
- The precision of this data type
-
hasPrecision
boolean hasPrecision()
Whether this data type has a precision.- Returns:
- Whether this data type has a precision
-
precisionDefined
boolean precisionDefined()
Whether the precision returned byprecision()is defined.The default precision is
0for all data types. If a data type does not have a precision (seehasPrecision()), or if it was initialised without precision (e.g.SQLDataType.TIMESTAMP), then the precision is not defined.
-
scale
@NotNull @Support @NotNull DataType<T> scale(int scale)
Return a new data type like this, with a new scale value.This will have no effect if
hasScale()isfalse- Parameters:
scale- The new scale value- Returns:
- The new data type
-
scale
int scale()
Get the scale of this data type.- Returns:
- The scale of this data type
-
hasScale
boolean hasScale()
Whether this data type has a scale.- Returns:
- Whether this data type has a scale
-
scaleDefined
boolean scaleDefined()
Whether the precision returned byscale()is defined.The default scale is
0for all data types. If a data type does not have a scale (seehasScale()), or if it was initialised without scale (e.g.SQLDataType.TIMESTAMP), then the scale is not defined.
-
length
@NotNull @Support @NotNull DataType<T> length(int length)
Return a new data type like this, with a new length value.This will have no effect if
hasLength()isfalse- Parameters:
length- The new length value- Returns:
- The new data type
-
length
int length()
Get the length of this data type.- Returns:
- The length of this data type
-
hasLength
boolean hasLength()
Whether this data type has a length.- Returns:
- Whether this data type has a length
-
lengthDefined
boolean lengthDefined()
Whether the precision returned bylength()is defined.The default length is
0for all data types. If a data type does not have a length (seehasLength()), or if it was initialised without length (e.g.SQLDataType.TIMESTAMP), then the length is not defined.
-
isNumeric
boolean isNumeric()
Whether this data type is any numeric data type.This applies to any of these types:
- See Also:
isNumeric()
-
isInteger
boolean isInteger()
Whether this data type is any integer data type.This applies to any of these types:
-
isString
boolean isString()
Whether this data type is any character data type.This applies to any of these types:
-
isNString
boolean isNString()
Whether this data type is any national character data type.This applies to any of these types:
-
isDateTime
boolean isDateTime()
Whether this data type is any date or time type.This applies to any of these types.
- See Also:
isDate()
-
isDate
boolean isDate()
Whether this data type is any date type.This applies to any of these types.
-
isTimestamp
boolean isTimestamp()
Whether this data type is any timestamp type.This applies to any of these types.
-
isTime
boolean isTime()
Whether this data type is any time type.This applies to any of these types.
-
isTemporal
boolean isTemporal()
Whether this data type is any date or time type.This applies to any of these types.
-
SQLDataType.DATE -
SQLDataType.TIME -
SQLDataType.TIMESTAMP -
SQLDataType.LOCALDATE -
SQLDataType.LOCALTIME -
SQLDataType.LOCALDATETIME -
SQLDataType.OFFSETTIME -
SQLDataType.OFFSETDATETIME -
YearToSecond -
YearToMonth -
DayToSecond
This is a combination of
isDateTime()orisInterval() -
-
isInterval
boolean isInterval()
Whether this data type is any interval type.This applies to any of these types.
-
isBinary
boolean isBinary()
Whether this data type is any binary type.This applies to any of these types.
-
isLob
boolean isLob()
Whether this data type is best deserialised as aLOB.This applies to any of these types.
-
isArray
boolean isArray()
Whether this data type is an array type.
-
isEmbeddable
boolean isEmbeddable()
Whether this data type is an embeddable type.
-
isUDT
boolean isUDT()
Whether this data type is a UDT type.
-
isEnum
boolean isEnum()
Whether this data type is an enum type.
-
isJSON
boolean isJSON()
Whether this data type is a JSON type.
-
isXML
boolean isXML()
Whether this data type is an XML type.
-
-