OOP SimpleDaoHelper Version 1.2

com.bentofw.dao
Class SimpleDaoHelperImpl

java.lang.Object
  extended by com.bentofw.dao.SimpleDaoHelperImpl
All Implemented Interfaces:
SimpleDaoHelper
Direct Known Subclasses:
DaoHelperForJdbc, DaoHelperForJndi, DaoHelperForPooledStatement

public abstract class SimpleDaoHelperImpl
extends java.lang.Object
implements SimpleDaoHelper

The abstract super class for the implementation of SimpleDaoHelper interface.

The 3 implementations of SimpleDaoHelper interface are available in this package. They are:

And all of these implementations are the sub-class of this abstract class. In usual, you need not be concerned with this class.

Author:
Jun Inamori

Constructor Summary
SimpleDaoHelperImpl()
           
 
Method Summary
abstract  void closeResource(java.sql.ResultSet res, java.sql.PreparedStatement ps, java.sql.Connection con, boolean isOK)
          Close the specified ResultSet, PreparedStatement and Connection.
abstract  java.sql.Connection getConnection()
          Return the JDBC Connection.
abstract  java.sql.PreparedStatement getPrepareStatement(java.sql.Connection con, java.lang.String sql)
          Return the JDBC PreparedStatement for the given SQL statement.
 java.util.List select(QueryData data, int[] return_types)
          Based on the given QueryData object, this method executes PreparedStatement.
 int update(QueryData data)
          Based on the given QueryData object, this method executes PreparedStatement.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleDaoHelperImpl

public SimpleDaoHelperImpl()
Method Detail

getConnection

public abstract java.sql.Connection getConnection()
                                           throws java.sql.SQLException
Return the JDBC Connection. How to get the Connection depends on the implementation.

In case that you use DaoHelperForJndi, this method queries Connection on the JNDI DataSource. If you use DaoHelperForJdbc, Connection is created from DriverManager each time this method is called. Or, when DaoHelperForPooledStatement is used, this method returns null, because OOP PooledStatement keeps the Connection in its pool along with the PreparedStatement.

Specified by:
getConnection in interface SimpleDaoHelper
Returns:
Connection
Throws:
java.sql.SQLException

getPrepareStatement

public abstract java.sql.PreparedStatement getPrepareStatement(java.sql.Connection con,
                                                               java.lang.String sql)
                                                        throws java.sql.SQLException
Return the JDBC PreparedStatement for the given SQL statement.

In case that you use DaoHelperForJndi or DaoHelperForJdbc, this method creates PreparedStatement from the specified Connection.

If you use DaoHelperForPooledStatement, this method picks the PreparedStatement from the pool of OOP PooledStatement. Because Connection is always null, please specify null as the first parameter.

Specified by:
getPrepareStatement in interface SimpleDaoHelper
Parameters:
con - JDBC Connection
sql - SQL statement
Returns:
PreparedStatement
Throws:
java.sql.SQLException

closeResource

public abstract void closeResource(java.sql.ResultSet res,
                                   java.sql.PreparedStatement ps,
                                   java.sql.Connection con,
                                   boolean isOK)
Close the specified ResultSet, PreparedStatement and Connection.

In case that you use DaoHelperForJndi or DaoHelperForJdbc, this method calls close method on them.

If you use DaoHelperForPooledStatement, this method closes only ResultSet. And PreparedStatement will be pushed back to the pool of OOP PooledStatement. As for Connection, this method does nothing, because it is always null.

Specified by:
closeResource in interface SimpleDaoHelper
Parameters:
res - ResultSet
ps - PreparedStatement
con - Connection
isOK - This parameter will be used only by DaoHelperForPooledStatement, because the PreparedStatement should not be pushed back to the pool if something is wrong. But, to make your code portable between the implementations, please specify the correct value. If SQLException is thrown while playing with PreparedStatement, please specify false. Otherwise, true.

select

public java.util.List select(QueryData data,
                             int[] return_types)
                      throws java.sql.SQLException,
                             SimpleException
Based on the given QueryData object, this method executes PreparedStatement.

Specified by:
select in interface SimpleDaoHelper
Parameters:
data - QueryData object.
return_types - The int array which consists of the pre-defined int constants.
Returns:
List object which includes List objects, each of which represents the selected row.
Throws:
java.sql.SQLException
SimpleException

update

public int update(QueryData data)
           throws java.sql.SQLException,
                  SimpleException
Based on the given QueryData object, this method executes PreparedStatement.

Specified by:
update in interface SimpleDaoHelper
Parameters:
data - QueryData object.
Returns:
int value returned from PreparedStatement.
Throws:
java.sql.SQLException
SimpleException

OOP SimpleDaoHelper Version 1.2

ALL CONTENTS COPYRIGHT 2005, OOP-Research Corporation. All rights reserved.
Any questions and comments are welcome to OOP-Research Corporation.