public class PgStatement extends Object implements Statement, BaseStatement
| Modifier and Type | Class and Description |
|---|---|
class |
PgStatement.StatementResultHandler
ResultHandler implementations for updates, queries, and either-or.
|
| Modifier and Type | Field and Description |
|---|---|
protected boolean |
adaptiveFetch |
protected @Nullable ArrayList<ParameterList> |
batchParameters |
protected @Nullable ArrayList<Query> |
batchStatements |
protected int |
concurrency |
protected BaseConnection |
connection |
protected int |
fetchdirection |
protected int |
fetchSize
Number of rows to get in a batch.
|
protected @Nullable @GuardedBy(value="<self>") ResultWrapper |
firstUnclosedResult
The first unclosed result.
|
protected @Nullable ResultWrapper |
generatedKeys
Results returned by a statement that wants generated keys.
|
protected int |
maxFieldSize |
protected int |
maxrows
Maximum number of rows to return, 0 = unlimited.
|
protected int |
mPrepareThreshold |
protected boolean |
replaceProcessingEnabled |
protected @Nullable ResultWrapper |
result
The current results.
|
protected int |
resultsettype |
protected long |
timeout
Timeout (in milliseconds) for a query.
|
boolean |
wantsGeneratedKeysAlways
Was this PreparedStatement created to return generated keys for every execution? This is set at
creation time and never cleared by execution.
|
protected boolean |
wantsGeneratedKeysOnce
Does the caller of execute/executeUpdate want generated keys for this execution? This is set by
Statement methods that have generated keys arguments and cleared after execution is complete.
|
protected @Nullable org.postgresql.jdbc.PSQLWarningWrapper |
warnings
The warnings chain.
|
DATE_NEGATIVE_INFINITY, DATE_NEGATIVE_SMALLER_INFINITY, DATE_POSITIVE_INFINITY, DATE_POSITIVE_SMALLER_INFINITYCLOSE_ALL_RESULTS, CLOSE_CURRENT_RESULT, EXECUTE_FAILED, KEEP_CURRENT_RESULT, NO_GENERATED_KEYS, RETURN_GENERATED_KEYS, SUCCESS_NO_INFO| Modifier and Type | Method and Description |
|---|---|
void |
addBatch(String sql) |
void |
addWarning(SQLWarning warn)
Either initializes new warning wrapper, or adds warning onto the chain.
|
void |
cancel() |
protected void |
checkClosed() |
protected void |
checkCompletion() |
protected void |
checkNoResultUpdate() |
void |
clearBatch() |
void |
clearWarnings()
Clears the warning chain.
|
void |
close()
Note: even though
Statement is automatically closed when it is garbage
collected, it is better to close it explicitly to lower resource consumption. |
protected void |
closeForNextExecution() |
protected void |
closeImpl()
This is guaranteed to be called exactly once even in case of concurrent
close() calls. |
void |
closeOnCompletion() |
protected BatchResultHandler |
createBatchHandler(Query[] queries,
@Nullable ParameterList[] parameterLists) |
ResultSet |
createDriverResultSet(Field[] fields,
List<Tuple> tuples)
Create a synthetic resultset from data provided by the driver.
|
ResultSet |
createResultSet(@Nullable Query originalQuery,
Field[] fields,
List<Tuple> tuples,
@Nullable ResultCursor cursor)
Create a resultset from data retrieved from the server.
|
protected void |
execute(CachedQuery cachedQuery,
@Nullable ParameterList queryParameters,
int flags) |
boolean |
execute(String sql) |
boolean |
execute(String sql,
int autoGeneratedKeys) |
boolean |
execute(String sql,
int[] columnIndexes) |
boolean |
execute(String sql,
String[] columnNames) |
int[] |
executeBatch() |
long[] |
executeLargeBatch() |
long |
executeLargeUpdate(String sql) |
long |
executeLargeUpdate(String sql,
int autoGeneratedKeys) |
long |
executeLargeUpdate(String sql,
int[] columnIndexes) |
long |
executeLargeUpdate(String sql,
String[] columnNames) |
ResultSet |
executeQuery(String sql) |
int |
executeUpdate(String sql) |
int |
executeUpdate(String sql,
int autoGeneratedKeys) |
int |
executeUpdate(String sql,
int[] columnIndexes) |
int |
executeUpdate(String sql,
String[] columnNames) |
boolean |
executeWithFlags(CachedQuery simpleQuery,
int flags)
Execute a query, passing additional query flags.
|
boolean |
executeWithFlags(int flags)
Execute a prepared query, passing additional query flags.
|
boolean |
executeWithFlags(String sql,
int flags)
Execute a query, passing additional query flags.
|
boolean |
getAdaptiveFetch()
Get state of adaptive fetch for statement.
|
Connection |
getConnection() |
int |
getFetchDirection() |
@Nullable String |
getFetchingCursorName() |
@NonNegative int |
getFetchSize() |
protected boolean |
getForceBinaryTransfer() |
ResultSet |
getGeneratedKeys() |
long |
getLargeMaxRows() |
long |
getLargeUpdateCount() |
long |
getLastOID()
Returns the Last inserted/updated oid.
|
int |
getMaxFieldSize() |
int |
getMaxRows() |
boolean |
getMoreResults() |
boolean |
getMoreResults(int current) |
BaseConnection |
getPGConnection() |
int |
getPrepareThreshold()
Gets the server-side prepare reuse threshold in use for this statement.
|
int |
getQueryTimeout() |
long |
getQueryTimeoutMs()
The queryTimeout limit is the number of milliseconds the driver will wait for a Statement to
execute.
|
@Nullable ResultSet |
getResultSet() |
int |
getResultSetConcurrency() |
int |
getResultSetHoldability() |
int |
getResultSetType() |
protected ResultSet |
getSingleResultSet() |
int |
getUpdateCount() |
@Nullable SQLWarning |
getWarnings() |
boolean |
isClosed() |
boolean |
isCloseOnCompletion() |
protected boolean |
isOneShotQuery(@Nullable CachedQuery cachedQuery)
Returns true if query is unlikely to be reused.
|
boolean |
isPoolable() |
boolean |
isUseServerPrepare()
Checks if this statement will be executed as a server-prepared statement.
|
boolean |
isWrapperFor(Class<?> iface) |
void |
setAdaptiveFetch(boolean adaptiveFetch)
Turn on/off adaptive fetch for statement.
|
void |
setCursorName(String name) |
void |
setEscapeProcessing(boolean enable) |
void |
setFetchDirection(int direction) |
void |
setFetchSize(@NonNegative int rows) |
void |
setLargeMaxRows(long max) |
void |
setMaxFieldSize(int max) |
void |
setMaxRows(int max) |
void |
setPoolable(boolean poolable) |
void |
setPrepareThreshold(int newThreshold)
Sets the reuse threshold for using server-prepared statements.
|
void |
setQueryTimeout(int seconds) |
void |
setQueryTimeoutMs(long millis)
Sets the queryTimeout limit.
|
void |
setUseServerPrepare(boolean flag)
Turn on the use of prepared statements in the server (server side prepared statements are
unrelated to jdbc PreparedStatements) As of build 302, this method is equivalent to
setPrepareThreshold(1). |
protected void |
transformQueriesAndParameters() |
<T> T |
unwrap(Class<T> iface) |
protected boolean |
wantsHoldableResultSet() |
protected boolean |
wantsScrollableResultSet() |
protected @Nullable ArrayList<ParameterList> batchParameters
protected final int resultsettype
protected final int concurrency
protected int fetchdirection
protected boolean wantsGeneratedKeysOnce
public boolean wantsGeneratedKeysAlways
protected final BaseConnection connection
protected volatile @Nullable org.postgresql.jdbc.PSQLWarningWrapper warnings
protected int maxrows
protected int fetchSize
protected long timeout
protected boolean replaceProcessingEnabled
protected @Nullable ResultWrapper result
protected @Nullable @GuardedBy(value="<self>") ResultWrapper firstUnclosedResult
protected @Nullable ResultWrapper generatedKeys
protected int mPrepareThreshold
protected int maxFieldSize
protected boolean adaptiveFetch
public ResultSet createResultSet(@Nullable Query originalQuery, Field[] fields, List<Tuple> tuples, @Nullable ResultCursor cursor) throws SQLException
BaseStatementcreateResultSet in interface BaseStatementoriginalQuery - the query that generated this resultset; used when dealing with updateable
resultsetsfields - the column metadata for the resultsettuples - the resultset datacursor - the cursor to use to retrieve more data from the server; if null, no additional
data is present.SQLException - if something goes wrongpublic BaseConnection getPGConnection()
public @Nullable String getFetchingCursorName()
public @NonNegative int getFetchSize()
getFetchSize in interface Statementprotected boolean wantsScrollableResultSet()
protected boolean wantsHoldableResultSet()
public ResultSet executeQuery(String sql) throws SQLException
executeQuery in interface StatementSQLExceptionprotected ResultSet getSingleResultSet() throws SQLException
SQLExceptionpublic int executeUpdate(String sql) throws SQLException
executeUpdate in interface StatementSQLExceptionprotected final void checkNoResultUpdate()
throws SQLException
SQLExceptionpublic boolean execute(String sql) throws SQLException
execute in interface StatementSQLExceptionpublic boolean executeWithFlags(String sql, int flags) throws SQLException
BaseStatementexecuteWithFlags in interface BaseStatementsql - the query to execute (JDBC-style query)flags - additional QueryExecutor flags for execution; these are bitwise-ORed into
the default flags.SQLException - if something goes wrong.public boolean executeWithFlags(CachedQuery simpleQuery, int flags) throws SQLException
BaseStatementexecuteWithFlags in interface BaseStatementsimpleQuery - the query to execute (native to PostgreSQL)flags - additional QueryExecutor flags for execution; these are bitwise-ORed into
the default flags.SQLException - if something goes wrong.public boolean executeWithFlags(int flags)
throws SQLException
BaseStatementexecuteWithFlags in interface BaseStatementflags - additional QueryExecutor flags for execution; these are bitwise-ORed into
the default flags.SQLException - if something goes wrong.protected void closeForNextExecution()
throws SQLException
SQLExceptionprotected boolean isOneShotQuery(@Nullable CachedQuery cachedQuery)
cachedQuery - to check (null if current query)protected final void execute(CachedQuery cachedQuery, @Nullable ParameterList queryParameters, int flags) throws SQLException
SQLExceptionpublic void setCursorName(String name) throws SQLException
setCursorName in interface StatementSQLExceptionpublic int getUpdateCount()
throws SQLException
getUpdateCount in interface StatementSQLExceptionpublic boolean getMoreResults()
throws SQLException
getMoreResults in interface StatementSQLExceptionpublic int getMaxRows()
throws SQLException
getMaxRows in interface StatementSQLExceptionpublic void setMaxRows(int max)
throws SQLException
setMaxRows in interface StatementSQLExceptionpublic void setEscapeProcessing(boolean enable)
throws SQLException
setEscapeProcessing in interface StatementSQLExceptionpublic int getQueryTimeout()
throws SQLException
getQueryTimeout in interface StatementSQLExceptionpublic void setQueryTimeout(int seconds)
throws SQLException
setQueryTimeout in interface StatementSQLExceptionpublic long getQueryTimeoutMs()
throws SQLException
SQLException - if a database access error occurspublic void setQueryTimeoutMs(long millis)
throws SQLException
millis - - the new query timeout limit in millisecondsSQLException - if a database access error occurspublic void addWarning(SQLWarning warn)
Either initializes new warning wrapper, or adds warning onto the chain.
Although warnings are expected to be added sequentially, the warnings chain may be cleared
concurrently at any time via clearWarnings(), therefore it is possible that a warning
added via this method is placed onto the end of the previous warning chain
warn - warning to addpublic @Nullable SQLWarning getWarnings() throws SQLException
getWarnings in interface StatementSQLExceptionpublic int getMaxFieldSize()
throws SQLException
getMaxFieldSize in interface StatementSQLExceptionpublic void setMaxFieldSize(int max)
throws SQLException
setMaxFieldSize in interface StatementSQLExceptionpublic void clearWarnings()
throws SQLException
Clears the warning chain.
Note that while it is safe to clear warnings while the query is executing, warnings that are
added between calls to getWarnings() and #clearWarnings() may be missed.
Therefore you should hold a reference to the tail of the previous warning chain
and verify if its SQLWarning.getNextWarning() value is holds any new value.
clearWarnings in interface StatementSQLExceptionpublic @Nullable ResultSet getResultSet() throws SQLException
getResultSet in interface StatementSQLExceptionpublic final void close()
throws SQLException
Statement is automatically closed when it is garbage
collected, it is better to close it explicitly to lower resource consumption.
close in interface AutoCloseableclose in interface StatementSQLExceptionprotected void closeImpl()
throws SQLException
close() calls.SQLException - in case of errorpublic long getLastOID()
throws SQLException
PGStatementgetLastOID in interface PGStatementSQLException - if something goes wrongpublic void setPrepareThreshold(int newThreshold)
throws SQLException
PGStatementSets the reuse threshold for using server-prepared statements.
If threshold is a non-zero value N, the Nth and subsequent reuses of a
PreparedStatement will use server-side prepare.
If threshold is zero, server-side prepare will not be used.
The reuse threshold is only used by PreparedStatement and CallableStatement objects; it is ignored for plain Statements.
setPrepareThreshold in interface PGStatementnewThreshold - the new threshold for this statementSQLException - if an exception occurs while changing the thresholdpublic int getPrepareThreshold()
PGStatementgetPrepareThreshold in interface PGStatementPGStatement.setPrepareThreshold(int)public void setUseServerPrepare(boolean flag)
throws SQLException
PGStatementsetPrepareThreshold(1).setUseServerPrepare in interface PGStatementflag - use server prepareSQLException - if something goes wrongpublic boolean isUseServerPrepare()
PGStatementtrue indicates that the next execution of the statement will be done as a
server-prepared statement, assuming the underlying protocol supports it.isUseServerPrepare in interface PGStatementprotected void checkClosed()
throws SQLException
SQLExceptionpublic void addBatch(String sql) throws SQLException
addBatch in interface StatementSQLExceptionpublic void clearBatch()
throws SQLException
clearBatch in interface StatementSQLExceptionprotected BatchResultHandler createBatchHandler(Query[] queries, @Nullable ParameterList[] parameterLists)
public int[] executeBatch()
throws SQLException
executeBatch in interface StatementSQLExceptionpublic void cancel()
throws SQLException
cancel in interface StatementSQLExceptionpublic Connection getConnection() throws SQLException
getConnection in interface StatementSQLExceptionpublic int getFetchDirection()
getFetchDirection in interface Statementpublic int getResultSetConcurrency()
getResultSetConcurrency in interface Statementpublic int getResultSetType()
getResultSetType in interface Statementpublic void setFetchDirection(int direction)
throws SQLException
setFetchDirection in interface StatementSQLExceptionpublic void setFetchSize(@NonNegative int rows)
throws SQLException
setFetchSize in interface StatementSQLExceptionprotected boolean getForceBinaryTransfer()
public long getLargeUpdateCount()
throws SQLException
getLargeUpdateCount in interface StatementSQLExceptionpublic void setLargeMaxRows(long max)
throws SQLException
setLargeMaxRows in interface StatementSQLExceptionpublic long getLargeMaxRows()
throws SQLException
getLargeMaxRows in interface StatementSQLExceptionpublic long[] executeLargeBatch()
throws SQLException
executeLargeBatch in interface StatementSQLExceptionpublic long executeLargeUpdate(String sql) throws SQLException
executeLargeUpdate in interface StatementSQLExceptionpublic long executeLargeUpdate(String sql, int autoGeneratedKeys) throws SQLException
executeLargeUpdate in interface StatementSQLExceptionpublic long executeLargeUpdate(String sql, int[] columnIndexes) throws SQLException
executeLargeUpdate in interface StatementSQLExceptionpublic long executeLargeUpdate(String sql, String[] columnNames) throws SQLException
executeLargeUpdate in interface StatementSQLExceptionpublic boolean isClosed()
throws SQLException
isClosed in interface StatementSQLExceptionpublic void setPoolable(boolean poolable)
throws SQLException
setPoolable in interface StatementSQLExceptionpublic boolean isPoolable()
throws SQLException
isPoolable in interface StatementSQLExceptionpublic boolean isWrapperFor(Class<?> iface) throws SQLException
isWrapperFor in interface WrapperSQLExceptionpublic <T> T unwrap(Class<T> iface) throws SQLException
unwrap in interface WrapperSQLExceptionpublic void closeOnCompletion()
throws SQLException
closeOnCompletion in interface StatementSQLExceptionpublic boolean isCloseOnCompletion()
throws SQLException
isCloseOnCompletion in interface StatementSQLExceptionprotected void checkCompletion()
throws SQLException
SQLExceptionpublic boolean getMoreResults(int current)
throws SQLException
getMoreResults in interface StatementSQLExceptionpublic ResultSet getGeneratedKeys() throws SQLException
getGeneratedKeys in interface StatementSQLExceptionpublic int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException
executeUpdate in interface StatementSQLExceptionpublic int executeUpdate(String sql, int[] columnIndexes) throws SQLException
executeUpdate in interface StatementSQLExceptionpublic int executeUpdate(String sql, String[] columnNames) throws SQLException
executeUpdate in interface StatementSQLExceptionpublic boolean execute(String sql, int autoGeneratedKeys) throws SQLException
execute in interface StatementSQLExceptionpublic boolean execute(String sql, int[] columnIndexes) throws SQLException
execute in interface StatementSQLExceptionpublic boolean execute(String sql, String[] columnNames) throws SQLException
execute in interface StatementSQLExceptionpublic int getResultSetHoldability()
throws SQLException
getResultSetHoldability in interface StatementSQLExceptionpublic ResultSet createDriverResultSet(Field[] fields, List<Tuple> tuples) throws SQLException
BaseStatementcreateDriverResultSet in interface BaseStatementfields - the column metadata for the resultsettuples - the resultset dataSQLException - if something goes wrongprotected void transformQueriesAndParameters()
throws SQLException
SQLExceptionpublic void setAdaptiveFetch(boolean adaptiveFetch)
PGStatementsetAdaptiveFetch in interface PGStatementadaptiveFetch - desired state of adaptive fetch.public boolean getAdaptiveFetch()
PGStatementgetAdaptiveFetch in interface PGStatementCopyright © 1997-2020 PostgreSQL Global Development Group. All Rights Reserved.