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,I18NTextType,StringType,UUIDType
Implements some common methods for data types.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic intMaximum number of lines in literal.
> 0 if unlimited. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidChecks that this type has a fixed number of columns or the backend is specified.createColumnNames(Backend backend, String columnName) Creates a list of column names.createColumnNamesAsString(Backend backend, String columnName, String separator) Creates a list of column names as a concatenated string.
The string can be used in SQL INSERT and UPDATE statements.booleangetColumnAlias(int index) Gets the alias name of a column.intgetColumnCount(Backend backend) Gets 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, String varName) Returns the java code to get the value of a column.getColumnSuffix(Backend backend, int index) Predefined DataTypes must not override this method!
SeeResultSetWrapper#COL2_SUFFIX.getColumnValue(Backend backend, int index, T value) Gets the value of a column.getCommentSuffix(Backend backend, int index) Gets the optional comment suffix.
If present, it will be appended to the comment.Gets the name of the datatype constant.getMappedNullValue(Backend backend, int index) Gets the mapped non-null value that represents the model's null value.
The method throws aBackendException, if !DataType.isMapNullSupported().intGets the column scale.
The scale may be differently aligned according to the backend.intGets the column size.
Sizes may be differently aligned according to the backend.int[]Gets the indexes to the sortable columns.
The number and order of the indexes is reflected in the generated order-by SQL clause.Gets the optional variant of the type.inthashCode()booleanisBool()Returns whether this is a boolean or Boolean type.booleanReturns whether the number of columns is backend-specific.
For such types the following restrictions apply: noCN_...will be generated for the individual columns, just the column basename they cannot be used as wurblet arguments (to generate the WHERE-clause) the application cannot refer to a column in a backend-agnostic waybooleanReturns whether this is a date and/or time type.booleanFor certain numeric types, a downcast is necessary when assigning literals.booleanReturns whether the inner type describes a generified java type.
ImpliesDataType.isModelProvidingInnerType().booleanisLiteralSupported(Integer index) Returns 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 aCalendar-timezone can be applied to this date and/or time related type.
Only for types where methods with Calendar argument are provided in ResultSet and PreparedStatement.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).valueOfLiteralToCode(String str, Integer index) Creates the java code to apply the valueOf method to a String.protected StringvalueStringToCode(String str) Transforms the value string of an object to java code.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
-
Field Details
-
maxLinesInLiteral
public static int maxLinesInLiteralMaximum number of lines in literal.
> 0 if unlimited.
-
-
Constructor Details
-
AbstractDataType
public AbstractDataType()Parent constructor.
-
-
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
-
isColumnCountBackendSpecific
public boolean isColumnCountBackendSpecific()Description copied from interface:DataTypeReturns whether the number of columns is backend-specific.
For such types the following restrictions apply:- no
CN_...will be generated for the individual columns, just the column basename - they cannot be used as wurblet arguments (to generate the WHERE-clause)
- the application cannot refer to a column in a backend-agnostic way
- Specified by:
isColumnCountBackendSpecificin interfaceDataType<T>- Returns:
- false if not backend-specific (default), true if varying
- no
-
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>- Parameters:
backend- the backend, ignored if !DataType.isColumnCountBackendSpecific()- Returns:
- default is 1
-
getSortableColumns
public int[] getSortableColumns()Description copied from interface:DataTypeGets the indexes to the sortable columns.
The number and order of the indexes is reflected in the generated order-by SQL clause.- Specified by:
getSortableColumnsin interfaceDataType<T>- Returns:
- the column indexes, null or empty if datatype is not sortable in a meaningful manner by the database
-
getColumnSuffix
Predefined DataTypes must not override this method!
SeeResultSetWrapper#COL2_SUFFIX.Gets the optional suffix.
Suffixes usually begin with an underscore.- Specified by:
getColumnSuffixin interfaceDataType<T>- Parameters:
backend- the backend, ignored if !DataType.isColumnCountBackendSpecific()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:
backend- the backend, ignored if !DataType.isColumnCountBackendSpecific()index- the column index- Returns:
- the optional suffix
-
createColumnNames
Description copied from interface:DataTypeCreates a list of column names.- Specified by:
createColumnNamesin interfaceDataType<T>- Parameters:
backend- the backend, ignored if !DataType.isColumnCountBackendSpecific()columnName- the column basename- Returns:
- the names as an unmodifiable list
-
createColumnNamesAsString
Description copied from interface:DataTypeCreates a list of column names as a concatenated string.
The string can be used in SQL INSERT and UPDATE statements.- Specified by:
createColumnNamesAsStringin interfaceDataType<T>- Parameters:
backend- the backend, ignored if !DataType.isColumnCountBackendSpecific()columnName- the column basenameseparator- the separator string between names- Returns:
- the names list
-
getSize
Description copied from interface:DataTypeGets the column size.
Sizes may be differently aligned according to the backend. -
getScale
Description copied from interface:DataTypeGets the column scale.
The scale may be differently aligned according to the backend. -
getColumnValue
Description copied from interface:DataTypeGets the value of a column.- Specified by:
getColumnValuein interfaceDataType<T>- Parameters:
backend- the backend, ignored if !DataType.isColumnCountBackendSpecific()index- the column indexvalue- the datatype's value according to the model- Returns:
- the column's value
-
getColumnGetter
Description copied from interface:DataTypeReturns the java code to get the value of a column.- Specified by:
getColumnGetterin interfaceDataType<T>- Parameters:
index- the column indexvarName- the java variable name- Returns:
- the java code, empty string if this is a single column type
-
getColumnAlias
Description copied from interface:DataTypeGets the alias name of a column.- Specified by:
getColumnAliasin interfaceDataType<T>- Parameters:
index- the column index- Returns:
- the column's alias
-
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
-
isTimezoneApplicable
public boolean isTimezoneApplicable()Description copied from interface:DataTypeReturns whether aCalendar-timezone can be applied to this date and/or time related type.
Only for types where methods with Calendar argument are provided in ResultSet and PreparedStatement.- Specified by:
isTimezoneApplicablein interfaceDataType<T>- Returns:
- true if methods exist with timezone correction
-
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
-
getMappedNullValue
Description copied from interface:DataTypeGets the mapped non-null value that represents the model's null value.
The method throws aBackendException, if !DataType.isMapNullSupported().- Specified by:
getMappedNullValuein interfaceDataType<T>- Parameters:
backend- the backend, null if not backend-specificindex- the column index- Returns:
- the non-null mapped value
-
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, a downcast is necessary when assigning literals.- Specified by:
isDowncastNecessaryin interfaceDataType<T>- Returns:
- true if downcast is necessary
-
isLiteralSupported
Description copied from interface:DataTypeReturns whether this type can be used literally in a query String.- Specified by:
isLiteralSupportedin interfaceDataType<T>- Parameters:
index- the column index, null if applies to object of this type- 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 parsedindex- the column index, null if applies to object of this type- 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() -
assertColumnCountNotBackendSpecific
Checks that this type has a fixed number of columns or the backend is specified. -
valueStringToCode
Transforms the value string of an object to java code.- Parameters:
str- the value string- Returns:
- the java code
-