org.postgresql.core
Interface QueryExecutor

All Known Implementing Classes:
QueryExecutorImpl, QueryExecutorImpl

public interface QueryExecutor

Abstracts the protocol-specific details of executing a query.

Every connection has a single QueryExecutor implementation associated with it. This object provides:

Query objects may represent a query that has parameter placeholders. To provide actual values for these parameters, a ParameterList object is created via a factory method (Query.createParameterList()). The parameters are filled in by the caller and passed along with the query to the query execution methods. Several ParameterLists for a given query might exist at one time (or over time); this allows the underlying Query to be reused for several executions, or for batch execution of the same Query.

In general, a Query created by a particular QueryExecutor may only be executed by that QueryExecutor, and a ParameterList created by a particular Query may only be used as parameters to that Query. Unpredictable things will happen if this isn't done.

Author:
Oliver Jowett (oliver@opencloud.com)

Field Summary
static int QUERY_DESCRIBE_ONLY
          Flag for query execution when we don't really want to execute, we just want to get the parameter metadata for the statement.
static int QUERY_FORWARD_CURSOR
          Flag for query execution that indicates a forward-fetch-capable cursor should be used if possible.
static int QUERY_NO_METADATA
          Flag for query execution that indicates that resultset metadata isn't needed and can be safely omitted.
static int QUERY_NO_RESULTS
          Flag for query execution that indicates that a resultset isn't expected and the query executor can safely discard any rows (although the resultset should still appear to be from a resultset-returning query).
static int QUERY_ONESHOT
          Flag for query execution that indicates the given Query object is unlikely to be reused.
static int QUERY_SUPPRESS_BEGIN
          Flag for query execution that indicates the automatic BEGIN on the first statement when outside a transaction should not be done.
 
Method Summary
 ParameterList createFastpathParameters(int count)
          Create a new ParameterList implementation suitable for invoking a fastpath function via 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[] parameterLists, 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 params, boolean suppressBegin)
          Invoke a backend function via the fastpath interface.
 void fetch(ResultCursor cursor, ResultHandler handler, int fetchSize)
          Fetch additional rows from a cursor.
 

Field Detail

QUERY_ONESHOT

static final int QUERY_ONESHOT
Flag for query execution that indicates the given Query object is unlikely to be reused.

See Also:
Constant Field Values

QUERY_NO_METADATA

static final int QUERY_NO_METADATA
Flag for query execution that indicates that resultset metadata isn't needed and can be safely omitted.

See Also:
Constant Field Values

QUERY_NO_RESULTS

static final int QUERY_NO_RESULTS
Flag for query execution that indicates that a resultset isn't expected and the query executor can safely discard any rows (although the resultset should still appear to be from a resultset-returning query).

See Also:
Constant Field Values

QUERY_FORWARD_CURSOR

static final int QUERY_FORWARD_CURSOR
Flag for query execution that indicates a forward-fetch-capable cursor should be used if possible.

See Also:
Constant Field Values

QUERY_SUPPRESS_BEGIN

static final int QUERY_SUPPRESS_BEGIN
Flag for query execution that indicates the automatic BEGIN on the first statement when outside a transaction should not be done.

See Also:
Constant Field Values

QUERY_DESCRIBE_ONLY

static final int QUERY_DESCRIBE_ONLY
Flag for query execution when we don't really want to execute, we just want to get the parameter metadata for the statement.

See Also:
Constant Field Values
Method Detail

execute

void execute(Query query,
             ParameterList parameters,
             ResultHandler handler,
             int maxRows,
             int fetchSize,
             int flags)
             throws java.sql.SQLException
Execute a Query, passing results to a provided ResultHandler.

Parameters:
query - the query to execute; must be a query returned from calling createSimpleQuery(String) or 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

void execute(Query[] queries,
             ParameterList[] parameterLists,
             ResultHandler handler,
             int maxRows,
             int fetchSize,
             int flags)
             throws java.sql.SQLException
Execute several Query, passing results to a provided ResultHandler.

Parameters:
queries - the queries to execute; each must be a query returned from calling createSimpleQuery(String) or createParameterizedQuery(String) on this QueryExecutor object.
parameterLists - 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

void fetch(ResultCursor cursor,
           ResultHandler handler,
           int fetchSize)
           throws java.sql.SQLException
Fetch additional rows from a cursor.

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

createSimpleQuery

Query createSimpleQuery(java.lang.String sql)
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.

Parameters:
sql - the SQL for the query to create
Returns:
a new Query object

createParameterizedQuery

Query createParameterizedQuery(java.lang.String sql)
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.

Parameters:
sql - the SQL for the query to create, with '?' placeholders for parameters.
Returns:
a new Query object

createFastpathParameters

ParameterList createFastpathParameters(int count)
Create a new ParameterList implementation suitable for invoking a fastpath function via fastpathCall(int, org.postgresql.core.ParameterList, boolean).

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

fastpathCall

byte[] fastpathCall(int fnid,
                    ParameterList params,
                    boolean suppressBegin)
                    throws java.sql.SQLException
Invoke a backend function via the fastpath interface.

Parameters:
fnid - the OID of the backend function to invoke
params - a ParameterList returned from 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