com.j256.ormlite.field.types
Class DateTimeType

java.lang.Object
  extended by com.j256.ormlite.field.BaseFieldConverter
      extended by com.j256.ormlite.field.types.BaseDataType
          extended by com.j256.ormlite.field.types.DateTimeType
All Implemented Interfaces:
DataPersister, FieldConverter

public class DateTimeType
extends BaseDataType

A custom persister that is able to store the org.joda.time.DateTime class in the database as epoch-millis long integer. This is done with reflection so we don't have to introduce the dependency.

NOTE: Because this class uses reflection, you have to specify this using DatabaseField.dataType(). It won't be detected automatically.

Author:
graywatson

Constructor Summary
protected DateTimeType(SqlType sqlType, Class<?>[] classes)
           
 
Method Summary
 String[] getAssociatedClassNames()
          Return the class names that should be associated with this or null.
 Class<?> getPrimaryClass()
          Return the class most associated with this persister or null if none.
static DateTimeType getSingleton()
           
 boolean isAppropriateId()
          Return true if this data type can be an id column in a class.
 boolean isEscapedValue()
          Return whether we need to escape this value in SQL expressions.
 Object javaToSqlArg(FieldType fieldType, Object javaObject)
          Convert a Java object and return the appropriate argument to a SQL insert or update statement.
 Object parseDefaultString(FieldType fieldType, String defaultStr)
          Convert a default string object and return the appropriate argument to a SQL insert or update statement.
 Object resultToSqlArg(FieldType fieldType, DatabaseResults results, int columnPos)
          Return the SQL argument 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 com.j256.ormlite.field.types.BaseDataType
convertIdNumber, dataIsEqual, generateId, getAssociatedClasses, getDefaultWidth, getSqlType, isArgumentHolderRequired, isComparable, isEscapedDefaultValue, isPrimitive, isSelfGeneratedId, isValidForField, isValidForVersion, isValidGeneratedType, makeConfigObject, moveToNextValue, resultStringToJava
 
Methods inherited from class com.j256.ormlite.field.BaseFieldConverter
isStreamType, resultToJava
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.j256.ormlite.field.FieldConverter
isStreamType, resultToJava
 

Constructor Detail

DateTimeType

protected DateTimeType(SqlType sqlType,
                       Class<?>[] classes)
Method Detail

getSingleton

public static DateTimeType getSingleton()

getAssociatedClassNames

public String[] getAssociatedClassNames()
Description copied from interface: DataPersister
Return the class names that should be associated with this or null. This is used by reflection classes so we can discover if a Field matches _without_ needed the class dependency in -core.

Specified by:
getAssociatedClassNames in interface DataPersister
Overrides:
getAssociatedClassNames in class BaseDataType

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
Overrides:
javaToSqlArg in class BaseFieldConverter
Throws:
SQLException - If there are problems with the conversion.

parseDefaultString

public Object parseDefaultString(FieldType fieldType,
                                 String defaultStr)
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
Specified by:
parseDefaultString in class BaseDataType

resultToSqlArg

public Object resultToSqlArg(FieldType fieldType,
                             DatabaseResults results,
                             int columnPos)
                      throws SQLException
Description copied from interface: FieldConverter
Return the SQL argument object extracted from the results associated with column in position columnPos. For example, if the type is a date-long then this will return a long value or null.

Specified by:
resultToSqlArg in interface FieldConverter
Specified by:
resultToSqlArg in class BaseDataType
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. This takes the database representation and converts it into a Java object. For example, if the type is a date-long then this will take a long which is stored in the database and return a Date.

Specified by:
sqlArgToJava in interface FieldConverter
Overrides:
sqlArgToJava in class BaseFieldConverter
Parameters:
fieldType - Associated FieldType which may be null.
sqlArg - SQL argument converted with FieldConverter.resultToSqlArg(FieldType, DatabaseResults, int) which will not be null.
Throws:
SQLException - If there are problems with the conversion.

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
Overrides:
isEscapedValue in class BaseDataType

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
Overrides:
isAppropriateId in class BaseDataType

getPrimaryClass

public Class<?> getPrimaryClass()
Description copied from interface: DataPersister
Return the class most associated with this persister or null if none.

Specified by:
getPrimaryClass in interface DataPersister
Overrides:
getPrimaryClass in class BaseDataType


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