|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Interface for modules that are used by the DAO's fetch calls to prepare and execute SQL statements.
A custom imlpementation of FetchExecutor
can be installed to
the DAO as a DAO plugin. Only one such plugin is allowed for a DAO. By
default, if no custom FetchExecutor
plugin is installed, the
DAO uses GenericFetchExecutor
.
Unlike many other DAO plugin types, the DAO does not allow concurrent threads into the same instance of the fetch executor. Also, the fetch executor can be stateful - the DAO guarantees that single instance will be used during one fetch call.
Here is the protocol of how the DAO calls the fetch executor:
FetchExecutor
implementation (
GenericFetchExecutor
by default) is taken from the pool. Then
the init
method is called on it and the fetch call parameters
are passed to it so it can initialize its internals.prepareStatement
is called and it returns the
java.sql.Statement
object to be executed by the DAO. If there
are query parameters, then the method must return an instance of
java.sql.PreparedStatement
, so the DAO can set the parameters
on it.QueryParamProcessor and
QueryParamSetter
plugins are, if defined for the DAO).
execute
is called and the fetch executor actually
executes the query, which returnes a result set. The result set is stored
then internally in the fetch executor.getResultSet
is called and it
returns a reference to the just fetched result set.setToTheFirstRow
is called.true
, then the DAO processes
the result set rows, and, when it is finished, it calls finish
method on the fetch executor. Otherwise, if the
setToTheFirstRow
call returned false
, this step is
skipped and the finish
method is never called.destroy
method is called and the fetch executor
instance is returned back to the pool. Note, that the destroy
method gets called always, even if there were exceptions thrown by other
methods.
DAO.fetch(String, Set, Object [], String [], int, int, int, FetchResultProcessorHandler [], FetchResultDescriptor)
Method Summary | |
void |
destroy()
Releases any used resources, but does not close any exposed to the DAO database resources like the result set, the statement returned by the execute method and the
connection. |
java.sql.Statement |
execute()
Executes the query and returns the statement, which was actually used for getting the result set (possibly a different statement from what prepareStatement returned). |
void |
finish(int nRowsProcessed,
java.util.List result)
Called after everything has been processed and the resulting array of DMs formed. |
java.sql.ResultSet |
getResultSet()
Gets the result set after execute method call. |
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 before calling any other methods. |
java.sql.Statement |
prepareStatement()
Prepares a statement object before the execute method call. |
boolean |
setToTheFirstRow()
Positions the result set cursor to the first row of the requested data. |
Methods inherited from interface com.boylesoftware.cb2.DAOPlugin |
setApplicationContext |
Method Detail |
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) throws java.sql.SQLException
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.
java.sql.SQLException
- if the executor cannot be initialized.public java.sql.Statement prepareStatement() throws java.sql.SQLException
execute
method call.
Note, that if the query requires parameters, that is the
queryParams
passed to the init
method was not
null
and not empty, then this method is required to return
an instance of java.sql.PreparedStatement
, so the DAO can
set query parameters on it before calling execute
.
java.sql.PreparedStatement
.
java.sql.SQLException
- if a database error happens.public java.sql.Statement execute() throws java.sql.SQLException
prepareStatement
returned). The getResultSet
method is called later to retrieve the result set.
java.sql.SQLException
- if a database error happens.public java.sql.ResultSet getResultSet()
execute
method call.
public boolean setToTheFirstRow() throws java.sql.SQLException
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).
java.sql.SQLException
- if a database error happens.public void finish(int nRowsProcessed, java.util.List result) throws java.sql.SQLException
setToTheFirstRow
returned false
.
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.
java.sql.SQLException
- if a database error happens.public void destroy()
execute
method and the
connection.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |