OOP SimpleDaoHelper Version 1.2

com.bentofw.dao
Class DaoHelperForJndi

java.lang.Object
  extended by com.bentofw.dao.SimpleDaoHelperImpl
      extended by com.bentofw.dao.DaoHelperForJndi
All Implemented Interfaces:
SimpleDaoHelper

public class DaoHelperForJndi
extends SimpleDaoHelperImpl

Implementation of SimpleDaoHelper interface. This class creates PreparedStatement from JNDI DataSource.

To use this implementation, the JNDI DataSource must be found by:

within your J2EE environment. And the res-auth element of this JNDI DataSource must be Container. Then, the constructor of this implementation can look up the intended JNDI DataSource and can obtain the JDBC Connection from it.

Author:
Jun Inamori
See Also:
SimpleDaoHelper

Constructor Summary
DaoHelperForJndi()
          The constructor.
 
Method Summary
 void closeResource(java.sql.ResultSet res, java.sql.PreparedStatement ps, java.sql.Connection con, boolean isOK)
          Close the specified ResultSet, PreparedStatment and Connection.
 java.sql.Connection getConnection()
          Return the JDBC Connection.
 java.sql.PreparedStatement getPrepareStatement(java.sql.Connection con, java.lang.String sql)
          Return the JDBC PreparedStatement for the given SQL statement.
 
Methods inherited from class com.bentofw.dao.SimpleDaoHelperImpl
select, update
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DaoHelperForJndi

public DaoHelperForJndi()
                 throws NestedException,
                        SimpleException
The constructor.

Throws:
NestedException
SimpleException
Method Detail

getConnection

public java.sql.Connection getConnection()
                                  throws java.sql.SQLException
Return the JDBC Connection. This method queries Connection on the JNDI DataSource.

The implementation of the JNDI DataSource depends on the environment. If your J2EE environment implements the JNDI DataSource with the pooling mechanism, the Connection will be picked up from its pool and you can get the better performance.

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

getPrepareStatement

public 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.

This method creates PreparedStatement from the specified Connection.

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

closeResource

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

This method calls close method on them. The implementation of the JNDI DataSource depends on the environment. If your J2EE environment implements the JNDI DataSource with the pooling mechanism, the Connection will be pushed back to the pool and its connection will not be closed actually.

Specified by:
closeResource in interface SimpleDaoHelper
Specified by:
closeResource in class SimpleDaoHelperImpl
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.

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.