View Javadoc

1   /*   Copyright (C) 2004 Finalist IT Group
2    *
3    *   This file is part of JAG - the Java J2EE Application Generator
4    *
5    *   JAG is free software; you can redistribute it and/or modify
6    *   it under the terms of the GNU General Public License as published by
7    *   the Free Software Foundation; either version 2 of the License, or
8    *   (at your option) any later version.
9    *   JAG is distributed in the hope that it will be useful,
10   *   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   *   GNU General Public License for more details.
13   *   You should have received a copy of the GNU General Public License
14   *   along with JAG; if not, write to the Free Software
15   *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16   */
17  
18  package com.finalist.tools.database;
19  
20  import java.sql.*;
21  import java.util.*;
22  
23  /***
24   * Abstract class that database specific RowMappers should extend.
25   *
26   * @author  P.S.D.Reitsma, Finalist IT Group
27   * @version 1.0
28   */
29  public abstract class RowMapper {
30  
31     /***
32      * Method that binds an object of a specified type into a PreparedStatement and returns the PreparedStatement.
33      *
34      * @return PreparedStatement the resulting PreparedStatement after the bind has happened.
35      * @param pstmt PreparedStatement to which the object should be bound.
36      * @param bindVar the object that is to be bound.
37      * @param bindVarClassType the full classname that identifies the type of the class
38      * @param pos the position at which the object should be bound into the statement.
39      * @throws NotMappableException when no appropriate bind method could be found
40      * @throws SQLException
41      */
42     public abstract PreparedStatement bind(PreparedStatement pstmt, Object bindVar, String bindVarClassType, int pos) throws SQLException, NotMappableException;
43  
44  
45     /***
46      * Method that reads the values from a ResultSet for one row and stores them into a HashMap.
47      *
48      * @return the resulting HashMap
49      * @param rset the resultset that serves a source
50      * @param target the HashMap in which the values will be stored
51      * @throws NotMappableException when no appropriate unbind method could be found
52      * @throws SQLException
53      */
54     public abstract HashMap unBindIntoHashMap(ResultSet rset, HashMap target) throws SQLException, NotMappableException;
55  
56  
57     /***
58      * Method that reads the values from a ResultSet an populates the properties of a bean
59      *
60      * @return the resulting bean
61      * @param rset the resultset that serves a source
62      * @param target the bean of which the properties should be set
63      * @throws NotMappableException when no appropriate unbind method could be found
64      * @throws SQLException
65      */
66     public abstract Object unBindIntoBean(ResultSet rset, Object target) throws SQLException, NotMappableException;
67  }
68