com.j256.ormlite.field
Enum DataType

java.lang.Object
  extended by java.lang.Enum<DataType>
      extended by com.j256.ormlite.field.DataType
All Implemented Interfaces:
FieldConverter, Serializable, Comparable<DataType>

public enum DataType
extends Enum<DataType>
implements FieldConverter

Data type enumeration to provide Java class to/from database mapping.

NOTE: If you add types here you will need to add to the various DatabaseType implementors' appendColumnArg() method.

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

Author:
graywatson

Enum Constant Summary
BOOLEAN
          Persists the boolean Java primitive.
BOOLEAN_OBJ
          Persists the Boolean Java class.
BYTE
          Persists the byte primitive.
BYTE_ARRAY
          Persists the byte[] array type.
BYTE_OBJ
          Persists the Byte Java class.
CHAR
          Persists the char primitive.
CHAR_OBJ
          Persists the char primitive.
DATE
          Persists the Date Java class.
DATE_LONG
          Persists the Date Java class as long milliseconds since epoch.
DATE_STRING
          Persists the Date Java class as a string of a format.
DOUBLE
          Persists the double primitive.
DOUBLE_OBJ
          Persists the Double Java class.
ENUM_INTEGER
          Persists an Enum Java class as its ordinal interger value.
ENUM_STRING
          Persists an Enum Java class as its string value.
FLOAT
          Persists the float primitive.
FLOAT_OBJ
          Persists the Float Java class.
INTEGER
          Persists the int primitive.
INTEGER_OBJ
          Persists the Integer Java class.
JAVA_DATE
          Deprecated. You should use DATE
JAVA_DATE_LONG
          Deprecated. You should use DATE_LONG
JAVA_DATE_STRING
          Deprecated. You should use DATE_STRING
LONG
          Persists the long primitive.
LONG_OBJ
          Persists the Long Java class.
LONG_STRING
          Persists the String Java class.
SERIALIZABLE
          Persists an unknown Java Object that is serializable.
SHORT
          Persists the short primitive.
SHORT_OBJ
          Persists the Short Java class.
STRING
          Persists the String Java class.
STRING_BYTES
          Persists the String Java class.
UNKNOWN
          Marker for fields that are unknown.
UUID
          Persists the UUID Java class.
 
Field Summary
static com.j256.ormlite.field.DataType.DateStringFormatConfig defaultDateFormatConfig
           
 
Method Summary
 Object generatedId()
          Return a generated id if appropriate or null if none.
 SqlType getSqlType()
          Return the SQL type that is stored in the database for this argument.
 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.
 Object javaToSqlArg(FieldType fieldType, Object javaObject)
          Convert a Java object and return the appropriate argument to a SQL insert or update statement.
static DataType lookupClass(Class<?> dataClass)
          Static method that returns the DataType associated with the class argument or UNKNOWN if not found.
 Object makeConfigObject(FieldType fieldType)
          This makes a configuration object for the data-type or returns null if none.
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.
static DataType valueOf(String name)
          Returns the enum constant of this type with the specified name.
static DataType[] values()
          Returns an array containing the constants of this enum type, in the order they are declared.
 
Methods inherited from class java.lang.Enum
clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Enum Constant Detail

STRING

public static final DataType STRING
Persists the String Java class.


LONG_STRING

public static final DataType LONG_STRING
Persists the String Java class.


STRING_BYTES

public static final DataType STRING_BYTES
Persists the String Java class.


BOOLEAN

public static final DataType BOOLEAN
Persists the boolean Java primitive.


BOOLEAN_OBJ

public static final DataType BOOLEAN_OBJ
Persists the Boolean Java class.


DATE

public static final DataType DATE
Persists the Date Java class.

NOTE: This is not the same as the Date class.


JAVA_DATE

@Deprecated
public static final DataType JAVA_DATE
Deprecated. You should use DATE

DATE_LONG

public static final DataType DATE_LONG
Persists the Date Java class as long milliseconds since epoch.

NOTE: This is not the same as the Date class.


JAVA_DATE_LONG

@Deprecated
public static final DataType JAVA_DATE_LONG
Deprecated. You should use DATE_LONG

DATE_STRING

public static final DataType DATE_STRING
Persists the Date Java class as a string of a format.

NOTE: This is not the same as the Date class.

WARNING: Because of SimpleDateFormat not being reentrant, this has to do some synchronization with every data in/out unfortunately.


JAVA_DATE_STRING

@Deprecated
public static final DataType JAVA_DATE_STRING
Deprecated. You should use DATE_STRING

CHAR

public static final DataType CHAR
Persists the char primitive.


CHAR_OBJ

public static final DataType CHAR_OBJ
Persists the char primitive.


BYTE

public static final DataType BYTE
Persists the byte primitive.


BYTE_ARRAY

public static final DataType BYTE_ARRAY
Persists the byte[] array type.


BYTE_OBJ

public static final DataType BYTE_OBJ
Persists the Byte Java class.


SHORT

public static final DataType SHORT
Persists the short primitive.


SHORT_OBJ

public static final DataType SHORT_OBJ
Persists the Short Java class.


INTEGER

public static final DataType INTEGER
Persists the int primitive.


INTEGER_OBJ

public static final DataType INTEGER_OBJ
Persists the Integer Java class.


LONG

public static final DataType LONG
Persists the long primitive.


LONG_OBJ

public static final DataType LONG_OBJ
Persists the Long Java class.


FLOAT

public static final DataType FLOAT
Persists the float primitive.


FLOAT_OBJ

public static final DataType FLOAT_OBJ
Persists the Float Java class.


DOUBLE

public static final DataType DOUBLE
Persists the double primitive.


DOUBLE_OBJ

public static final DataType DOUBLE_OBJ
Persists the Double Java class.


SERIALIZABLE

public static final DataType SERIALIZABLE
Persists an unknown Java Object that is serializable.


ENUM_STRING

public static final DataType ENUM_STRING
Persists an Enum Java class as its string value. You can also specify the ENUM_INTEGER as the type.


ENUM_INTEGER

public static final DataType ENUM_INTEGER
Persists an Enum Java class as its ordinal interger value. You can also specify the ENUM_STRING as the type.


UUID

public static final DataType UUID
Persists the UUID Java class.


UNKNOWN

public static final DataType UNKNOWN
Marker for fields that are unknown.

Field Detail

defaultDateFormatConfig

public static final com.j256.ormlite.field.DataType.DateStringFormatConfig defaultDateFormatConfig
Method Detail

values

public static DataType[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
for (DataType c : DataType.values())
    System.out.println(c);

Returns:
an array containing the constants of this enum type, in the order they are declared

valueOf

public static DataType valueOf(String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)

Parameters:
name - the name of the enum constant to be returned.
Returns:
the enum constant with the specified name
Throws:
IllegalArgumentException - if this enum type has no constant with the specified name
NullPointerException - if the argument is null

lookupClass

public static DataType lookupClass(Class<?> dataClass)
                            throws SQLException
Static method that returns the DataType associated with the class argument or UNKNOWN if not found.

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.

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

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

makeConfigObject

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

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

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

isSelfGeneratedId

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


generatedId

public Object generatedId()
Return a generated id if appropriate or null if none.



Copyright © 2011. All Rights Reserved.