org.postgresql.core.v2
Class QueryExecutorImpl

java.lang.Object
  extended by org.postgresql.core.v2.QueryExecutorImpl
All Implemented Interfaces:
QueryExecutor

public class QueryExecutorImpl
extends java.lang.Object
implements QueryExecutor

QueryExecutor implementation for the V2 protocol.


Field Summary
 
Fields inherited from interface org.postgresql.core.QueryExecutor
QUERY_DESCRIBE_ONLY, QUERY_FORWARD_CURSOR, QUERY_NO_METADATA, QUERY_NO_RESULTS, QUERY_ONESHOT, QUERY_SUPPRESS_BEGIN
 
Constructor Summary
QueryExecutorImpl(org.postgresql.core.v2.ProtocolConnectionImpl protoConnection, PGStream pgStream, Logger logger)
           
 
Method Summary
 ParameterList createFastpathParameters(int count)
          Create a new ParameterList implementation suitable for invoking a fastpath function via QueryExecutor.fastpathCall(int, org.postgresql.core.ParameterList, boolean).
 Query createParameterizedQuery(java.lang.String sql)
          Create a parameterized Query object suitable for execution by this QueryExecutor.
 Query createSimpleQuery(java.lang.String sql)
          Create an unparameterized Query object suitable for execution by this QueryExecutor.
 void execute(Query[] queries, ParameterList[] parameters, ResultHandler handler, int maxRows, int fetchSize, int flags)
          Execute several Query, passing results to a provided ResultHandler.
 void execute(Query query, ParameterList parameters, ResultHandler handler, int maxRows, int fetchSize, int flags)
          Execute a Query, passing results to a provided ResultHandler.
 byte[] fastpathCall(int fnid, ParameterList parameters, boolean suppressBegin)
          Invoke a backend function via the fastpath interface.
 void fetch(ResultCursor cursor, ResultHandler handler, int rows)
          Fetch additional rows from a cursor.
 void processNotifies()
           
protected  void processResults(Query originalQuery, ResultHandler handler, int maxRows)
           
protected  void sendQuery(org.postgresql.core.v2.V2Query query, org.postgresql.core.v2.SimpleParameterList params, java.lang.String queryPrefix)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

QueryExecutorImpl

public QueryExecutorImpl(org.postgresql.core.v2.ProtocolConnectionImpl protoConnection,
                         PGStream pgStream,
                         Logger logger)
Method Detail

createSimpleQuery

public Query createSimpleQuery(java.lang.String sql)
Description copied from interface: QueryExecutor
Create an unparameterized Query object suitable for execution by this QueryExecutor. The provided query string is not parsed for parameter placeholders ('?' characters), and the Query.createParameterList() of the returned object will always return an empty ParameterList.

Specified by:
createSimpleQuery in interface QueryExecutor
Parameters:
sql - the SQL for the query to create
Returns:
a new Query object

createParameterizedQuery

public Query createParameterizedQuery(java.lang.String sql)
Description copied from interface: QueryExecutor
Create a parameterized Query object suitable for execution by this QueryExecutor. The provided query string is parsed for parameter placeholders ('?' characters), and the Query.createParameterList() of the returned object will create an appropriately-sized ParameterList.

Specified by:
createParameterizedQuery in interface QueryExecutor
Parameters:
sql - the SQL for the query to create, with '?' placeholders for parameters.
Returns:
a new Query object

createFastpathParameters

public ParameterList createFastpathParameters(int count)
Description copied from interface: QueryExecutor
Create a new ParameterList implementation suitable for invoking a fastpath function via QueryExecutor.fastpathCall(int, org.postgresql.core.ParameterList, boolean).

Specified by:
createFastpathParameters in interface QueryExecutor
Parameters:
count - the number of parameters the fastpath call will take
Returns:
a ParameterList suitable for passing to QueryExecutor.fastpathCall(int, org.postgresql.core.ParameterList, boolean).

fastpathCall

public byte[] fastpathCall(int fnid,
                           ParameterList parameters,
                           boolean suppressBegin)
                    throws java.sql.SQLException
Description copied from interface: QueryExecutor
Invoke a backend function via the fastpath interface.

Specified by:
fastpathCall in interface QueryExecutor
Parameters:
fnid - the OID of the backend function to invoke
parameters - a ParameterList returned from QueryExecutor.createFastpathParameters(int) containing the parameters to pass to the backend function
Returns:
the binary-format result of the fastpath call, or null if a void result was returned
Throws:
java.sql.SQLException - if an error occurs while executing the fastpath call

processNotifies

public void processNotifies()
                     throws java.sql.SQLException
Throws:
java.sql.SQLException

execute

public void execute(Query query,
                    ParameterList parameters,
                    ResultHandler handler,
                    int maxRows,
                    int fetchSize,
                    int flags)
             throws java.sql.SQLException
Description copied from interface: QueryExecutor
Execute a Query, passing results to a provided ResultHandler.

Specified by:
execute in interface QueryExecutor
Parameters:
query - the query to execute; must be a query returned from calling QueryExecutor.createSimpleQuery(String) or QueryExecutor.createParameterizedQuery(String) on this QueryExecutor object.
parameters - the parameters for the query. Must be non-null if the query takes parameters. Must be a parameter object returned by Query.createParameterList().
handler - a ResultHandler responsible for handling results generated by this query
maxRows - the maximum number of rows to retrieve
fetchSize - if QUERY_FORWARD_CURSOR is set, the preferred number of rows to retrieve before suspending
flags - a combination of QUERY_* flags indicating how to handle the query.
Throws:
java.sql.SQLException - if query execution fails

execute

public void execute(Query[] queries,
                    ParameterList[] parameters,
                    ResultHandler handler,
                    int maxRows,
                    int fetchSize,
                    int flags)
             throws java.sql.SQLException
Description copied from interface: QueryExecutor
Execute several Query, passing results to a provided ResultHandler.

Specified by:
execute in interface QueryExecutor
Parameters:
queries - the queries to execute; each must be a query returned from calling QueryExecutor.createSimpleQuery(String) or QueryExecutor.createParameterizedQuery(String) on this QueryExecutor object.
parameters - the parameter lists for the queries. The parameter lists correspond 1:1 to the queries passed in the queries array. Each must be non-null if the corresponding query takes parameters, and must be a parameter object returned by Query.createParameterList() created by the corresponding query.
handler - a ResultHandler responsible for handling results generated by this query
maxRows - the maximum number of rows to retrieve
fetchSize - if QUERY_FORWARD_CURSOR is set, the preferred number of rows to retrieve before suspending
flags - a combination of QUERY_* flags indicating how to handle the query.
Throws:
java.sql.SQLException - if query execution fails

fetch

public void fetch(ResultCursor cursor,
                  ResultHandler handler,
                  int rows)
           throws java.sql.SQLException
Description copied from interface: QueryExecutor
Fetch additional rows from a cursor.

Specified by:
fetch in interface QueryExecutor
Parameters:
cursor - the cursor to fetch from
handler - the handler to feed results to
rows - the preferred number of rows to retrieve before suspending
Throws:
java.sql.SQLException - if query execution fails

sendQuery

protected void sendQuery(org.postgresql.core.v2.V2Query query,
                         org.postgresql.core.v2.SimpleParameterList params,
                         java.lang.String queryPrefix)
                  throws java.io.IOException
Throws:
java.io.IOException

processResults

protected void processResults(Query originalQuery,
                              ResultHandler handler,
                              int maxRows)
                       throws java.io.IOException
Throws:
java.io.IOException