com.j256.ormlite.field
Class FieldType

java.lang.Object
  extended by com.j256.ormlite.field.FieldType

public class FieldType
extends Object

Per field information configured from the DatabaseField annotation and the associated Field in the class. Use the createFieldType(com.j256.ormlite.db.DatabaseType, java.lang.String, java.lang.reflect.Field) static method to instantiate the class.

Author:
graywatson

Field Summary
static String FOREIGN_ID_FIELD_SUFFIX
          default suffix added to fields that are id fields of foreign objects
 
Constructor Summary
FieldType(DatabaseType databaseType, String tableName, Field field, DatabaseFieldConfig fieldConfig)
          You should use createFieldType(com.j256.ormlite.db.DatabaseType, java.lang.String, java.lang.reflect.Field) to instantiate one of these field if you have a Field.
 
Method Summary
 void assignField(Object data, Object val)
          Assign to the data object the val corresponding to the fieldType.
 Object assignIdValue(Object data, Number val)
          Assign an ID value to this field.
static FieldType createFieldType(DatabaseType databaseType, String tableName, Field field)
          Return An instantiated FieldType or null if the field does not have a DatabaseField annotation.
 Enum<?> enumFromInt(Integer val)
          Get the Enum associated with the integer value.
 Enum<?> enumFromString(String val)
          Get the Enum associated with the String value.
 boolean escapeDefaultValue()
          Return whether this field's default value should be escaped in SQL.
<FV> FV
getConvertedFieldValue(Object object)
          Return the value from the field in the object after it has been converted to something suitable to be stored in the database.
 String getDbColumnName()
          Return the column name either specified my DatabaseField.columnName() or from Field.getName().
 Object getDefaultValue()
          Return the default value configured by DatabaseField.defaultValue() or null if none.
 String getFieldName()
          Return the column name either specified my DatabaseField.columnName() or from Field.getName().
<FV> FV
getFieldValue(Object object)
          Return the value from the field in the object that is defined by this FieldType.
 TableInfo<?> getForeignTableInfo()
          Return the TableInfo associated with the foreign object if the DatabaseField.foreign() annotation was set to true or null if none.
 String getGeneratedIdSequence()
          Return the generated-id-sequence associated with the field or null if isGeneratedIdSequence() is false.
 JdbcType getJdbcType()
          Return the JdbcType associated with this.
 int getJdbcTypeVal()
          Return the JDBC type value.
 int getWidth()
          Return the width of the field as configured by DatabaseField.width().
 boolean isCanBeNull()
          Return whether the field can be assigned to null as configured by DatabaseField.canBeNull().
 boolean isForeign()
          Return whether or not the field is a foreign object field.
 boolean isGeneratedId()
          Return whether the field is a generated-id field.
 boolean isGeneratedIdSequence()
          Return whether the field is a generated-id-sequence field.
 boolean isId()
          Return whether the field is an id field.
 boolean isNumber()
          Return whether this field is a number.
 boolean isThrowIfNull()
           
 Object parseDefaultString(String defaulStr)
          Convert the default value string into a valid Java object for this type.
<T> T
resultToJava(Results results, Map<String,Integer> columnPositions)
          Get the result object from the results.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

FOREIGN_ID_FIELD_SUFFIX

public static final String FOREIGN_ID_FIELD_SUFFIX
default suffix added to fields that are id fields of foreign objects

See Also:
Constant Field Values
Constructor Detail

FieldType

public FieldType(DatabaseType databaseType,
                 String tableName,
                 Field field,
                 DatabaseFieldConfig fieldConfig)
          throws SQLException
You should use createFieldType(com.j256.ormlite.db.DatabaseType, java.lang.String, java.lang.reflect.Field) to instantiate one of these field if you have a Field.

Throws:
SQLException
Method Detail

getFieldName

public String getFieldName()
Return the column name either specified my DatabaseField.columnName() or from Field.getName().


getDbColumnName

public String getDbColumnName()
Return the column name either specified my DatabaseField.columnName() or from Field.getName().


getJdbcType

public JdbcType getJdbcType()
Return the JdbcType associated with this.


getJdbcTypeVal

public int getJdbcTypeVal()
Return the JDBC type value.


getDefaultValue

public Object getDefaultValue()
Return the default value configured by DatabaseField.defaultValue() or null if none.


getWidth

public int getWidth()
Return the width of the field as configured by DatabaseField.width().


isCanBeNull

public boolean isCanBeNull()
Return whether the field can be assigned to null as configured by DatabaseField.canBeNull().


isId

public boolean isId()
Return whether the field is an id field. It is an id if DatabaseField.id(), DatabaseField.generatedId(), OR DatabaseField.generatedIdSequence() are enabled.


isGeneratedId

public boolean isGeneratedId()
Return whether the field is a generated-id field. This is true if DatabaseField.generatedId() OR DatabaseField.generatedIdSequence() are enabled.


isGeneratedIdSequence

public boolean isGeneratedIdSequence()
Return whether the field is a generated-id-sequence field. This is true if DatabaseField.generatedIdSequence() is specified OR if DatabaseField.generatedId() is enabled and the DatabaseType.isIdSequenceNeeded() is enabled. If the latter is true then the sequence name will be auto-generated.


getGeneratedIdSequence

public String getGeneratedIdSequence()
Return the generated-id-sequence associated with the field or null if isGeneratedIdSequence() is false.


isForeign

public boolean isForeign()
Return whether or not the field is a foreign object field.


getForeignTableInfo

public TableInfo<?> getForeignTableInfo()
Return the TableInfo associated with the foreign object if the DatabaseField.foreign() annotation was set to true or null if none.


parseDefaultString

public Object parseDefaultString(String defaulStr)
                          throws SQLException
Convert the default value string into a valid Java object for this type.

Throws:
SQLException

assignField

public void assignField(Object data,
                        Object val)
                 throws SQLException
Assign to the data object the val corresponding to the fieldType.

Throws:
SQLException

assignIdValue

public Object assignIdValue(Object data,
                            Number val)
                     throws SQLException
Assign an ID value to this field.

Throws:
SQLException

getFieldValue

public <FV> FV getFieldValue(Object object)
                 throws SQLException
Return the value from the field in the object that is defined by this FieldType.

Throws:
SQLException

getConvertedFieldValue

public <FV> FV getConvertedFieldValue(Object object)
                          throws SQLException
Return the value from the field in the object after it has been converted to something suitable to be stored in the database.

Throws:
SQLException

isThrowIfNull

public boolean isThrowIfNull()

isNumber

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


escapeDefaultValue

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


resultToJava

public <T> T resultToJava(Results results,
                          Map<String,Integer> columnPositions)
               throws SQLException
Get the result object from the results. A call through to FieldConverter.resultToJava(com.j256.ormlite.field.FieldType, com.j256.ormlite.support.Results, int).

Throws:
SQLException

enumFromInt

public Enum<?> enumFromInt(Integer val)
                    throws SQLException
Get the Enum associated with the integer value. NOTE: It is an Integer object for a reason. No changie.

Throws:
SQLException

enumFromString

public Enum<?> enumFromString(String val)
                       throws SQLException
Get the Enum associated with the String value.

Throws:
SQLException

createFieldType

public static FieldType createFieldType(DatabaseType databaseType,
                                        String tableName,
                                        Field field)
                                 throws SQLException
Return An instantiated FieldType or null if the field does not have a DatabaseField annotation.

Throws:
SQLException

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2010. All Rights Reserved.