com.boylesoftware.cb2
Class GenericFetchExecutor

java.lang.Object
  extended bycom.boylesoftware.cb2.GenericFetchExecutor
All Implemented Interfaces:
DAOPlugin, FetchExecutor
Direct Known Subclasses:
NoCursorFetchExecutor

public class GenericFetchExecutor
extends java.lang.Object
implements FetchExecutor

Generic FetchExecutor implementation used by the DAO by default when no other DAO plugin implementing FetchExecutor interface is installed. This implementation uses JDBC scrollable result sets for paginated results. In general, it tries to use the most standard JDBC features to implement functionality.

Version:
$Id: GenericFetchExecutor.java,v 1.5 2004/04/20 16:00:58 levahim Exp $
Author:
Lev Himmelfarb

Field Summary
protected  ApplicationContext appCtx
          The application context.
protected  java.sql.Connection con
          The database connection.
protected  DAOConfig daoConfig
          The DAO configuration.
protected  FetchResultDescriptor fetchResultDescriptor
          Reference to the fetch result descriptor instance passed to the DAO for the call.
protected  int page
          Requested page starting from zero.
protected  int pageSize
          Requested page size.
protected  java.lang.String query
          Text of the SQL query to be executed.
protected  java.lang.Object[] queryParams
          The query parameters as passed to the DAO.
protected  java.sql.ResultSet rs
          The result set object.
protected  java.sql.Statement stmt
          The statement object.
protected  boolean usePreparedStatement
          Set to true if the stmt is an instance of java.sql.PreparedStatement.
 
Constructor Summary
GenericFetchExecutor()
           
 
Method Summary
 void destroy()
          Sets null to all internal member variables.
 java.sql.Statement execute()
          Executes the stmt statement and sets the rs member variable.
 void finish(int nRowsProcessed, java.util.List result)
          Finishes query execution and result set processing and sets up fetch result descriptor in fetchResultDescriptor member variable if it is not null.
 java.sql.ResultSet getResultSet()
          Gets the result set.
 void init(DAOConfig daoConfig, java.sql.Connection con, java.lang.Class dmClass, java.lang.String query, java.lang.Object[] queryParams, int page, int pageSize, FetchResultDescriptor fetchResultDescriptor)
          Initializes the executor setting up internal member variables.
 java.sql.Statement prepareStatement()
          Creates a statement object.
 void setApplicationContext(ApplicationContext appCtx)
          Sets the application context.
 boolean setToTheFirstRow()
          Positions the result set cursor to the first row of the requested data.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

appCtx

protected ApplicationContext appCtx
The application context.


daoConfig

protected DAOConfig daoConfig
The DAO configuration. Set by the init method.


con

protected java.sql.Connection con
The database connection. Set by the init method.


query

protected java.lang.String query
Text of the SQL query to be executed. Set by the init method.


queryParams

protected java.lang.Object[] queryParams
The query parameters as passed to the DAO. Set by the init method.


page

protected int page
Requested page starting from zero. Set by the init method.


pageSize

protected int pageSize
Requested page size. Is less or equal to zero if no result set pagination is requested. Set by the init method.


fetchResultDescriptor

protected FetchResultDescriptor fetchResultDescriptor
Reference to the fetch result descriptor instance passed to the DAO for the call. May be null. Set by the init method.


stmt

protected java.sql.Statement stmt
The statement object.


usePreparedStatement

protected boolean usePreparedStatement
Set to true if the stmt is an instance of java.sql.PreparedStatement.


rs

protected java.sql.ResultSet rs
The result set object.

Constructor Detail

GenericFetchExecutor

public GenericFetchExecutor()
Method Detail

setApplicationContext

public void setApplicationContext(ApplicationContext appCtx)
Sets the application context.

Specified by:
setApplicationContext in interface DAOPlugin
Parameters:
appCtx - the application context.

init

public void init(DAOConfig daoConfig,
                 java.sql.Connection con,
                 java.lang.Class dmClass,
                 java.lang.String query,
                 java.lang.Object[] queryParams,
                 int page,
                 int pageSize,
                 FetchResultDescriptor fetchResultDescriptor)
Initializes the executor setting up internal member variables.

Specified by:
init in interface FetchExecutor
Parameters:
daoConfig - the DAO configuration.
con - the database connection to be used.
dmClass - class of the top-level DMs to be returned by the call.
query - the SQL query text.
queryParams - values for the query parameters, null or empty array if the query needs no parameters.
page - number of the result set page requested, starting from zero.
pageSize - number of records in one result set page, equal or less than zero if result set pagination is not requested.
fetchResultDescriptor - the FetchResultDescriptor instance or null if no result info requested.

prepareStatement

public java.sql.Statement prepareStatement()
                                    throws java.sql.SQLException
Creates a statement object. This method sets the stmt member variable.

Specified by:
prepareStatement in interface FetchExecutor
Returns:
the statement object, which may be an instance of java.sql.PreparedStatement.
Throws:
java.sql.SQLException - if a JDBC error happens.

execute

public java.sql.Statement execute()
                           throws java.sql.SQLException
Executes the stmt statement and sets the rs member variable.

Specified by:
execute in interface FetchExecutor
Returns:
the statement owning the result set.
Throws:
java.sql.SQLException - if a JDBC error happens.

getResultSet

public java.sql.ResultSet getResultSet()
Gets the result set.

Specified by:
getResultSet in interface FetchExecutor
Returns:
result set with the requested data.

setToTheFirstRow

public boolean setToTheFirstRow()
                         throws java.sql.SQLException
Positions the result set cursor to the first row of the requested data.

Specified by:
setToTheFirstRow in interface FetchExecutor
Returns:
true if the cursor has been set or false if there is not data (for example the result set is empty or the requested page does not exist).
Throws:
java.sql.SQLException - if a JDBC error happens.

finish

public void finish(int nRowsProcessed,
                   java.util.List result)
Finishes query execution and result set processing and sets up fetch result descriptor in fetchResultDescriptor member variable if it is not null.

Specified by:
finish in interface FetchExecutor
Parameters:
nRowsProcessed - number of result set rows processed by the DAO.
result - the result, which will be returned by the DAO to the caller as a java.util.List of DMs.

destroy

public void destroy()
Sets null to all internal member variables.

Specified by:
destroy in interface FetchExecutor


Copyright © 2002,2003,2004 - Boyle Software, Inc.