org.afcs.warts.handlers
Class CharacterHandler

java.lang.Object
  extended byorg.afcs.warts.handlers.DataHandlerSupport
      extended byorg.afcs.warts.handlers.CharacterHandler
All Implemented Interfaces:
DataHandler

public final class CharacterHandler
extends DataHandlerSupport
implements DataHandler

The CharacterHandler class handles the loading, printing, and binding of database columns containing character data (i.e., columns of type CHAR and VARCHAR). All character data loaded using this handler is stored in DataHighBitAnalysis instances, allowing encoding analysis to be performed without further conversion.

This class contains a workaround for an Oracle JDBC driver bug where data is not loaded correctly from CHAR columns with character length semantics. These are padded with extra characters by the driver, where the number of padding characters depends on the number of non-ascii characters in the field. These cases are truncated. The bug has been documented in a post to Oracle's JDBC forum.

LICENSE: This code is released to the public domain and may be used for any purpose whatsoever without permission or acknowledgment.

Version:
Last Modified 29 August 2003
Author:
Warren Hedley ( whedley at sdsc dot edu )

Constructor Summary
CharacterHandler(TableDescription tableDescription, ColumnDescription columnDescription)
          Constructs a new instance on behalf of subclasses that will handle data values for the specified column in the specified table.
 
Method Summary
 void bindNonNullValue(java.sql.PreparedStatement statement, int columnIndex, java.lang.Object value)
          Given a prepared statement and a column index, this method binds the specified value to the specified column in the specified prepared statement, using a binding appropriate to character data.
 boolean isCharacterData()
          Always returns true.
 java.lang.Object loadValue(java.sql.ResultSet resultSet, int columnIndex)
          This method loads the character data associated with the specified column in the specified result set, returning a DataHighBitAnalysis instance containing analysis of the character data, if some exists, or null otherwise.
 java.lang.String printNonNullValue(java.lang.Object value)
          Returns a string containing a representation of the specified value appropriate for use in a SQL script.
 
Methods inherited from class org.afcs.warts.handlers.DataHandlerSupport
getColumnDescription, getNullType, getTableDescription, isNullHandler, loadBytesFromStream, logWrongValueTypeWarning, postProcessBind, requiresBindPostProcessing, requiresStreamedLoading, toString, verifyObjectIsString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.afcs.warts.handlers.DataHandler
getNullType, isNullHandler, postProcessBind, requiresBindPostProcessing, requiresStreamedLoading
 

Constructor Detail

CharacterHandler

public CharacterHandler(TableDescription tableDescription,
                        ColumnDescription columnDescription)
Constructs a new instance on behalf of subclasses that will handle data values for the specified column in the specified table.

Parameters:
tableDescription - The table that the handler will be handling data for.
columnDescription - The column that this class will be processing data for.
Method Detail

bindNonNullValue

public void bindNonNullValue(java.sql.PreparedStatement statement,
                             int columnIndex,
                             java.lang.Object value)
                      throws java.sql.SQLException
Given a prepared statement and a column index, this method binds the specified value to the specified column in the specified prepared statement, using a binding appropriate to character data.

Specified by:
bindNonNullValue in interface DataHandler
Parameters:
statement - The statement to bind the value to.
columnIndex - The index of the variable to bind the value to.
value - The value to bind. This must be a character data type, such as a DataHighBitAnalysis instance, a String instance, or null.
Throws:
java.sql.SQLException - If a SQL error occurs.

isCharacterData

public boolean isCharacterData()
Always returns true.

Specified by:
isCharacterData in interface DataHandler
Overrides:
isCharacterData in class DataHandlerSupport
Returns:
Always true.

loadValue

public java.lang.Object loadValue(java.sql.ResultSet resultSet,
                                  int columnIndex)
                           throws java.sql.SQLException
This method loads the character data associated with the specified column in the specified result set, returning a DataHighBitAnalysis instance containing analysis of the character data, if some exists, or null otherwise.

Specified by:
loadValue in interface DataHandler
Parameters:
resultSet - The result set to load the value from.
columnIndex - The column to load the value from.
Returns:
A DataHighBitAnalysis instance containing analysis of the character data, if some exists, or null otherwise.
Throws:
java.sql.SQLException - If a SQL error occurs.

printNonNullValue

public java.lang.String printNonNullValue(java.lang.Object value)
Returns a string containing a representation of the specified value appropriate for use in a SQL script. Any apostrophes in the string will be escaped, and the data will be truncated if necessary to the column size.

Specified by:
printNonNullValue in interface DataHandler
Parameters:
value - The value to print. This must be a character data type, such as a DataHighBitAnalysis instance, a String instance, or null.
Returns:
A string containing a representation of the specified value appropriate for use in a SQL script.