org.sormula.translator
Class AbstractBlobColumnTranslator<R,T>

java.lang.Object
  extended by org.sormula.translator.AbstractColumnTranslator<R,T>
      extended by org.sormula.translator.AbstractBlobColumnTranslator<R,T>
Type Parameters:
R - row class
T - type of field that is stored as SQL BLOB type
All Implemented Interfaces:
ColumnTranslator<R>

public abstract class AbstractBlobColumnTranslator<R,T>
extends AbstractColumnTranslator<R,T>

Base class for creating custom column translators for fields stored as SQL BLOB. Translates a field using PreparedStatement.setBlob(int, Blob) and ResultSet.getBlob(int). Implement blobToField(Blob) and fieldToBlob(Object) to create a blob column translator for type T in row type R. AbstractColumnTranslator is the base class. See BlobExample and WidgetColumnTranslator2 for example of how to use this class.

Since:
1.0
Author:
Jeff Miller

Constructor Summary
AbstractBlobColumnTranslator(java.lang.reflect.Field field, java.lang.String columnName)
          See super class constructor for description.
 
Method Summary
protected abstract  T blobToField(java.sql.Blob blob)
          Converts a Blob object to a domain object for use by read(ResultSet, int, Object).
protected abstract  java.sql.Blob fieldToBlob(T field)
          Converts a domain object to a Blob for use by write(PreparedStatement, int, Object).
 void read(java.sql.ResultSet resultSet, int columnIndex, R row)
          Reads column value from result set and sets in row object.
 void write(java.sql.PreparedStatement preparedStatement, int parameterIndex, R row)
          Gets column value from row and sets as parameter in prepared statement.
 
Methods inherited from class org.sormula.translator.AbstractColumnTranslator
getColumnName, getField, getSormulaField, getTypeTranslator, isIdentity, newInstance, setIdentity, setTypeTranslator
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractBlobColumnTranslator

public AbstractBlobColumnTranslator(java.lang.reflect.Field field,
                                    java.lang.String columnName)
                             throws java.lang.Exception
See super class constructor for description.

Throws:
java.lang.Exception
Method Detail

write

public void write(java.sql.PreparedStatement preparedStatement,
                  int parameterIndex,
                  R row)
           throws java.lang.Exception
Gets column value from row and sets as parameter in prepared statement.

Specified by:
write in interface ColumnTranslator<R>
Overrides:
write in class AbstractColumnTranslator<R,T>
Parameters:
preparedStatement - set column value as parameter in this statement
parameterIndex - set parameter at this index
row - get value from this row
Throws:
java.lang.Exception - if error

read

public void read(java.sql.ResultSet resultSet,
                 int columnIndex,
                 R row)
          throws java.lang.Exception
Reads column value from result set and sets in row object.

Specified by:
read in interface ColumnTranslator<R>
Overrides:
read in class AbstractColumnTranslator<R,T>
Parameters:
resultSet - read column from this result set
columnIndex - read value at this column index from result set
row - set value in this row
Throws:
java.lang.Exception - if error

fieldToBlob

protected abstract java.sql.Blob fieldToBlob(T field)
                                      throws java.lang.Exception
Converts a domain object to a Blob for use by write(PreparedStatement, int, Object). Implement this method in a subclass to write type T that to database as a BLOB column type.

Parameters:
field - domain object that is stored in database as SQL BLOB type
Returns:
JDBC blob
Throws:
java.lang.Exception - if error

blobToField

protected abstract T blobToField(java.sql.Blob blob)
                          throws java.lang.Exception
Converts a Blob object to a domain object for use by read(ResultSet, int, Object). Implement this method in a subclass to read type T from database as a BLOB column type.

Parameters:
blob - JDBC blob
Returns:
domain object that is stored in database as SQL BLOB type
Throws:
java.lang.Exception