org.afcs.warts.handlers
Class DecimalHandler

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

public final class DecimalHandler
extends DataHandlerSupport
implements DataHandler

The DecimalHandler class handles decimal data. The object returned by loadValue(java.sql.ResultSet, int), and expected by bindValue() and printValue() is a java.match.BigDecimal instance.

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

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

Constructor Summary
DecimalHandler(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 variableIndex, java.lang.Object value)
          This method binds the specified non-null value (which should be a java.math.BigDecimal instance) to the specified index in the specified statement.
 int getNullType()
          Oracle returns the constant java.sql.Types.OTHER for FLOAT columns, and bizarrely, this can not be used when binding null values in prepared statements.
 java.lang.Object loadValue(java.sql.ResultSet resultSet, int columnIndex)
          Returns a java.math.BigDecimal instance with the decimal value of the specified column from the specified result set, if non-null.
 java.lang.String printNonNullValue(java.lang.Object value)
          Returns the result of value.toString(), which means avoiding having to cast the object to a java.math.BigDecimal.
 
Methods inherited from class org.afcs.warts.handlers.DataHandlerSupport
getColumnDescription, getTableDescription, isCharacterData, 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
isCharacterData, isNullHandler, postProcessBind, requiresBindPostProcessing, requiresStreamedLoading
 

Constructor Detail

DecimalHandler

public DecimalHandler(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 variableIndex,
                             java.lang.Object value)
                      throws java.sql.SQLException
This method binds the specified non-null value (which should be a java.math.BigDecimal instance) to the specified index in the specified statement. A warning message is logged if the value is not a BigDecimal.

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.
Throws:
java.sql.SQLException - If a SQL error occurs during binding.

getNullType

public int getNullType()
Oracle returns the constant java.sql.Types.OTHER for FLOAT 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.DECIMAL. See my post to Oracle's JDBC forum.

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

loadValue

public java.lang.Object loadValue(java.sql.ResultSet resultSet,
                                  int columnIndex)
                           throws java.sql.SQLException
Returns a java.math.BigDecimal instance with the decimal value of the specified column from the specified result set, if non-null.

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 BigDecimal instance 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 the result of value.toString(), which means avoiding having to cast the object to a java.math.BigDecimal.

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.