com.j256.ormlite.field
Enum JdbcType

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

public enum JdbcType
extends Enum<JdbcType>
implements FieldConverter

JDBC type enumeration to provide Java class to/from JDBC 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
          Links the Types.BOOLEAN SQL type and the boolean primitive.
BOOLEAN_OBJ
          Links the Types.BOOLEAN SQL type and the Boolean Java class.
BYTE
          Links the Types.TINYINT SQL type and the byte primitive.
BYTE_OBJ
          Links the Types.TINYINT SQL type and the Byte Java class.
DOUBLE
          Links the Types.DOUBLE SQL type and the double primitive.
DOUBLE_OBJ
          Links the Types.DOUBLE SQL type and the Double Java class.
ENUM_INTEGER
          Links the Types.INTEGER SQL type and the Enum Java class.
ENUM_STRING
          Links the Types.VARCHAR SQL type and the Enum Java class.
FLOAT
          Links the Types.FLOAT SQL type and the float primitive.
FLOAT_OBJ
          Links the Types.FLOAT SQL type and the Float Java class.
INTEGER
          Links the Types.INTEGER SQL type and the int primitive.
INTEGER_OBJ
          Links the Types.INTEGER SQL type and the Integer Java class.
JAVA_DATE
          Links the Types.TIMESTAMP SQL type and the Date Java class.
LONG
          Links the Types.BIGINT SQL type and the long primitive.
LONG_OBJ
          Links the Types.BIGINT SQL type and the Long Java class.
SERIALIZABLE
          Links the Types.VARBINARY SQL type and an unknown Java Object that is serializable.
SHORT
          Links the Types.SMALLINT SQL type and the short primitive.
SHORT_OBJ
          Links the Types.SMALLINT SQL type and the Short Java class.
STRING
          Links the Types.VARCHAR SQL type and the String Java class.
UNKNOWN
          Marker for fields that are unknown.
 
Method Summary
 Object convertIdNumber(Number number)
          Convert a Number object to its primitive object suitable for assigning to an ID field.
 boolean escapeDefaultValue()
          Return whether this field's default value should be escaped in SQL.
 int getJdbcTypeVal()
          Return the SQL type that is stored in the database for this argument.
 boolean isNumber()
          Return whether this field is a number.
 boolean isPrimitive()
          Return whether this field is a primitive type or not.
 boolean isStreamType()
          Return whether or not this is a SQL "stream" object.
 boolean isValidForType(Class<?> fieldClass)
          Return true if the fieldClass is appropriate for this enum.
 boolean isValidGeneratedType()
          Return true if this type can be auto-generated by the database.
 Object javaToArg(Object javaObject)
          Convert a Java object and return the appropriate argument to a SQL insert or update statement.
static JdbcType lookupClass(Class<?> dataClass)
          Static method that returns the JdbcType associated with the class argument or UNKNOWN if not found.
static JdbcType lookupIdTypeVal(int typeVal)
          Static method that returns the JdbcType associated with the SQL type value or UNKNOWN if UNKNOWN not found.
abstract  Object parseDefaultString(String defaultStr)
          Convert a default string object and return the appropriate argument to a SQL insert or update statement.
 Number resultToId(Results results, int columnPos)
          Return the object suitable to be set on an id field that was extracted from the results associated with column in position columnPos.
abstract  Object resultToJava(FieldType fieldType, Results results, int columnPos)
          Return the object extracted from the results associated with column in position columnPos.
static JdbcType valueOf(String name)
          Returns the enum constant of this type with the specified name.
static JdbcType[] 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 JdbcType STRING
Links the Types.VARCHAR SQL type and the String Java class.


BOOLEAN

public static final JdbcType BOOLEAN
Links the Types.BOOLEAN SQL type and the boolean primitive.


BOOLEAN_OBJ

public static final JdbcType BOOLEAN_OBJ
Links the Types.BOOLEAN SQL type and the Boolean Java class.


JAVA_DATE

public static final JdbcType JAVA_DATE
Links the Types.TIMESTAMP SQL type and the Date Java class.

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


BYTE

public static final JdbcType BYTE
Links the Types.TINYINT SQL type and the byte primitive.


BYTE_OBJ

public static final JdbcType BYTE_OBJ
Links the Types.TINYINT SQL type and the Byte Java class.


SHORT

public static final JdbcType SHORT
Links the Types.SMALLINT SQL type and the short primitive.


SHORT_OBJ

public static final JdbcType SHORT_OBJ
Links the Types.SMALLINT SQL type and the Short Java class.


INTEGER

public static final JdbcType INTEGER
Links the Types.INTEGER SQL type and the int primitive.


INTEGER_OBJ

public static final JdbcType INTEGER_OBJ
Links the Types.INTEGER SQL type and the Integer Java class.


LONG

public static final JdbcType LONG
Links the Types.BIGINT SQL type and the long primitive.


LONG_OBJ

public static final JdbcType LONG_OBJ
Links the Types.BIGINT SQL type and the Long Java class.


FLOAT

public static final JdbcType FLOAT
Links the Types.FLOAT SQL type and the float primitive.


FLOAT_OBJ

public static final JdbcType FLOAT_OBJ
Links the Types.FLOAT SQL type and the Float Java class.


DOUBLE

public static final JdbcType DOUBLE
Links the Types.DOUBLE SQL type and the double primitive.


DOUBLE_OBJ

public static final JdbcType DOUBLE_OBJ
Links the Types.DOUBLE SQL type and the Double Java class.


SERIALIZABLE

public static final JdbcType SERIALIZABLE
Links the Types.VARBINARY SQL type and an unknown Java Object that is serializable.


ENUM_STRING

public static final JdbcType ENUM_STRING
Links the Types.VARCHAR SQL type and the Enum Java class. You can also specify the ENUM_INTEGER as the JdbcType.


ENUM_INTEGER

public static final JdbcType ENUM_INTEGER
Links the Types.INTEGER SQL type and the Enum Java class. You can also specify the ENUM_STRING as the JdbcType.


UNKNOWN

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

Method Detail

values

public static JdbcType[] 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 (JdbcType c : JdbcType.values())
    System.out.println(c);

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

valueOf

public static JdbcType 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

resultToJava

public abstract Object resultToJava(FieldType fieldType,
                                    Results 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
Throws:
SQLException - If there is a problem accessing the results data.

parseDefaultString

public abstract Object parseDefaultString(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

javaToArg

public Object javaToArg(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:
javaToArg in interface FieldConverter
Throws:
SQLException

getJdbcTypeVal

public int getJdbcTypeVal()
Description copied from interface: FieldConverter
Return the SQL type that is stored in the database for this argument. This should be one of the Types constants.

Specified by:
getJdbcTypeVal in interface FieldConverter

isValidGeneratedType

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


convertIdNumber

public Object convertIdNumber(Number number)
Convert a Number object to its primitive object suitable for assigning to an ID field.


resultToId

public Number resultToId(Results results,
                         int columnPos)
                  throws SQLException
Return the object suitable to be set on an id field that was extracted from the results associated with column in position columnPos.

Throws:
SQLException

isValidForType

public boolean isValidForType(Class<?> fieldClass)
Return true if the fieldClass is appropriate for this enum.


lookupClass

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


lookupIdTypeVal

public static JdbcType lookupIdTypeVal(int typeVal)
Static method that returns the JdbcType associated with the SQL type value or UNKNOWN if UNKNOWN not found.


escapeDefaultValue

public boolean escapeDefaultValue()
Return whether this field's default value should be escaped in SQL.


isNumber

public boolean isNumber()
Return whether this field is a number.


isPrimitive

public boolean isPrimitive()
Return whether this field is a primitive type or not.


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


Copyright © 2010. All Rights Reserved.