java.lang.Object
org.tentackle.sql.datatypes.AbstractDataType<T>
- All Implemented Interfaces:
DataType<T>
- Direct Known Subclasses:
AbstractDateTimeType,AbstractNumberType,BinaryType,BMoneyType,BooleanType,CharacterType,ConvertibleType,DMoneyType,StringType
Implements some common methods for datatypes.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanintGets the number of database columns.
A tentackle type may be mapped to more than one column for multi-column types such asBMoney.getColumnGetter(int index) Gets the java getter name of a column.getColumnSuffix(int index) Gets the optional suffix.
Suffixes usually begin with an underscore.getColumnValue(int index, T value) Gets the value of a column.getCommentSuffix(int index) Gets the optional comment suffix.
If present, it will be appended to the comment.Gets the name of the datatype constant.intGets the column scale.intGets the column size.Gets the optional variant of the type.inthashCode()booleanisBool()Returns whether this is a boolean or Boolean type.booleanReturns whether this is a date and/or time type.booleanFor certain numeric types, downcasts are necessary when assigning literals.booleanReturns whether the inner type describes a generified java type.
ImpliesDataType.isModelProvidingInnerType().booleanReturns whether this type can be used literally in a query String.booleanReturns whether this type supports mapping null values to some well-defined constant.booleanReturns whether the model provides an inner type.booleanReturns whether type is a mutable java object.
Mutable objects may change their state and must implementFreezable.booleanReturns whether this is a numeric type.booleanReturns whether this is a predefined type.booleanReturns whether type is a primitive.booleanReturns whether this type supports the UTC option.set(Backend backend, PreparedStatement statement, int pos, T object, int index, boolean mapNull, Integer size) Sets a column of an object into a prepared statement.
Must be implemented ifDataType.isPredefined()returns false.Takes the string representation of a value and converts it to an SQL literal.
Some types need single quotes, for example.DataType<?>Gets the non-primitive type if this is a primitive.Gets the primitive type if this is a non-primitive.toString()Takes an object and converts it to a string that can in turn be parsed withDataType.valueOf(String).
The method is used to print a literal (for example the default value of a dumped attribute).Creates the java code to apply the valueOf method to a String.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.tentackle.sql.DataType
get, getJavaType, getSqlType, set, valueOf
-
Constructor Details
-
AbstractDataType
public AbstractDataType()
-
-
Method Details
-
isPredefined
public boolean isPredefined()Description copied from interface:DataTypeReturns whether this is a predefined type.- Specified by:
isPredefinedin interfaceDataType<T>- Returns:
- true if explicit methods provided by the persistence layer, false if generic methods must be used
-
getVariant
Description copied from interface:DataTypeGets the optional variant of the type.- Specified by:
getVariantin interfaceDataType<T>- Returns:
- the variant, empty string if none, never null
-
getColumnCount
public int getColumnCount()Description copied from interface:DataTypeGets the number of database columns.
A tentackle type may be mapped to more than one column for multi-column types such asBMoney.- Specified by:
getColumnCountin interfaceDataType<T>- Returns:
- default is 1
-
getColumnSuffix
Description copied from interface:DataTypeGets the optional suffix.
Suffixes usually begin with an underscore.- Specified by:
getColumnSuffixin interfaceDataType<T>- Parameters:
index- the column index- Returns:
- the optional suffix
-
getCommentSuffix
Description copied from interface:DataTypeGets the optional comment suffix.
If present, it will be appended to the comment.Important: for datatypes with more than one column, none or exactly one should be without suffix. See WurbletArgument in tentackle-wurblets.
- Specified by:
getCommentSuffixin interfaceDataType<T>- Parameters:
index- the column index- Returns:
- the optional suffix
-
getSize
Description copied from interface:DataTypeGets the column size. -
getScale
Description copied from interface:DataTypeGets the column scale. -
getColumnValue
Description copied from interface:DataTypeGets the value of a column.- Specified by:
getColumnValuein interfaceDataType<T>- Parameters:
index- the column indexvalue- the datatype's value according to the model- Returns:
- the column's value
-
getColumnGetter
Description copied from interface:DataTypeGets the java getter name of a column.- Specified by:
getColumnGetterin interfaceDataType<T>- Parameters:
index- the datatype's value according to the model- Returns:
- the column's getter name, empty string if this is a single column type
-
isPrimitive
public boolean isPrimitive()Description copied from interface:DataTypeReturns whether type is a primitive.- Specified by:
isPrimitivein interfaceDataType<T>- Returns:
- true if primitive
-
toNonPrimitive
Description copied from interface:DataTypeGets the non-primitive type if this is a primitive.- Specified by:
toNonPrimitivein interfaceDataType<T>- Returns:
- the non-primitive type, this type if it is already a non-primitive
-
toPrimitive
Description copied from interface:DataTypeGets the primitive type if this is a non-primitive.- Specified by:
toPrimitivein interfaceDataType<T>- Returns:
- the primitive type if there is one
-
isMutable
public boolean isMutable()Description copied from interface:DataTypeReturns whether type is a mutable java object.
Mutable objects may change their state and must implementFreezable. -
isNumeric
public boolean isNumeric()Description copied from interface:DataTypeReturns whether this is a numeric type. -
isDateOrTime
public boolean isDateOrTime()Description copied from interface:DataTypeReturns whether this is a date and/or time type.- Specified by:
isDateOrTimein interfaceDataType<T>- Returns:
- true if time, date or timestamp
-
isBool
public boolean isBool()Description copied from interface:DataTypeReturns whether this is a boolean or Boolean type. -
isMapNullSupported
public boolean isMapNullSupported()Description copied from interface:DataTypeReturns whether this type supports mapping null values to some well-defined constant.- Specified by:
isMapNullSupportedin interfaceDataType<T>- Returns:
- true if mapNull supported
-
isUTCSupported
public boolean isUTCSupported()Description copied from interface:DataTypeReturns whether this type supports the UTC option.- Specified by:
isUTCSupportedin interfaceDataType<T>- Returns:
- true if UTC supported
-
isModelProvidingInnerType
public boolean isModelProvidingInnerType()Description copied from interface:DataTypeReturns whether the model provides an inner type.- Specified by:
isModelProvidingInnerTypein interfaceDataType<T>- Returns:
- true if inner type is specified within angle brackets, false if standard type
-
isJavaTypeGenerified
public boolean isJavaTypeGenerified()Description copied from interface:DataTypeReturns whether the inner type describes a generified java type.
ImpliesDataType.isModelProvidingInnerType().- Specified by:
isJavaTypeGenerifiedin interfaceDataType<T>- Returns:
- true if javaType<T>, else simple type
-
isDowncastNecessary
public boolean isDowncastNecessary()Description copied from interface:DataTypeFor certain numeric types, downcasts are necessary when assigning literals.- Specified by:
isDowncastNecessaryin interfaceDataType<T>- Returns:
- true if downcast is necessary
-
isLiteralSupported
public boolean isLiteralSupported()Description copied from interface:DataTypeReturns whether this type can be used literally in a query String.- Specified by:
isLiteralSupportedin interfaceDataType<T>- Returns:
- true if literal String supported, else false
-
toLiteral
Description copied from interface:DataTypeTakes the string representation of a value and converts it to an SQL literal.
Some types need single quotes, for example. -
valueOfLiteralToCode
Description copied from interface:DataTypeCreates the java code to apply the valueOf method to a String.- Specified by:
valueOfLiteralToCodein interfaceDataType<T>- Parameters:
str- the literal to be parsed- Returns:
- the java code
-
toString
Description copied from interface:DataTypeTakes an object and converts it to a string that can in turn be parsed withDataType.valueOf(String).
The method is used to print a literal (for example the default value of a dumped attribute).Notice: the method doesn't use any locale, so the results are always the same regardless of the JVM's locale.
-
toString
-
getDataTypeConstant
Description copied from interface:DataTypeGets the name of the datatype constant.- Specified by:
getDataTypeConstantin interfaceDataType<T>- Returns:
- the DT_...
-
set
public Object set(Backend backend, PreparedStatement statement, int pos, T object, int index, boolean mapNull, Integer size) throws SQLException Description copied from interface:DataTypeSets a column of an object into a prepared statement.
Must be implemented ifDataType.isPredefined()returns false. Not invoked by framework otherwise.- Specified by:
setin interfaceDataType<T>- Parameters:
backend- the database backendstatement- the prepared statementpos- the position of the first SQL valueobject- the object, may be nullindex- the column indexmapNull- true if map null-values to non-null valuessize- the optional size specified in the model- Returns:
- the object stored in the prepared statement
- Throws:
SQLException- if failed
-
equals
-
hashCode
public int hashCode()
-