org.afcs.warts.handlers
Class OracleClobHandler

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

public final class OracleClobHandler
extends LobDataHandlerSupport
implements DataHandler

The OracleClobHandler class extends LobDataHandlerSupport and handles the reading and writing of CLOB data. The compilation and use of this code requires the availability of Oracle's proprietary JDBC drivers -- as of release 9.2.0.3 of their drivers, there is no way to write to CLOB columns without resorting to their non-standard API.

The object returned by loadValue(java.sql.ResultSet, int), and expected by bindValue() and printValue() is a stored in DataHighBitAnalysis instance, which ensures that encoding analysis is performed on all character data.

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

Version:
Last Modified 17 September 2003
Author:
Warren Hedley ( whedley at sdsc dot edu )

Constructor Summary
OracleClobHandler(TableDescription tableDescription, ColumnDescription columnDescription)
          Contructs a new instance for the specified table and column.
 
Method Summary
 void bindNonNullValue(java.sql.PreparedStatement statement, int variableIndex, java.lang.Object value)
          This method binds an empty CLOB locator to the specified index in the specified statement.
 int getNullType()
          Oracle returns the constant java.sql.Types.OTHER for CLOB columns, and bizarrely, this can not be used when binding null values in prepared statements.
 boolean isCharacterData()
          Always returns true.
 java.lang.Object loadValue(java.sql.ResultSet resultSet, int columnIndex)
          Returns a DataHighBitAnalysis instance with the text loaded from the specified column from the specified result set, if non-null.
 java.lang.String printNonNullValue(java.lang.Object value)
          Returns a representation of the specified value (which should be a DataHighBitAnalysis instance) that is appropriate for inclusion in a SQL script.
protected  void writeLobValue(java.sql.ResultSet results, java.lang.Object newLobValue)
          This method is responsible for writing the specified LOB value (which is a string) to the first column in the specified result set, which should contain a newly initialized CLOB locator.
 
Methods inherited from class org.afcs.warts.handlers.LobDataHandlerSupport
postProcessBind, requiresBindPostProcessing, requiresStreamedLoading
 
Methods inherited from class org.afcs.warts.handlers.DataHandlerSupport
getColumnDescription, getTableDescription, isNullHandler, loadBytesFromStream, logWrongValueTypeWarning, 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
isNullHandler, postProcessBind, requiresBindPostProcessing, requiresStreamedLoading
 

Constructor Detail

OracleClobHandler

public OracleClobHandler(TableDescription tableDescription,
                         ColumnDescription columnDescription)
Contructs a new instance for the specified table and column. The full table description is needed so that SQL statements can be generated for writing CLOB data.

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 variableIndex,
                             java.lang.Object value)
                      throws java.sql.SQLException
This method binds an empty CLOB locator to the specified index in the specified statement. The specified value is ignored.

Specified by:
bindNonNullValue in interface DataHandler
Parameters:
statement - The statement to bind the value in.
variableIndex - The index of the variable to bind.
value - The value to bind to the statement (always ignored).
Throws:
java.sql.SQLException - If a SQL error occurs during binding.

getNullType

public int getNullType()
Oracle returns the constant java.sql.Types.OTHER for CLOB columns, and bizarrely, this can not be used when binding null values in prepared statements. This method overrides the default behaviour always returning java.sql.Types.CLOB. See my post to Oracle's JDBC forum for more information.

Specified by:
getNullType in interface DataHandler
Overrides:
getNullType in class DataHandlerSupport
Returns:
Always java.sql.Types.CLOB.

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
Returns a DataHighBitAnalysis instance with the text loaded from the specified column from the specified result set, if non-null. The method used to load the string depends on whether the account configuration from which the table was loaded specifies that the account was to a UTF-8 database or not, with a binary load being done in non-UTF8 databases to ensure that non-ascii characters are properly obtained.

Specified by:
loadValue in interface DataHandler
Parameters:
resultSet - The result set to load data from.
columnIndex - The index of the column to load data from.
Returns:
A DataHighBitAnalysis object or null.
Throws:
java.sql.SQLException - If a SQL exception occurs while loading data.

printNonNullValue

public java.lang.String printNonNullValue(java.lang.Object value)
Returns a representation of the specified value (which should be a DataHighBitAnalysis instance) that is appropriate for inclusion in a SQL script.

Specified by:
printNonNullValue in interface DataHandler
Parameters:
value - The object value to print.
Returns:
A string containing a representation of the specified value appropriate for use in a SQL script.

writeLobValue

protected void writeLobValue(java.sql.ResultSet results,
                             java.lang.Object newLobValue)
                      throws java.sql.SQLException
This method is responsible for writing the specified LOB value (which is a string) to the first column in the specified result set, which should contain a newly initialized CLOB locator.

Specified by:
writeLobValue in class LobDataHandlerSupport
Parameters:
results - The result set containing the CLOB locator.
newLobValue - The new LOB value.
Throws:
java.sql.SQLException - If a SQL error occurs during update.