org.apache.cocoon.components.language.markup.xsp
Class AbstractEsqlQuery

java.lang.Object
  extended by org.apache.avalon.framework.logger.AbstractLogEnabled
      extended by org.apache.cocoon.components.language.markup.xsp.AbstractEsqlQuery
All Implemented Interfaces:
LogEnabled
Direct Known Subclasses:
JdbcEsqlQuery, MysqlEsqlQuery, OracleEsqlQuery, PervasiveEsqlQuery, PostgresEsqlQuery, PostgresOldEsqlQuery, SybaseEsqlQuery

public abstract class AbstractEsqlQuery
extends AbstractLogEnabled

This is base class for all EsqlQueries

Version:
CVS $Id: AbstractEsqlQuery.html 1304258 2012-03-23 10:09:27Z ilgrosso $
Author:
Torsten Curdt

Constructor Summary
protected AbstractEsqlQuery(Connection connection, String query)
          Constructor
protected AbstractEsqlQuery(ResultSet resultSet)
          Only newInstance may use this contructor
 
Method Summary
 void cleanUp()
          Clean up all database resources used by the query.
 void decGroupLevel()
           
 boolean execute()
           
 boolean execute(int resultSetFromObject)
           
 boolean executeQuery()
           
 CallableStatement getCallableStatement()
           
 Connection getConnection()
           
 int getCurrentRow()
           
 int getMaxRows()
           
 boolean getMoreResults()
          Try to get the next ResultSet
 PreparedStatement getPreparedStatement()
           
 int getQueryResultsCount()
          Returns the number of query results
 String getQueryString()
          Return the query string ("select * from bla") NOTE: Might want to be overridden by indiviual EsqlQuery implementations e.g. for database specific LIMIT features.
 void getResultRows()
          Move to the first row.
 ResultSet getResultSet()
           
 ResultSetMetaData getResultSetMetaData()
           
 int getRowCount()
          Gets the total number of rows of a the query WITHOUT the limits of skip/max rows.
 int getSkipRows()
           
 int getUpdateCount()
          Returns the how many rows where updated on last update
 int getUpdateResultsCount()
          Returns the number of update results
 boolean groupLevelExists()
           
 boolean hasGroupingVarChanged()
           
 boolean hasResultSet()
           
 void incGroupLevel()
           
 boolean keepGoing()
           
abstract  AbstractEsqlQuery newInstance(ResultSet resultSet)
          Create a EsqlQuery of the same type
 boolean nextRow()
           
 CallableStatement prepareCall()
          NOTE: Might want to be overridden by indiviual EsqlQuery implementations
 PreparedStatement prepareStatement()
          NOTE: Might want to be overridden by indiviual EsqlQuery implementations
 void setGroupingVar(String key)
           
 void setKeepGoing(boolean still)
           
 void setMaxRows(int i)
           
protected  void setPosition(int p)
           
protected  PreparedStatement setPreparedStatement(PreparedStatement ps)
           
 void setSkipRows(int i)
           
 
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractEsqlQuery

protected AbstractEsqlQuery(Connection connection,
                            String query)
Constructor

Parameters:
connection -
query - - The SQL query string

AbstractEsqlQuery

protected AbstractEsqlQuery(ResultSet resultSet)
Only newInstance may use this contructor

Parameters:
resultSet -
Method Detail

newInstance

public abstract AbstractEsqlQuery newInstance(ResultSet resultSet)
Create a EsqlQuery of the same type

Parameters:
resultSet -

getQueryString

public String getQueryString()
                      throws SQLException
Return the query string ("select * from bla") NOTE: Might want to be overridden by indiviual EsqlQuery implementations e.g. for database specific LIMIT features. Be aware that there a two different limit approaches:
 retrieve                   query
 time                       time
 +---------+                ...........
 |JDBC     |                :         :
 |ResultSet|                :         :
 |.........|-+              :_________:_
 |         | | skip/max+1   |JDBC     | | skip/max+1
 |         | | window       |ResultSet| | window
 |.........| |              |_________| |
 |         |-+              :         :_|
 |         |                :         :
 +---------+                :.........:
  
With the "retrieve time" limit the JDBC ResultSet includes ALL of the rows of the query. With the "query time" limit only a small window of rows are in the actuall JDBC ResultSet. In order to know whether there are more rows available (without an additional query) we need to have at least one more row in the JDBC ResultSet. So we ask for getMaxRows()+1

Throws:
SQLException

prepareStatement

public PreparedStatement prepareStatement()
                                   throws SQLException
NOTE: Might want to be overridden by indiviual EsqlQuery implementations

Throws:
SQLException

prepareCall

public CallableStatement prepareCall()
                              throws SQLException
NOTE: Might want to be overridden by indiviual EsqlQuery implementations

Throws:
SQLException

getRowCount

public int getRowCount()
                throws SQLException
Gets the total number of rows of a the query WITHOUT the limits of skip/max rows. NOTE: Might want to be overridden by indiviual EsqlQuery implementations

Returns:
total number of rows
Throws:
SQLException

getResultRows

public void getResultRows()
                   throws SQLException
Move to the first row. NOTE: Might want to be overridden by indiviual EsqlQuery implementations

Throws:
SQLException

cleanUp

public void cleanUp()
Clean up all database resources used by the query. In particular, close result sets and statements.


setPosition

protected final void setPosition(int p)

setPreparedStatement

protected final PreparedStatement setPreparedStatement(PreparedStatement ps)

getConnection

public final Connection getConnection()

getSkipRows

public final int getSkipRows()

setSkipRows

public final void setSkipRows(int i)

getMaxRows

public final int getMaxRows()

setMaxRows

public final void setMaxRows(int i)

getResultSetMetaData

public final ResultSetMetaData getResultSetMetaData()

getPreparedStatement

public final PreparedStatement getPreparedStatement()

getCallableStatement

public final CallableStatement getCallableStatement()

getResultSet

public final ResultSet getResultSet()

nextRow

public final boolean nextRow()
                      throws SQLException
Throws:
SQLException

getCurrentRow

public final int getCurrentRow()

execute

public final boolean execute(int resultSetFromObject)
                      throws SQLException
Throws:
SQLException

execute

public final boolean execute()
                      throws SQLException
Throws:
SQLException

executeQuery

public final boolean executeQuery()
                           throws SQLException
Throws:
SQLException

getMoreResults

public final boolean getMoreResults()
                             throws SQLException
Try to get the next ResultSet

Returns:
whether there is one or not
Throws:
SQLException

hasResultSet

public final boolean hasResultSet()

getUpdateCount

public final int getUpdateCount()
Returns the how many rows where updated on last update


getQueryResultsCount

public final int getQueryResultsCount()
Returns the number of query results


getUpdateResultsCount

public final int getUpdateResultsCount()
Returns the number of update results


keepGoing

public final boolean keepGoing()

setKeepGoing

public final void setKeepGoing(boolean still)

incGroupLevel

public final void incGroupLevel()

decGroupLevel

public final void decGroupLevel()

groupLevelExists

public final boolean groupLevelExists()

setGroupingVar

public final void setGroupingVar(String key)
                          throws SQLException
Throws:
SQLException

hasGroupingVarChanged

public final boolean hasGroupingVarChanged()
                                    throws SQLException
Throws:
SQLException


Copyright © 1999-2010 The Apache Software Foundation. All Rights Reserved.