com.j256.ormlite.field.types
Class BaseDataType

java.lang.Object
  extended by com.j256.ormlite.field.types.BaseDataType
All Implemented Interfaces:
DataPersister, FieldConverter
Direct Known Subclasses:
BaseDateType, BaseEnumType, BigDecimalType, BigIntegerType, BooleanObjectType, ByteArrayType, ByteObjectType, CharacterObjectType, DoubleObjectType, FloatObjectType, IntegerObjectType, LongObjectType, SerializableType, ShortObjectType, StringBytesType, StringType, UuidType, VoidType

public abstract class BaseDataType
extends Object
implements DataPersister

Base data type that defines the defaults the various data types.

Here's a good page about the mapping for a number of database types:

Author:
graywatson

Constructor Summary
BaseDataType(SqlType sqlType, Class<?>[] classes)
           
 
Method Summary
 Object convertIdNumber(Number number)
          Convert a Number object to its primitive object suitable for assigning to an ID field.
 boolean dataIsEqual(Object fieldObj1, Object fieldObj2)
          Compare two fields of this type returning true if equals else false.
 Object generateId()
          Return a generated id if appropriate or null if none.
 Class<?>[] getAssociatedClasses()
          Return the classes that should be associated with this.
 int getDefaultWidth()
          Return the default width associated with this type or 0 if none.
 SqlType getSqlType()
          Return the SQL type that is stored in the database for this argument.
 boolean isAppropriateId()
          Return true if this data type can be an id column in a class.
 boolean isComparable()
          Return true if this data type be compared in SQL statements.
 boolean isEscapedDefaultValue()
          Return whether this field's default value should be escaped in SQL.
 boolean isEscapedValue()
          Return whether we need to escape this value in SQL expressions.
 boolean isPrimitive()
          Return whether this field is a primitive type or not.
 boolean isSelectArgRequired()
          Must use SelectArg when querying for values of this type.
 boolean isSelfGeneratedId()
          Return true if this type creates its own generated ids else false to have the database do it.
 boolean isStreamType()
          Return whether or not this is a SQL "stream" object.
abstract  boolean isValidForField(Field field)
          Return true if the field is appropriate for this persister.
 boolean isValidForVersion()
          Return true if this is a valid field for the DatabaseField.version().
 boolean isValidGeneratedType()
          Return true if this type can be auto-generated by the database.
 Object javaToSqlArg(FieldType fieldType, Object javaObject)
          Convert a Java object and return the appropriate argument to a SQL insert or update statement.
 Object makeConfigObject(FieldType fieldType)
          This makes a configuration object for the data-type or returns null if none.
 Object moveToNextValue(Object currentValue)
          Move the current-value to the next value.
abstract  Object parseDefaultString(FieldType fieldType, String defaultStr)
          Convert a default string object and return the appropriate argument to a SQL insert or update statement.
abstract  Object resultToJava(FieldType fieldType, DatabaseResults results, int columnPos)
          Return the object extracted from the results associated with column in position columnPos.
 Object sqlArgToJava(FieldType fieldType, Object sqlArg, int columnPos)
          Return the object converted from the SQL arg to java.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BaseDataType

public BaseDataType(SqlType sqlType,
                    Class<?>[] classes)
Method Detail

parseDefaultString

public abstract Object parseDefaultString(FieldType fieldType,
                                          String defaultStr)
                                   throws SQLException
Description copied from interface: FieldConverter
Convert a default string object and return the appropriate argument to a SQL insert or update statement.

Specified by:
parseDefaultString in interface FieldConverter
Throws:
SQLException

resultToJava

public abstract Object resultToJava(FieldType fieldType,
                                    DatabaseResults results,
                                    int columnPos)
                             throws SQLException
Description copied from interface: FieldConverter
Return the object extracted from the results associated with column in position columnPos.

Specified by:
resultToJava in interface FieldConverter
Parameters:
fieldType - Associated FieldType which may be null.
Throws:
SQLException - If there is a problem accessing the results data.

sqlArgToJava

public Object sqlArgToJava(FieldType fieldType,
                           Object sqlArg,
                           int columnPos)
                    throws SQLException
Description copied from interface: FieldConverter
Return the object converted from the SQL arg to java.

Specified by:
sqlArgToJava in interface FieldConverter
Parameters:
fieldType - Associated FieldType which may be null.
Throws:
SQLException

javaToSqlArg

public Object javaToSqlArg(FieldType fieldType,
                           Object javaObject)
                    throws SQLException
Description copied from interface: FieldConverter
Convert a Java object and return the appropriate argument to a SQL insert or update statement.

Specified by:
javaToSqlArg in interface FieldConverter
Throws:
SQLException

isValidForField

public abstract boolean isValidForField(Field field)
Description copied from interface: DataPersister
Return true if the field is appropriate for this persister.

Specified by:
isValidForField in interface DataPersister

makeConfigObject

public Object makeConfigObject(FieldType fieldType)
                        throws SQLException
Description copied from interface: DataPersister
This makes a configuration object for the data-type or returns null if none. The object can be accessed later via FieldType.getDataTypeConfigObj().

Specified by:
makeConfigObject in interface DataPersister
Throws:
SQLException

getSqlType

public SqlType getSqlType()
Description copied from interface: FieldConverter
Return the SQL type that is stored in the database for this argument.

Specified by:
getSqlType in interface FieldConverter

getAssociatedClasses

public Class<?>[] getAssociatedClasses()
Description copied from interface: DataPersister
Return the classes that should be associated with this.

Specified by:
getAssociatedClasses in interface DataPersister

isStreamType

public boolean isStreamType()
Description copied from interface: FieldConverter
Return whether or not this is a SQL "stream" object. Cannot get certain stream objects from the SQL results more than once. If true, the converter has to protect itself against null values.

Specified by:
isStreamType in interface FieldConverter

convertIdNumber

public Object convertIdNumber(Number number)
Description copied from interface: DataPersister
Convert a Number object to its primitive object suitable for assigning to an ID field.

Specified by:
convertIdNumber in interface DataPersister

isValidGeneratedType

public boolean isValidGeneratedType()
Description copied from interface: DataPersister
Return true if this type can be auto-generated by the database. Probably only numbers will return true.

Specified by:
isValidGeneratedType in interface DataPersister

isEscapedDefaultValue

public boolean isEscapedDefaultValue()
Description copied from interface: DataPersister
Return whether this field's default value should be escaped in SQL.

Specified by:
isEscapedDefaultValue in interface DataPersister

isEscapedValue

public boolean isEscapedValue()
Description copied from interface: DataPersister
Return whether we need to escape this value in SQL expressions. Numbers _must_ not be escaped but most other values should be.

Specified by:
isEscapedValue in interface DataPersister

isPrimitive

public boolean isPrimitive()
Description copied from interface: DataPersister
Return whether this field is a primitive type or not. This is used to know if we should throw if the field value is null.

Specified by:
isPrimitive in interface DataPersister

isComparable

public boolean isComparable()
Description copied from interface: DataPersister
Return true if this data type be compared in SQL statements.

Specified by:
isComparable in interface DataPersister

isAppropriateId

public boolean isAppropriateId()
Description copied from interface: DataPersister
Return true if this data type can be an id column in a class.

Specified by:
isAppropriateId in interface DataPersister

isSelectArgRequired

public boolean isSelectArgRequired()
Description copied from interface: DataPersister
Must use SelectArg when querying for values of this type.

Specified by:
isSelectArgRequired in interface DataPersister

isSelfGeneratedId

public boolean isSelfGeneratedId()
Description copied from interface: DataPersister
Return true if this type creates its own generated ids else false to have the database do it.

Specified by:
isSelfGeneratedId in interface DataPersister

generateId

public Object generateId()
Description copied from interface: DataPersister
Return a generated id if appropriate or null if none.

Specified by:
generateId in interface DataPersister

getDefaultWidth

public int getDefaultWidth()
Description copied from interface: DataPersister
Return the default width associated with this type or 0 if none.

Specified by:
getDefaultWidth in interface DataPersister

dataIsEqual

public boolean dataIsEqual(Object fieldObj1,
                           Object fieldObj2)
Description copied from interface: DataPersister
Compare two fields of this type returning true if equals else false.

Specified by:
dataIsEqual in interface DataPersister

isValidForVersion

public boolean isValidForVersion()
Description copied from interface: DataPersister
Return true if this is a valid field for the DatabaseField.version().

Specified by:
isValidForVersion in interface DataPersister

moveToNextValue

public Object moveToNextValue(Object currentValue)
Description copied from interface: DataPersister
Move the current-value to the next value. Used for the version field.

Specified by:
moveToNextValue in interface DataPersister


This content is licensed by Gray Watson under the Creative Commons Attribution-Share Alike 3.0 License.