com.j256.ormlite.field
Interface FieldConverter

All Known Subinterfaces:
DataPersister
All Known Implementing Classes:
BaseDatabaseType.BooleanNumberFieldConverter, BaseDataType, BaseDateType, BaseEnumType, BaseFieldConverter, BigDecimalNumericType, BigDecimalStringType, BigIntegerType, BooleanObjectType, BooleanType, ByteArrayType, ByteObjectType, ByteType, CharacterObjectType, CharType, DateLongType, DateStringType, DateTimeType, DateType, DoubleObjectType, DoubleType, EnumIntegerType, EnumStringType, FloatObjectType, FloatType, IntegerObjectType, IntType, LongObjectType, LongStringType, LongType, SerializableType, ShortObjectType, ShortType, SqlDateType, StringBytesType, StringType, TimeStampType, UuidType, VoidType

public interface FieldConverter

Convert a Java object into the appropriate argument to a SQL statement and then back from the result set to the Java object. This allows databases to configure per-type conversion. This is used by the BaseDatabaseType.getFieldConverter(DataPersister) method to find the converter for a particular database type. Databases can then override the default data conversion mechanisms as necessary.

Author:
graywatson

Method Summary
 SqlType getSqlType()
          Return the SQL type that is stored in the database for this argument.
 boolean isStreamType()
          Return whether or not this is a SQL "stream" object.
 Object javaToSqlArg(FieldType fieldType, Object obj)
          Convert a Java object and return the appropriate argument to a SQL insert or update statement.
 Object parseDefaultString(FieldType fieldType, String defaultStr)
          Convert a default string object and return the appropriate argument to a SQL insert or update statement.
 Object resultStringToJava(FieldType fieldType, String stringValue, int columnPos)
          Convert a string result value to the related Java field.
 Object resultToJava(FieldType fieldType, DatabaseResults results, int columnPos)
          This is usually just a call that takes the result from resultToSqlArg(FieldType, DatabaseResults, int) and passes it through sqlArgToJava(FieldType, Object, int).
 Object resultToSqlArg(FieldType fieldType, DatabaseResults results, int columnPos)
          Return the SQL argument object extracted from the results associated with column in position columnPos.
 Object sqlArgToJava(FieldType fieldType, Object sqlArg, int columnPos)
          Return the object converted from the SQL arg to java.
 

Method Detail

parseDefaultString

Object parseDefaultString(FieldType fieldType,
                          String defaultStr)
                          throws SQLException
Convert a default string object and return the appropriate argument to a SQL insert or update statement.

Throws:
SQLException

javaToSqlArg

Object javaToSqlArg(FieldType fieldType,
                    Object obj)
                    throws SQLException
Convert a Java object and return the appropriate argument to a SQL insert or update statement.

Throws:
SQLException

resultToSqlArg

Object resultToSqlArg(FieldType fieldType,
                      DatabaseResults results,
                      int columnPos)
                      throws SQLException
Return the SQL argument object extracted from the results associated with column in position columnPos.

Parameters:
fieldType - Associated FieldType which may be null.
Throws:
SQLException - If there is a problem accessing the results data.

resultToJava

Object resultToJava(FieldType fieldType,
                    DatabaseResults results,
                    int columnPos)
                    throws SQLException
This is usually just a call that takes the result from resultToSqlArg(FieldType, DatabaseResults, int) and passes it through sqlArgToJava(FieldType, Object, int).

Throws:
SQLException

sqlArgToJava

Object sqlArgToJava(FieldType fieldType,
                    Object sqlArg,
                    int columnPos)
                    throws SQLException
Return the object converted from the SQL arg to java.

Parameters:
fieldType - Associated FieldType which may be null.
sqlArg - SQL argument converted with resultToSqlArg(FieldType, DatabaseResults, int) which will not be null.
Throws:
SQLException

getSqlType

SqlType getSqlType()
Return the SQL type that is stored in the database for this argument.


isStreamType

boolean isStreamType()
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.


resultStringToJava

Object resultStringToJava(FieldType fieldType,
                          String stringValue,
                          int columnPos)
                          throws SQLException
Convert a string result value to the related Java field.

Throws:
SQLException


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