com.finalist.tools.database
Class OracleRowMapper

java.lang.Object
  extended bycom.finalist.tools.database.RowMapper
      extended bycom.finalist.tools.database.OracleRowMapper

public class OracleRowMapper
extends RowMapper

Implementation of the rowmapper for Oracle. This class has been tested against Oracle 8.1.7 and 8.2.

Author:
P.S.D.Reitsma, Michael O'Connor - Finalist IT Group

Constructor Summary
OracleRowMapper()
           
 
Method Summary
 java.sql.PreparedStatement bind(java.sql.PreparedStatement pstmt, java.lang.Object bindVar, java.lang.String bindVarClassType, int pos)
          Method that binds an object of a specified type into a PreparedStatement and returns the PreparedStatement.
static java.util.ArrayList convertDatatypes(java.util.ArrayList columnList)
          converts datatypes from oracle specific to java specific types.
 java.lang.Object unBindIntoBean(java.sql.ResultSet rset, java.lang.Object target)
          Method reads the values from a ResultSet and puts them as properties into a bean.
 java.util.HashMap unBindIntoHashMap(java.sql.ResultSet rset, java.util.HashMap target)
          Method reads the values from a ResultSet and puts them as properties into a HashMap.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OracleRowMapper

public OracleRowMapper()
Method Detail

bind

public java.sql.PreparedStatement bind(java.sql.PreparedStatement pstmt,
                                       java.lang.Object bindVar,
                                       java.lang.String bindVarClassType,
                                       int pos)
                                throws java.sql.SQLException,
                                       NotMappableException
Method that binds an object of a specified type into a PreparedStatement and returns the PreparedStatement. The following mappings are made.
Input Type Method used NullType used
String setString() java.sql.Types.VARCHAR
int/Integer setInt() java.sql.Types.Numeric
byte/Byte setByte() java.sql.Types.Numeric
short/Short setShort() java.sql.Types.Numeric
float/Float setFloat() java.sql.Types.Numeric
long/Long setLong() java.sql.Types.Numeric
double/Double setDouble() java.sql.Types.Numeric
util.Date setDate() java.sql.Types.Date
util.Calendar setDate() java.sql.Types.Date

Specified by:
bind in class RowMapper
Parameters:
pstmt - PreparedStatement to which the object should be bound.
bindVar - the object that is to be bound.
bindVarClassType - the full classname that identifies the type of the class
pos - the position at which the object should be bound into the statement.
Returns:
PreparedStatement the resulting PreparedStatement after the bind has happened.
Throws:
NotMappableException - when no appropriate bind method could be found
java.sql.SQLException

unBindIntoHashMap

public java.util.HashMap unBindIntoHashMap(java.sql.ResultSet rset,
                                           java.util.HashMap target)
                                    throws java.sql.SQLException,
                                           NotMappableException
Method reads the values from a ResultSet and puts them as properties into a HashMap. The keys of the HashMap will be the column aliases of the SQL-Statement and the values will be java Objects. The following conversions rules are valid:
Oracle DatatypeJava Object type
VARCHAR2 String
DATE java.sql.Timestamp
NUMBER(<3,0) Byte
NUMBER(>2 <6,0) Short
NUMBER(>5 <10,0) Integer
NUMBER(>9 <19,0) Long
NUMBER( (scale and precision)<13) Float
NUMBER( (scale and precision)>12) Double
CHAR String
Date java.util.Date
TODO: more mappings could be made.

Specified by:
unBindIntoHashMap in class RowMapper
Parameters:
rset - ResultSet
target - The HashMap in which the values are stored
Returns:
the resulting HashMap
Throws:
java.sql.SQLException - thrown when some SQL related error occurs.
NotMappableException - thrown when no appropriate mapping could be found to map a SQL datatype to a Java counterpart.

unBindIntoBean

public java.lang.Object unBindIntoBean(java.sql.ResultSet rset,
                                       java.lang.Object target)
                                throws java.sql.SQLException,
                                       NotMappableException
Method reads the values from a ResultSet and puts them as properties into a bean. The column-property mapping happens through the use of column aliases in the SQL Statement. The column aliases should map to a property name. The mapping is not case sensitive. TODO: need for more mapping might arise.

Specified by:
unBindIntoBean in class RowMapper
Parameters:
rset - ResultSet
target - The bean whose properties should be set.
Returns:
the resulting bean
Throws:
java.sql.SQLException - thrown when some SQL related error occurs.
NotMappableException - thrown when no appropriate mapping could be found to map a SQL datatype to a Java counterpart.

convertDatatypes

public static java.util.ArrayList convertDatatypes(java.util.ArrayList columnList)
converts datatypes from oracle specific to java specific types.

Parameters:
columnList - ArrayList filled with hashMaps. HashMap consists of name, type, scale and precision.
Returns:
columnList with altered datatypes


Copyright © 2003-2004 SourceForge. All Rights Reserved.