com.finalist.tools.database
Class PostgreSQLRowMapper

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

public class PostgreSQLRowMapper
extends RowMapper

Implementation of the rowmapper for PostgreSQL.

Version:
$Revision: 1.1 $, $Date: 2004/03/01 19:52:45 $
Author:
Hillebrand Gelderblom, Finalist IT Group

Constructor Summary
PostgreSQLRowMapper(java.sql.Connection conn)
          constuctor
 
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 PostgreSQL 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

PostgreSQLRowMapper

public PostgreSQLRowMapper(java.sql.Connection conn)
constuctor

Parameters:
conn - connection to the database
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 - An exception that provides information on a database access error or other errors.

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.util.Date
NUMBER(<3LargeObjectManager lobj = ((org.postgresql.PGConnection)conn).getLargeObjectAPI(); ,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

Specified by:
unBindIntoHashMap in class RowMapper
Parameters:
rset - ResultSet
target - The HashMap in which the values are stored
Returns:
Hashmap with query results
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.

Specified by:
unBindIntoBean in class RowMapper
Parameters:
rset - ResultSet
target - The bean whose properties should be set.
Returns:
Bean with query results
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 PostgreSQL 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.