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.support.ConnectionSource, java.lang.String, java.lang.reflect.Field, java.lang.Class) 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(ConnectionSource connectionSource, String tableName, Field field, DatabaseFieldConfig fieldConfig, Class<?> parentClass)
          You should use createFieldType(com.j256.ormlite.support.ConnectionSource, java.lang.String, java.lang.reflect.Field, java.lang.Class) to instantiate one of these field if you have a Field.
 
Method Summary
 void assignField(Object data, Object val, boolean parentObject, ObjectCache objectCache)
          Assign to the data object the val corresponding to the fieldType.
 Object assignIdValue(Object data, Number val, ObjectCache objectCache)
          Assign an ID value to this field.
<FT,FID> BaseForeignCollection<FT,FID>
buildForeignCollection(Object parent, FID id)
          Build and return a foreign collection based on the field settings that matches the id argument.
 void configDaoInformation(ConnectionSource connectionSource, Class<?> parentClass)
          Because we go recursive in a lot of situations if we construct DAOs inside of the FieldType constructor, we have to do this 2nd pass initialization so we can better use the DAO caches.
 Object convertJavaFieldToSqlArgValue(Object fieldVal)
          Convert a field value to something suitable to be stored in the database.
 Object convertStringToJavaField(String value, int columnPos)
          Convert a string value into the appropriate Java field value.
static FieldType createFieldType(ConnectionSource connectionSource, String tableName, Field field, Class<?> parentClass)
          Return An instantiated FieldType or null if the field does not have a DatabaseField annotation.
<T> int
createWithForeignDao(T foreignData)
          Pass the foreign data argument to the foreign Dao.create(Object) method.
 boolean equals(Object arg)
           
 Object extractJavaFieldToSqlArgValue(Object object)
          Extract a field from an object and convert to something suitable to be passed to SQL as an argument.
 Object extractJavaFieldValue(Object object)
          Return the value from the field in the object that is defined by this FieldType.
<FV> FV
extractRawJavaFieldValue(Object object)
          Return the value from the field in the object that is defined by this FieldType.
 Object generateId()
          Call through to DataPersister.generateId()
 String getColumnDefinition()
          Call through to DatabaseFieldConfig.getColumnDefinition()
 String getColumnName()
           
 DataPersister getDataPersister()
           
 Object getDataTypeConfigObj()
           
 Object getDefaultValue()
          Return the default value as parsed from the DatabaseFieldConfig.getDefaultValue().
 Field getField()
           
 String getFieldName()
           
<FV> FV
getFieldValueIfNotDefault(Object object)
          Return the value of field in the data argument if it is not the default value for the class.
 FieldType getForeignIdField()
          Return the id field associated with the foreign object or null if none.
 String getFormat()
          Return the format of the field.
 String getGeneratedIdSequence()
          Return the generated-id-sequence associated with the field or null if isGeneratedIdSequence() is false.
 String getIndexName()
           
 Object getJavaDefaultValueDefault()
          Return whether or not the field value passed in is the default value for the type of the field.
 SqlType getSqlType()
           
 String getTableName()
           
 Class<?> getType()
          Return the class of the field associated with this field type.
 String getUniqueIndexName()
           
 Enum<?> getUnknownEnumVal()
           
 int getWidth()
           
 int hashCode()
           
 boolean isAllowGeneratedIdInsert()
          Call through to DatabaseFieldConfig.isAllowGeneratedIdInsert()
 boolean isArgumentHolderRequired()
          Call through to DataPersister.isArgumentHolderRequired()
 boolean isCanBeNull()
           
 boolean isComparable()
          Call through to DataPersister.isComparable()
 boolean isEscapedDefaultValue()
          Call through to DataPersister.isEscapedDefaultValue()
 boolean isEscapedValue()
          Call through to DataPersister.isEscapedValue()
 boolean isForeign()
           
 boolean isForeignAutoCreate()
          Call through to DatabaseFieldConfig.isForeignAutoCreate()
 boolean isForeignCollection()
          Call through to DatabaseFieldConfig.isForeignCollection()
 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 isObjectsFieldValueDefault(Object object)
          Return whether or not the data object has a default value passed for this field of this type.
 boolean isReadOnly()
          Call through to DatabaseFieldConfig.isReadOnly()
 boolean isSelfGeneratedId()
          Call through to DataPersister.isSelfGeneratedId()
 boolean isUnique()
           
 boolean isUniqueCombo()
           
 boolean isVersion()
          Call through to DatabaseFieldConfig.isVersion()
 Object moveToNextValue(Object val)
          Move the SQL value to the next one for version processing.
<T> T
resultToJava(DatabaseResults results, Map<String,Integer> columnPositions)
          Get the result object from the results.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, 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(ConnectionSource connectionSource,
                 String tableName,
                 Field field,
                 DatabaseFieldConfig fieldConfig,
                 Class<?> parentClass)
          throws SQLException
You should use createFieldType(com.j256.ormlite.support.ConnectionSource, java.lang.String, java.lang.reflect.Field, java.lang.Class) to instantiate one of these field if you have a Field.

Throws:
SQLException
Method Detail

configDaoInformation

public void configDaoInformation(ConnectionSource connectionSource,
                                 Class<?> parentClass)
                          throws SQLException
Because we go recursive in a lot of situations if we construct DAOs inside of the FieldType constructor, we have to do this 2nd pass initialization so we can better use the DAO caches.

Throws:
SQLException
See Also:
BaseDaoImpl.initialize()

getField

public Field getField()

getTableName

public String getTableName()

getFieldName

public String getFieldName()

getType

public Class<?> getType()
Return the class of the field associated with this field type.


getColumnName

public String getColumnName()

getDataPersister

public DataPersister getDataPersister()

getDataTypeConfigObj

public Object getDataTypeConfigObj()

getSqlType

public SqlType getSqlType()

getDefaultValue

public Object getDefaultValue()
Return the default value as parsed from the DatabaseFieldConfig.getDefaultValue().


getWidth

public int getWidth()

isCanBeNull

public boolean isCanBeNull()

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()

assignField

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

Throws:
SQLException

assignIdValue

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

Throws:
SQLException

extractRawJavaFieldValue

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

Throws:
SQLException

extractJavaFieldValue

public Object extractJavaFieldValue(Object object)
                             throws SQLException
Return the value from the field in the object that is defined by this FieldType. If the field is a foreign object then the ID of the field is returned instead.

Throws:
SQLException

extractJavaFieldToSqlArgValue

public Object extractJavaFieldToSqlArgValue(Object object)
                                     throws SQLException
Extract a field from an object and convert to something suitable to be passed to SQL as an argument.

Throws:
SQLException

convertJavaFieldToSqlArgValue

public Object convertJavaFieldToSqlArgValue(Object fieldVal)
                                     throws SQLException
Convert a field value to something suitable to be stored in the database.

Throws:
SQLException

convertStringToJavaField

public Object convertStringToJavaField(String value,
                                       int columnPos)
                                throws SQLException
Convert a string value into the appropriate Java field value.

Throws:
SQLException

moveToNextValue

public Object moveToNextValue(Object val)
Move the SQL value to the next one for version processing.


getForeignIdField

public FieldType getForeignIdField()
Return the id field associated with the foreign object or null if none.


isEscapedValue

public boolean isEscapedValue()
Call through to DataPersister.isEscapedValue()


getUnknownEnumVal

public Enum<?> getUnknownEnumVal()

getFormat

public String getFormat()
Return the format of the field.


isUnique

public boolean isUnique()

isUniqueCombo

public boolean isUniqueCombo()

getIndexName

public String getIndexName()

getUniqueIndexName

public String getUniqueIndexName()

isEscapedDefaultValue

public boolean isEscapedDefaultValue()
Call through to DataPersister.isEscapedDefaultValue()


isComparable

public boolean isComparable()
                     throws SQLException
Call through to DataPersister.isComparable()

Throws:
SQLException

isArgumentHolderRequired

public boolean isArgumentHolderRequired()
Call through to DataPersister.isArgumentHolderRequired()


isForeignCollection

public boolean isForeignCollection()
Call through to DatabaseFieldConfig.isForeignCollection()


buildForeignCollection

public <FT,FID> BaseForeignCollection<FT,FID> buildForeignCollection(Object parent,
                                                                     FID id)
                                                     throws SQLException
Build and return a foreign collection based on the field settings that matches the id argument. This can return null in certain circumstances.

Parameters:
parent - The parent object that we will set on each item in the collection.
id - The id of the foreign object we will look for. This can be null if we are creating an empty collection.
Throws:
SQLException

resultToJava

public <T> T resultToJava(DatabaseResults 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.DatabaseResults, int).

Throws:
SQLException

isSelfGeneratedId

public boolean isSelfGeneratedId()
Call through to DataPersister.isSelfGeneratedId()


isAllowGeneratedIdInsert

public boolean isAllowGeneratedIdInsert()
Call through to DatabaseFieldConfig.isAllowGeneratedIdInsert()


getColumnDefinition

public String getColumnDefinition()
Call through to DatabaseFieldConfig.getColumnDefinition()


isForeignAutoCreate

public boolean isForeignAutoCreate()
Call through to DatabaseFieldConfig.isForeignAutoCreate()


isVersion

public boolean isVersion()
Call through to DatabaseFieldConfig.isVersion()


generateId

public Object generateId()
Call through to DataPersister.generateId()


isReadOnly

public boolean isReadOnly()
Call through to DatabaseFieldConfig.isReadOnly()


getFieldValueIfNotDefault

public <FV> FV getFieldValueIfNotDefault(Object object)
                             throws SQLException
Return the value of field in the data argument if it is not the default value for the class. If it is the default then null is returned.

Throws:
SQLException

isObjectsFieldValueDefault

public boolean isObjectsFieldValueDefault(Object object)
                                   throws SQLException
Return whether or not the data object has a default value passed for this field of this type.

Throws:
SQLException

getJavaDefaultValueDefault

public Object getJavaDefaultValueDefault()
Return whether or not the field value passed in is the default value for the type of the field. Null will return true.


createWithForeignDao

public <T> int createWithForeignDao(T foreignData)
                         throws SQLException
Pass the foreign data argument to the foreign Dao.create(Object) method.

Throws:
SQLException

createFieldType

public static FieldType createFieldType(ConnectionSource connectionSource,
                                        String tableName,
                                        Field field,
                                        Class<?> parentClass)
                                 throws SQLException
Return An instantiated FieldType or null if the field does not have a DatabaseField annotation.

Throws:
SQLException

equals

public boolean equals(Object arg)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

toString

public String toString()
Overrides:
toString in class Object


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