public interface QueryExecutor extends TypeTransferModeRegistry
Abstracts the protocol-specific details of executing a query.
Every connection has a single QueryExecutor implementation associated with it. This object provides:
createSimpleQuery(String)
and
createQuery(String, boolean, boolean, String...)
)
execute(Query, ParameterList, ResultHandler, int, int, int)
for single queries and
execute(Query[], ParameterList[], BatchResultHandler, int, int, int)
for batches of queries)
createFastpathParameters(int)
and fastpathCall(int, org.postgresql.core.ParameterList, boolean)
).
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.
Modifier and Type | Field and Description |
---|---|
static int |
MAX_SAVE_POINTS |
static int |
QUERY_BOTH_ROWS_AND_STATUS
Flag for query execution used by generated keys where we want to receive both the ResultSet and
associated update count from the command status.
|
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_DISALLOW_BATCHING
Deprecated.
in PgJDBC 9.4 as we now auto-size batches.
|
static int |
QUERY_EXECUTE_AS_SIMPLE
Execute the query via simple 'Q' command (not parse, bind, exec, but simple execute).
|
static int |
QUERY_FORCE_DESCRIBE_PORTAL
Force this query to be described at each execution.
|
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_BINARY_TRANSFER
Flag for query execution to avoid using binary transfer.
|
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_READ_ONLY_HINT
Flag indicating that when beginning a transaction, it should be read only.
|
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.
|
Modifier and Type | Method and Description |
---|---|
void |
abort()
Abort at network level without sending the Terminate message to the backend.
|
void |
addQueryToAdaptiveFetchCache(boolean adaptiveFetch,
ResultCursor cursor)
Add query to adaptive fetch cache inside QueryExecutor.
|
CachedQuery |
borrowCallableQuery(String sql) |
CachedQuery |
borrowQuery(String sql) |
CachedQuery |
borrowQueryByKey(Object key) |
CachedQuery |
borrowReturningQuery(String sql,
String[] columnNames) |
void |
close()
Close this connection cleanly.
|
ParameterList |
createFastpathParameters(int count)
Deprecated.
This API is somewhat obsolete, as one may achieve similar performance
and greater functionality by setting up a prepared statement to define
the function call. Then, executing the statement with binary transmission of parameters
and results substitutes for a fast-path function call.
|
CachedQuery |
createQuery(String sql,
boolean escapeProcessing,
boolean isParameterized,
String... columnNames) |
CachedQuery |
createQueryByKey(Object key) |
Object |
createQueryKey(String sql,
boolean escapeProcessing,
boolean isParameterized,
String... columnNames) |
Query |
createSimpleQuery(String sql)
Create an unparameterized Query object suitable for execution by this QueryExecutor.
|
void |
execute(Query[] queries,
@Nullable ParameterList[] parameterLists,
BatchResultHandler handler,
int maxRows,
int fetchSize,
int flags)
Execute several Query, passing results to a provided ResultHandler.
|
void |
execute(Query[] queries,
@Nullable ParameterList[] parameterLists,
BatchResultHandler handler,
int maxRows,
int fetchSize,
int flags,
boolean adaptiveFetch)
Execute several Query with adaptive fetch, passing results to a provided ResultHandler.
|
void |
execute(Query query,
@Nullable ParameterList parameters,
ResultHandler handler,
int maxRows,
int fetchSize,
int flags)
Execute a Query, passing results to a provided ResultHandler.
|
void |
execute(Query query,
@Nullable ParameterList parameters,
ResultHandler handler,
int maxRows,
int fetchSize,
int flags,
boolean adaptiveFetch)
Execute a Query with adaptive fetch, passing results to a provided ResultHandler.
|
byte[] |
fastpathCall(int fnid,
ParameterList params,
boolean suppressBegin)
Deprecated.
This API is somewhat obsolete, as one may achieve similar performance
and greater functionality by setting up a prepared statement to define
the function call. Then, executing the statement with binary transmission of parameters
and results substitutes for a fast-path function call.
|
void |
fetch(ResultCursor cursor,
ResultHandler handler,
int fetchSize,
boolean adaptiveFetch)
Fetch additional rows from a cursor.
|
boolean |
getAdaptiveFetch()
Get state of adaptive fetch inside QueryExecutor.
|
int |
getAdaptiveFetchSize(boolean adaptiveFetch,
ResultCursor cursor)
Get fetch size computed by adaptive fetch size for given query.
|
String |
getApplicationName()
Returns application_name connection property.
|
AutoSave |
getAutoSave() |
int |
getBackendPID()
Return the process ID (PID) of the backend server process handling this connection.
|
String |
getDatabase() |
Encoding |
getEncoding() |
EscapeSyntaxCallMode |
getEscapeSyntaxCallMode() |
HostSpec |
getHostSpec() |
boolean |
getIntegerDateTimes()
Returns true if server uses integer instead of double for binary date and time encodings.
|
int |
getNetworkTimeout() |
PGNotification[] |
getNotifications()
Retrieve and clear the set of asynchronous notifications pending on this connection.
|
@Nullable String |
getParameterStatus(String parameterName) |
Map<String,String> |
getParameterStatuses() |
PreferQueryMode |
getPreferQueryMode() |
int |
getProtocolVersion() |
boolean |
getQuoteReturningIdentifiers() |
ReplicationProtocol |
getReplicationProtocol() |
String |
getServerVersion()
Return the server version from the server_version GUC.
|
int |
getServerVersionNum()
Get a machine-readable server version.
|
boolean |
getStandardConformingStrings()
Returns whether the server treats string-literals according to the SQL standard or if it uses
traditional PostgreSQL escaping rules.
|
@Nullable TimeZone |
getTimeZone()
Returns backend timezone in java format.
|
TransactionState |
getTransactionState()
Get the current transaction state of this connection.
|
String |
getUser() |
@Nullable SQLWarning |
getWarnings()
Retrieve and clear the chain of warnings accumulated on this connection.
|
boolean |
isClosed()
Check if this connection is closed.
|
boolean |
isColumnSanitiserDisabled() |
boolean |
isReWriteBatchedInsertsEnabled() |
void |
processNotifies()
Prior to attempting to retrieve notifications, we need to pull any recently received
notifications off of the network buffers.
|
void |
processNotifies(int timeoutMillis)
Prior to attempting to retrieve notifications, we need to pull any recently received
notifications off of the network buffers.
|
void |
releaseQuery(CachedQuery cachedQuery) |
void |
removeQueryFromAdaptiveFetchCache(boolean adaptiveFetch,
ResultCursor cursor)
Remove query from adaptive fetch cache inside QueryExecutor
|
void |
sendQueryCancel()
Sends a query cancellation for this connection.
|
void |
setAdaptiveFetch(boolean adaptiveFetch)
Set state of adaptive fetch inside QueryExecutor.
|
void |
setAutoSave(AutoSave autoSave) |
void |
setBinaryReceiveOids(Set<Integer> useBinaryForOids)
Sets the oids that should be received using binary encoding.
|
void |
setBinarySendOids(Set<Integer> useBinaryForOids)
Sets the oids that should be sent using binary encoding.
|
void |
setFlushCacheOnDeallocate(boolean flushCacheOnDeallocate)
By default, the connection resets statement cache in case deallocate all/discard all
message is observed.
|
void |
setNetworkTimeout(int milliseconds) |
CopyOperation |
startCopy(String sql,
boolean suppressBegin)
Issues a COPY FROM STDIN / COPY TO STDOUT statement and returns handler for associated
operation.
|
boolean |
willHealOnRetry(SQLException e) |
Query |
wrap(List<NativeQuery> queries)
Wrap given native query into a ready for execution format.
|
useBinaryForReceive, useBinaryForSend
static final int QUERY_ONESHOT
static final int QUERY_NO_METADATA
static final int QUERY_NO_RESULTS
static final int QUERY_FORWARD_CURSOR
static final int QUERY_SUPPRESS_BEGIN
static final int QUERY_DESCRIBE_ONLY
static final int QUERY_BOTH_ROWS_AND_STATUS
static final int QUERY_FORCE_DESCRIBE_PORTAL
@Deprecated static final int QUERY_DISALLOW_BATCHING
static final int QUERY_NO_BINARY_TRANSFER
static final int QUERY_EXECUTE_AS_SIMPLE
static final int MAX_SAVE_POINTS
static final int QUERY_READ_ONLY_HINT
void execute(Query query, @Nullable ParameterList parameters, ResultHandler handler, int maxRows, int fetchSize, int flags) throws SQLException
query
- the query to execute; must be a query returned from calling
wrap(List)
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 querymaxRows
- the maximum number of rows to retrievefetchSize
- if QUERY_FORWARD_CURSOR is set, the preferred number of rows to retrieve
before suspendingflags
- a combination of QUERY_* flags indicating how to handle the query.SQLException
- if query execution failsvoid execute(Query query, @Nullable ParameterList parameters, ResultHandler handler, int maxRows, int fetchSize, int flags, boolean adaptiveFetch) throws SQLException
query
- the query to execute; must be a query returned from calling
wrap(List)
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 querymaxRows
- the maximum number of rows to retrievefetchSize
- if QUERY_FORWARD_CURSOR is set, the preferred number of rows to retrieve
before suspendingflags
- a combination of QUERY_* flags indicating how to handle the query.adaptiveFetch
- state of adaptiveFetch to use during executionSQLException
- if query execution failsvoid execute(Query[] queries, @Nullable ParameterList[] parameterLists, BatchResultHandler handler, int maxRows, int fetchSize, int flags) throws SQLException
queries
- the queries to execute; each must be a query returned from calling
wrap(List)
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 querymaxRows
- the maximum number of rows to retrievefetchSize
- if QUERY_FORWARD_CURSOR is set, the preferred number of rows to retrieve
before suspendingflags
- a combination of QUERY_* flags indicating how to handle the query.SQLException
- if query execution failsvoid execute(Query[] queries, @Nullable ParameterList[] parameterLists, BatchResultHandler handler, int maxRows, int fetchSize, int flags, boolean adaptiveFetch) throws SQLException
queries
- the queries to execute; each must be a query returned from calling
wrap(List)
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 querymaxRows
- the maximum number of rows to retrievefetchSize
- if QUERY_FORWARD_CURSOR is set, the preferred number of rows to retrieve
before suspendingflags
- a combination of QUERY_* flags indicating how to handle the query.adaptiveFetch
- state of adaptiveFetch to use during executionSQLException
- if query execution failsvoid fetch(ResultCursor cursor, ResultHandler handler, int fetchSize, boolean adaptiveFetch) throws SQLException
cursor
- the cursor to fetch fromhandler
- the handler to feed results tofetchSize
- the preferred number of rows to retrieve before suspendingadaptiveFetch
- state of adaptiveFetch to use during fetchingSQLException
- if query execution failsQuery createSimpleQuery(String sql) throws SQLException
Query.createParameterList()
of the returned object will always return an empty
ParameterList.sql
- the SQL for the query to createSQLException
- if something goes wrongboolean isReWriteBatchedInsertsEnabled()
CachedQuery createQuery(String sql, boolean escapeProcessing, boolean isParameterized, String... columnNames) throws SQLException
SQLException
Object createQueryKey(String sql, boolean escapeProcessing, boolean isParameterized, String... columnNames)
CachedQuery createQueryByKey(Object key) throws SQLException
SQLException
CachedQuery borrowQueryByKey(Object key) throws SQLException
SQLException
CachedQuery borrowQuery(String sql) throws SQLException
SQLException
CachedQuery borrowCallableQuery(String sql) throws SQLException
SQLException
CachedQuery borrowReturningQuery(String sql, String[] columnNames) throws SQLException
SQLException
void releaseQuery(CachedQuery cachedQuery)
Query wrap(List<NativeQuery> queries)
queries
- list of queries in native to database syntaxvoid processNotifies() throws SQLException
SQLException
- if and error occurs while fetching notificationsvoid processNotifies(int timeoutMillis) throws SQLException
timeoutMillis
- number of milliseconds to block forSQLException
- if and error occurs while fetching notifications@Deprecated ParameterList createFastpathParameters(int count)
fastpathCall(int, org.postgresql.core.ParameterList, boolean)
.count
- the number of parameters the fastpath call will takefastpathCall(int, org.postgresql.core.ParameterList, boolean)
.@Deprecated byte[] fastpathCall(int fnid, ParameterList params, boolean suppressBegin) throws SQLException
fnid
- the OID of the backend function to invokeparams
- a ParameterList returned from createFastpathParameters(int)
containing the
parameters to pass to the backend functionsuppressBegin
- if begin should be suppressednull
if a void result
was returnedSQLException
- if an error occurs while executing the fastpath callCopyOperation startCopy(String sql, boolean suppressBegin) throws SQLException
sql
- input sqlsuppressBegin
- if begin should be suppressedSQLException
- when initializing the given query failsint getProtocolVersion()
void setBinaryReceiveOids(Set<Integer> useBinaryForOids)
useBinaryForOids
- The oids to request with binary encoding.void setBinarySendOids(Set<Integer> useBinaryForOids)
useBinaryForOids
- The oids to send with binary encoding.boolean getIntegerDateTimes()
HostSpec getHostSpec()
String getUser()
String getDatabase()
void sendQueryCancel() throws SQLException
SQLException
- if something goes wrong.int getBackendPID()
void abort()
void close()
boolean isClosed()
String getServerVersion()
Return the server version from the server_version GUC.
Note that there's no requirement for this to be numeric or of the form x.y.z. PostgreSQL development releases usually have the format x.ydevel e.g. 9.4devel; betas usually x.ybetan e.g. 9.4beta1. The --with-extra-version configure option may add an arbitrary string to this.
Don't use this string for logic, only use it when displaying the server version to the user. Prefer getServerVersionNum() for all logic purposes.
PGNotification[] getNotifications() throws SQLException
SQLException
- if and error occurs while fetching notifications@Nullable SQLWarning getWarnings()
int getServerVersionNum()
Get a machine-readable server version.
This returns the value of the server_version_num GUC. If no such GUC exists, it falls back on attempting to parse the text server version for the major version. If there's no minor version (e.g. a devel or beta release) then the minor version is set to zero. If the version could not be parsed, zero is returned.
TransactionState getTransactionState()
boolean getStandardConformingStrings()
standard_conforming_strings
server variable.boolean getQuoteReturningIdentifiers()
@Nullable TimeZone getTimeZone()
Encoding getEncoding()
String getApplicationName()
boolean isColumnSanitiserDisabled()
EscapeSyntaxCallMode getEscapeSyntaxCallMode()
PreferQueryMode getPreferQueryMode()
AutoSave getAutoSave()
void setAutoSave(AutoSave autoSave)
boolean willHealOnRetry(SQLException e)
void setFlushCacheOnDeallocate(boolean flushCacheOnDeallocate)
flushCacheOnDeallocate
- true if statement cache should be reset when "deallocate/discard" message observedReplicationProtocol getReplicationProtocol()
void setNetworkTimeout(int milliseconds) throws IOException
IOException
int getNetworkTimeout() throws IOException
IOException
int getAdaptiveFetchSize(boolean adaptiveFetch, ResultCursor cursor)
adaptiveFetch
- state of adaptive fetch, which should be used during retrievingcursor
- Cursor used by resultSet, containing query, have to be able to cast to
Portal class.boolean getAdaptiveFetch()
void setAdaptiveFetch(boolean adaptiveFetch)
adaptiveFetch
- desired state of adaptive fetchvoid addQueryToAdaptiveFetchCache(boolean adaptiveFetch, ResultCursor cursor)
adaptiveFetch
- state of adaptive fetch used during adding querycursor
- Cursor used by resultSet, containing query, have to be able to cast to
Portal class.void removeQueryFromAdaptiveFetchCache(boolean adaptiveFetch, ResultCursor cursor)
adaptiveFetch
- state of adaptive fetch used during removing querycursor
- Cursor used by resultSet, containing query, have to be able to cast to
Portal class.Copyright © 1997-2020 PostgreSQL Global Development Group. All Rights Reserved.