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
static int MAX_FOREIGN_RECURSE_LEVEL
           
 
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)
          Assign to the data object the val corresponding to the fieldType.
 Object assignIdValue(Object data, Number val)
          Assign an ID value to this field.
<FT,FID> BaseForeignCollection<FT,FID>
buildForeignCollection(Object id)
          Build and return a foreign collection based on the field settings that matches the id argument.
<FV> FV
convertJavaFieldToSqlArgValue(Object fieldVal)
          Convert a field value to something suitable to be stored in the database.
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.
 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.
<FV> FV
extractJavaFieldValue(Object object)
          Return the value from the field in the object that is defined by this FieldType.
 Object generatedId()
          Call through to DataType.generatedId()
 DataType getDataType()
           
 Object getDataTypeConfigObj()
           
 String getDbColumnName()
           
 Object getDefaultValue()
           
 String getFieldName()
           
 Class<?> getFieldType()
           
<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 getGeneratedIdSequence()
          Return the generated-id-sequence associated with the field or null if isGeneratedIdSequence() is false.
 String getIndexName()
           
 SqlType getSqlType()
           
 String getTableName()
           
 String getUniqueIndexName()
           
 int getWidth()
           
 int hashCode()
           
 boolean isCanBeNull()
           
 boolean isComparable()
          Call through to DataType.isComparable()
 boolean isEscapedDefaultValue()
          Call through to DataType.isEscapedDefaultValue()
 boolean isEscapedValue()
          Call through to DataType.isEscapedValue()
 boolean isForeign()
           
 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 isSelectArgRequired()
          Call through to DataType.isSelectArgRequired()
 boolean isSelfGeneratedId()
          Call through to DataType.isSelfGeneratedId()
 boolean isUnique()
           
 boolean isUniqueCombo()
           
<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

MAX_FOREIGN_RECURSE_LEVEL

public static final int MAX_FOREIGN_RECURSE_LEVEL
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

getTableName

public String getTableName()

getFieldName

public String getFieldName()

getFieldType

public Class<?> getFieldType()

getDbColumnName

public String getDbColumnName()

getDataType

public DataType getDataType()

getDataTypeConfigObj

public Object getDataTypeConfigObj()

getSqlType

public SqlType getSqlType()

getDefaultValue

public Object 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)
                 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

extractJavaFieldValue

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

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 <FV> FV convertJavaFieldToSqlArgValue(Object fieldVal)
                                 throws SQLException
Convert a field value to something suitable to be stored in the database.

Throws:
SQLException

getForeignIdField

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

Throws:
SQLException

isEscapedValue

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


isUnique

public boolean isUnique()

isUniqueCombo

public boolean isUniqueCombo()

getIndexName

public String getIndexName()

getUniqueIndexName

public String getUniqueIndexName()

isEscapedDefaultValue

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


isComparable

public boolean isComparable()
Call through to DataType.isComparable()


isSelectArgRequired

public boolean isSelectArgRequired()
Call through to DataType.isSelectArgRequired()


isForeignCollection

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


buildForeignCollection

public <FT,FID> BaseForeignCollection<FT,FID> buildForeignCollection(Object 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.

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 DataType.isSelfGeneratedId()


generatedId

public Object generatedId()
Call through to DataType.generatedId()


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

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


Copyright © 2011. All Rights Reserved.