public class PgStatement extends java.lang.Object implements java.sql.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 java.util.ArrayList<ParameterList> |
batchParameters |
protected java.util.ArrayList<Query> |
batchStatements |
protected int |
concurrency |
protected BaseConnection |
connection |
protected int |
fetchdirection |
protected int |
fetchSize
Number of rows to get in a batch.
|
protected ResultWrapper |
firstUnclosedResult
The first unclosed result.
|
protected 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 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 org.postgresql.jdbc.PSQLWarningWrapper |
warnings
The warnings chain.
|
DATE_NEGATIVE_INFINITY, DATE_NEGATIVE_SMALLER_INFINITY, DATE_POSITIVE_INFINITY, DATE_POSITIVE_SMALLER_INFINITY| Modifier and Type | Method and Description |
|---|---|
void |
addBatch(java.lang.String sql) |
void |
addWarning(java.sql.SQLWarning warn)
Either initializes new warning wrapper, or adds warning onto the chain.
|
void |
cancel() |
protected void |
checkClosed() |
protected void |
checkCompletion() |
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,
ParameterList[] parameterLists) |
java.sql.ResultSet |
createDriverResultSet(Field[] fields,
java.util.List<byte[][]> tuples)
Create a synthetic resultset from data provided by the driver.
|
java.sql.ResultSet |
createResultSet(Query originalQuery,
Field[] fields,
java.util.List<byte[][]> tuples,
ResultCursor cursor)
Create a resultset from data retrieved from the server.
|
protected void |
execute(CachedQuery cachedQuery,
ParameterList queryParameters,
int flags) |
boolean |
execute(java.lang.String sql) |
boolean |
execute(java.lang.String sql,
int autoGeneratedKeys) |
boolean |
execute(java.lang.String sql,
int[] columnIndexes) |
boolean |
execute(java.lang.String sql,
java.lang.String[] columnNames) |
int[] |
executeBatch() |
long[] |
executeLargeBatch() |
long |
executeLargeUpdate() |
long |
executeLargeUpdate(java.lang.String sql) |
long |
executeLargeUpdate(java.lang.String sql,
int autoGeneratedKeys) |
long |
executeLargeUpdate(java.lang.String sql,
int[] columnIndexes) |
long |
executeLargeUpdate(java.lang.String sql,
java.lang.String[] columnNames) |
java.sql.ResultSet |
executeQuery(java.lang.String sql) |
int |
executeUpdate(java.lang.String sql) |
int |
executeUpdate(java.lang.String sql,
int autoGeneratedKeys) |
int |
executeUpdate(java.lang.String sql,
int[] columnIndexes) |
int |
executeUpdate(java.lang.String sql,
java.lang.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(java.lang.String sql,
int flags)
Execute a query, passing additional query flags.
|
java.sql.Connection |
getConnection() |
int |
getFetchDirection() |
java.lang.String |
getFetchingCursorName() |
int |
getFetchSize() |
protected boolean |
getForceBinaryTransfer() |
java.sql.ResultSet |
getGeneratedKeys() |
long |
getLargeMaxRows() |
long |
getLargeUpdateCount() |
long |
getLastOID()
Returns the Last inserted/updated oid.
|
int |
getMaxFieldSize() |
int |
getMaxRows() |
boolean |
getMoreResults() |
boolean |
getMoreResults(int current) |
protected int |
getNoResultUpdateCount() |
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.
|
java.sql.ResultSet |
getResultSet() |
int |
getResultSetConcurrency() |
int |
getResultSetHoldability() |
int |
getResultSetType() |
protected java.sql.ResultSet |
getSingleResultSet() |
int |
getUpdateCount() |
java.sql.SQLWarning |
getWarnings() |
boolean |
isClosed() |
boolean |
isCloseOnCompletion() |
protected boolean |
isOneShotQuery(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(java.lang.Class<?> iface) |
void |
setCursorName(java.lang.String name) |
void |
setEscapeProcessing(boolean enable) |
void |
setFetchDirection(int direction) |
void |
setFetchSize(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(java.lang.Class<T> iface) |
protected boolean |
wantsHoldableResultSet() |
protected boolean |
wantsScrollableResultSet() |
protected java.util.ArrayList<Query> batchStatements
protected java.util.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 org.postgresql.jdbc.PSQLWarningWrapper warnings
protected int maxrows
protected int fetchSize
protected long timeout
protected boolean replaceProcessingEnabled
protected ResultWrapper result
protected ResultWrapper firstUnclosedResult
protected ResultWrapper generatedKeys
protected int mPrepareThreshold
protected int maxFieldSize
public java.sql.ResultSet createResultSet(Query originalQuery, Field[] fields, java.util.List<byte[][]> tuples, ResultCursor cursor) throws java.sql.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.java.sql.SQLException - if something goes wrongpublic BaseConnection getPGConnection()
public java.lang.String getFetchingCursorName()
public int getFetchSize()
getFetchSize in interface java.sql.Statementprotected boolean wantsScrollableResultSet()
protected boolean wantsHoldableResultSet()
public java.sql.ResultSet executeQuery(java.lang.String sql)
throws java.sql.SQLException
executeQuery in interface java.sql.Statementjava.sql.SQLExceptionprotected java.sql.ResultSet getSingleResultSet()
throws java.sql.SQLException
java.sql.SQLExceptionpublic int executeUpdate(java.lang.String sql)
throws java.sql.SQLException
executeUpdate in interface java.sql.Statementjava.sql.SQLExceptionprotected int getNoResultUpdateCount()
throws java.sql.SQLException
java.sql.SQLExceptionpublic boolean execute(java.lang.String sql)
throws java.sql.SQLException
execute in interface java.sql.Statementjava.sql.SQLExceptionpublic boolean executeWithFlags(java.lang.String sql,
int flags)
throws java.sql.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.java.sql.SQLException - if something goes wrong.public boolean executeWithFlags(CachedQuery simpleQuery, int flags) throws java.sql.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.java.sql.SQLException - if something goes wrong.public boolean executeWithFlags(int flags)
throws java.sql.SQLException
BaseStatementexecuteWithFlags in interface BaseStatementflags - additional QueryExecutor flags for execution; these are bitwise-ORed into
the default flags.java.sql.SQLException - if something goes wrong.protected void closeForNextExecution()
throws java.sql.SQLException
java.sql.SQLExceptionprotected boolean isOneShotQuery(CachedQuery cachedQuery)
cachedQuery - to check (null if current query)protected final void execute(CachedQuery cachedQuery, ParameterList queryParameters, int flags) throws java.sql.SQLException
java.sql.SQLExceptionpublic void setCursorName(java.lang.String name)
throws java.sql.SQLException
setCursorName in interface java.sql.Statementjava.sql.SQLExceptionpublic int getUpdateCount()
throws java.sql.SQLException
getUpdateCount in interface java.sql.Statementjava.sql.SQLExceptionpublic boolean getMoreResults()
throws java.sql.SQLException
getMoreResults in interface java.sql.Statementjava.sql.SQLExceptionpublic int getMaxRows()
throws java.sql.SQLException
getMaxRows in interface java.sql.Statementjava.sql.SQLExceptionpublic void setMaxRows(int max)
throws java.sql.SQLException
setMaxRows in interface java.sql.Statementjava.sql.SQLExceptionpublic void setEscapeProcessing(boolean enable)
throws java.sql.SQLException
setEscapeProcessing in interface java.sql.Statementjava.sql.SQLExceptionpublic int getQueryTimeout()
throws java.sql.SQLException
getQueryTimeout in interface java.sql.Statementjava.sql.SQLExceptionpublic void setQueryTimeout(int seconds)
throws java.sql.SQLException
setQueryTimeout in interface java.sql.Statementjava.sql.SQLExceptionpublic long getQueryTimeoutMs()
throws java.sql.SQLException
java.sql.SQLException - if a database access error occurspublic void setQueryTimeoutMs(long millis)
throws java.sql.SQLException
millis - - the new query timeout limit in millisecondsjava.sql.SQLException - if a database access error occurspublic void addWarning(java.sql.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 java.sql.SQLWarning getWarnings()
throws java.sql.SQLException
getWarnings in interface java.sql.Statementjava.sql.SQLExceptionpublic int getMaxFieldSize()
throws java.sql.SQLException
getMaxFieldSize in interface java.sql.Statementjava.sql.SQLExceptionpublic void setMaxFieldSize(int max)
throws java.sql.SQLException
setMaxFieldSize in interface java.sql.Statementjava.sql.SQLExceptionpublic void clearWarnings()
throws java.sql.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 java.sql.Statementjava.sql.SQLExceptionpublic java.sql.ResultSet getResultSet()
throws java.sql.SQLException
getResultSet in interface java.sql.Statementjava.sql.SQLExceptionpublic final void close()
throws java.sql.SQLException
Statement is automatically closed when it is garbage
collected, it is better to close it explicitly to lower resource consumption.
close in interface java.lang.AutoCloseableclose in interface java.sql.Statementjava.sql.SQLExceptionprotected void closeImpl()
throws java.sql.SQLException
close() calls.java.sql.SQLException - in case of errorpublic long getLastOID()
throws java.sql.SQLException
PGStatementgetLastOID in interface PGStatementjava.sql.SQLException - if something goes wrongpublic void setPrepareThreshold(int newThreshold)
throws java.sql.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 statementjava.sql.SQLException - if an exception occurs while changing the thresholdpublic int getPrepareThreshold()
PGStatementgetPrepareThreshold in interface PGStatementPGStatement.setPrepareThreshold(int)public void setUseServerPrepare(boolean flag)
throws java.sql.SQLException
PGStatementsetPrepareThreshold(1).setUseServerPrepare in interface PGStatementflag - use server preparejava.sql.SQLException - 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 java.sql.SQLException
java.sql.SQLExceptionpublic void addBatch(java.lang.String sql)
throws java.sql.SQLException
addBatch in interface java.sql.Statementjava.sql.SQLExceptionpublic void clearBatch()
throws java.sql.SQLException
clearBatch in interface java.sql.Statementjava.sql.SQLExceptionprotected BatchResultHandler createBatchHandler(Query[] queries, ParameterList[] parameterLists)
public int[] executeBatch()
throws java.sql.SQLException
executeBatch in interface java.sql.Statementjava.sql.SQLExceptionpublic void cancel()
throws java.sql.SQLException
cancel in interface java.sql.Statementjava.sql.SQLExceptionpublic java.sql.Connection getConnection()
throws java.sql.SQLException
getConnection in interface java.sql.Statementjava.sql.SQLExceptionpublic int getFetchDirection()
getFetchDirection in interface java.sql.Statementpublic int getResultSetConcurrency()
getResultSetConcurrency in interface java.sql.Statementpublic int getResultSetType()
getResultSetType in interface java.sql.Statementpublic void setFetchDirection(int direction)
throws java.sql.SQLException
setFetchDirection in interface java.sql.Statementjava.sql.SQLExceptionpublic void setFetchSize(int rows)
throws java.sql.SQLException
setFetchSize in interface java.sql.Statementjava.sql.SQLExceptionprotected boolean getForceBinaryTransfer()
public long getLargeUpdateCount()
throws java.sql.SQLException
getLargeUpdateCount in interface java.sql.Statementjava.sql.SQLExceptionpublic void setLargeMaxRows(long max)
throws java.sql.SQLException
setLargeMaxRows in interface java.sql.Statementjava.sql.SQLExceptionpublic long getLargeMaxRows()
throws java.sql.SQLException
getLargeMaxRows in interface java.sql.Statementjava.sql.SQLExceptionpublic long[] executeLargeBatch()
throws java.sql.SQLException
executeLargeBatch in interface java.sql.Statementjava.sql.SQLExceptionpublic long executeLargeUpdate(java.lang.String sql)
throws java.sql.SQLException
executeLargeUpdate in interface java.sql.Statementjava.sql.SQLExceptionpublic long executeLargeUpdate(java.lang.String sql,
int autoGeneratedKeys)
throws java.sql.SQLException
executeLargeUpdate in interface java.sql.Statementjava.sql.SQLExceptionpublic long executeLargeUpdate(java.lang.String sql,
int[] columnIndexes)
throws java.sql.SQLException
executeLargeUpdate in interface java.sql.Statementjava.sql.SQLExceptionpublic long executeLargeUpdate(java.lang.String sql,
java.lang.String[] columnNames)
throws java.sql.SQLException
executeLargeUpdate in interface java.sql.Statementjava.sql.SQLExceptionpublic long executeLargeUpdate()
throws java.sql.SQLException
java.sql.SQLExceptionpublic boolean isClosed()
throws java.sql.SQLException
isClosed in interface java.sql.Statementjava.sql.SQLExceptionpublic void setPoolable(boolean poolable)
throws java.sql.SQLException
setPoolable in interface java.sql.Statementjava.sql.SQLExceptionpublic boolean isPoolable()
throws java.sql.SQLException
isPoolable in interface java.sql.Statementjava.sql.SQLExceptionpublic boolean isWrapperFor(java.lang.Class<?> iface)
throws java.sql.SQLException
isWrapperFor in interface java.sql.Wrapperjava.sql.SQLExceptionpublic <T> T unwrap(java.lang.Class<T> iface)
throws java.sql.SQLException
unwrap in interface java.sql.Wrapperjava.sql.SQLExceptionpublic void closeOnCompletion()
throws java.sql.SQLException
closeOnCompletion in interface java.sql.Statementjava.sql.SQLExceptionpublic boolean isCloseOnCompletion()
throws java.sql.SQLException
isCloseOnCompletion in interface java.sql.Statementjava.sql.SQLExceptionprotected void checkCompletion()
throws java.sql.SQLException
java.sql.SQLExceptionpublic boolean getMoreResults(int current)
throws java.sql.SQLException
getMoreResults in interface java.sql.Statementjava.sql.SQLExceptionpublic java.sql.ResultSet getGeneratedKeys()
throws java.sql.SQLException
getGeneratedKeys in interface java.sql.Statementjava.sql.SQLExceptionpublic int executeUpdate(java.lang.String sql,
int autoGeneratedKeys)
throws java.sql.SQLException
executeUpdate in interface java.sql.Statementjava.sql.SQLExceptionpublic int executeUpdate(java.lang.String sql,
int[] columnIndexes)
throws java.sql.SQLException
executeUpdate in interface java.sql.Statementjava.sql.SQLExceptionpublic int executeUpdate(java.lang.String sql,
java.lang.String[] columnNames)
throws java.sql.SQLException
executeUpdate in interface java.sql.Statementjava.sql.SQLExceptionpublic boolean execute(java.lang.String sql,
int autoGeneratedKeys)
throws java.sql.SQLException
execute in interface java.sql.Statementjava.sql.SQLExceptionpublic boolean execute(java.lang.String sql,
int[] columnIndexes)
throws java.sql.SQLException
execute in interface java.sql.Statementjava.sql.SQLExceptionpublic boolean execute(java.lang.String sql,
java.lang.String[] columnNames)
throws java.sql.SQLException
execute in interface java.sql.Statementjava.sql.SQLExceptionpublic int getResultSetHoldability()
throws java.sql.SQLException
getResultSetHoldability in interface java.sql.Statementjava.sql.SQLExceptionpublic java.sql.ResultSet createDriverResultSet(Field[] fields, java.util.List<byte[][]> tuples) throws java.sql.SQLException
BaseStatementcreateDriverResultSet in interface BaseStatementfields - the column metadata for the resultsettuples - the resultset datajava.sql.SQLException - if something goes wrongprotected void transformQueriesAndParameters()
throws java.sql.SQLException
java.sql.SQLExceptionCopyright © 2021 PostgreSQL Global Development Group. All rights reserved.