- 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
public abstract class AbstractDataType<T> extends java.lang.Object implements DataType<T>
Implements some common methods for datatypes.
-
-
Constructor Summary
Constructors Constructor Description AbstractDataType()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(java.lang.Object o)intgetColumnCount()Gets the number of database columns.
A tentackle type may be mapped to more than one column for multi-column types such asBMoney.java.lang.StringgetColumnGetter(int index)Gets the java getter name of a column.java.util.Optional<java.lang.String>getColumnSuffix(int index)Gets the optional suffix.
Suffixes usually begin with an underscore.java.lang.ObjectgetColumnValue(int index, T value)Gets the value of a column.java.util.Optional<java.lang.String>getCommentSuffix(int index)Gets the optional comment suffix.
If present, it will be appended to the comment.java.lang.StringgetDataTypeConstant()Gets the name of the datatype constant.intgetScale(int index, java.lang.Integer scale)Gets the column scale.intgetSize(int index, java.lang.Integer size)Gets the column size.java.lang.StringgetVariant()Gets the optional variant of the type.inthashCode()booleanisBool()Returns whether this is a boolean or Boolean type.booleanisDateOrTime()Returns whether this is a date and/or time type.booleanisDowncastNecessary()For certain numeric types, downcasts are necessary when assigning literals.booleanisJavaTypeGenerified()Returns whether the inner type describes a generified java type.
ImpliesDataType.isModelProvidingInnerType().booleanisLiteralSupported()Returns whether this type can be used literally in a query String.booleanisMapNullSupported()Returns whether this type supports mapping null values to some well-defined constant.booleanisModelProvidingInnerType()Returns whether the model provides an inner type.booleanisMutable()Returns whether type is a mutable java object.
Mutable objects may change their state and must implementFreezable.booleanisNumeric()Returns whether this is a numeric type.booleanisPredefined()Returns whether this is a predefined type.booleanisPrimitive()Returns whether type is a primitive.booleanisUTCSupported()Returns whether this type supports the UTC option.java.lang.Objectset(Backend backend, java.sql.PreparedStatement statement, int pos, T object, int index, boolean mapNull, java.lang.Integer size)Sets a column of an object into a prepared statement.
Must be implemented ifDataType.isPredefined()returns false.java.lang.StringtoLiteral(java.lang.String str)Takes the string representation of a value and converts it to an SQL literal.
Some types need single quotes, for example.DataType<?>toNonPrimitive()Gets the non-primitive type if this is a primitive.java.util.Optional<DataType<?>>toPrimitive()Gets the primitive type if this is a non-primitive.java.lang.StringtoString()java.lang.StringtoString(T object)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).java.lang.StringvalueOfLiteralToCode(java.lang.String str)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, wait
-
Methods inherited from interface org.tentackle.sql.DataType
get, getJavaType, getSqlType, set, valueOf
-
-
-
-
Method Detail
-
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
public java.lang.String 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
public java.util.Optional<java.lang.String> getColumnSuffix(int index)
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
public java.util.Optional<java.lang.String> getCommentSuffix(int index)
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
public int getSize(int index, java.lang.Integer size)Description copied from interface:DataTypeGets the column size.
-
getScale
public int getScale(int index, java.lang.Integer scale)Description copied from interface:DataTypeGets the column scale.
-
getColumnValue
public java.lang.Object getColumnValue(int index, T value)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
public java.lang.String getColumnGetter(int index)
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
public DataType<?> 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
public java.util.Optional<DataType<?>> 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
public java.lang.String toLiteral(java.lang.String str)
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
public java.lang.String valueOfLiteralToCode(java.lang.String str)
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
public java.lang.String toString(T object)
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
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
getDataTypeConstant
public java.lang.String getDataTypeConstant()
Description copied from interface:DataTypeGets the name of the datatype constant.- Specified by:
getDataTypeConstantin interfaceDataType<T>- Returns:
- the DT_...
-
set
public java.lang.Object set(Backend backend, java.sql.PreparedStatement statement, int pos, T object, int index, boolean mapNull, java.lang.Integer size) throws java.sql.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:
java.sql.SQLException- if failed
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
-