Class PgStatement

  • All Implemented Interfaces:
    java.lang.AutoCloseable, java.sql.Statement, java.sql.Wrapper, BaseStatement, PGStatement

    public class PgStatement
    extends java.lang.Object
    implements java.sql.Statement, BaseStatement
    • Field Detail

      • batchStatements

        protected java.util.ArrayList<Query> batchStatements
      • batchParameters

        protected java.util.ArrayList<ParameterList> batchParameters
      • resultsettype

        protected final int resultsettype
      • concurrency

        protected final int concurrency
      • fetchdirection

        protected int fetchdirection
      • wantsGeneratedKeysOnce

        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.
      • wantsGeneratedKeysAlways

        public boolean wantsGeneratedKeysAlways
        Was this PreparedStatement created to return generated keys for every execution? This is set at creation time and never cleared by execution.
      • warnings

        protected volatile org.postgresql.jdbc.PSQLWarningWrapper warnings
        The warnings chain.
      • maxrows

        protected int maxrows
        Maximum number of rows to return, 0 = unlimited.
      • fetchSize

        protected int fetchSize
        Number of rows to get in a batch.
      • timeout

        protected long timeout
        Timeout (in milliseconds) for a query.
      • replaceProcessingEnabled

        protected boolean replaceProcessingEnabled
      • firstUnclosedResult

        protected ResultWrapper firstUnclosedResult
        The first unclosed result.
      • generatedKeys

        protected ResultWrapper generatedKeys
        Results returned by a statement that wants generated keys.
      • mPrepareThreshold

        protected int mPrepareThreshold
      • maxFieldSize

        protected int maxFieldSize
    • Method Detail

      • createResultSet

        public java.sql.ResultSet createResultSet​(Query originalQuery,
                                                  Field[] fields,
                                                  java.util.List<Tuple> tuples,
                                                  ResultCursor cursor)
                                           throws java.sql.SQLException
        Description copied from interface: BaseStatement
        Create a resultset from data retrieved from the server.
        Specified by:
        createResultSet in interface BaseStatement
        Parameters:
        originalQuery - the query that generated this resultset; used when dealing with updateable resultsets
        fields - the column metadata for the resultset
        tuples - the resultset data
        cursor - the cursor to use to retrieve more data from the server; if null, no additional data is present.
        Returns:
        the new ResultSet
        Throws:
        java.sql.SQLException - if something goes wrong
      • getFetchingCursorName

        public java.lang.String getFetchingCursorName()
      • getFetchSize

        public int getFetchSize()
        Specified by:
        getFetchSize in interface java.sql.Statement
      • wantsScrollableResultSet

        protected boolean wantsScrollableResultSet()
      • wantsHoldableResultSet

        protected boolean wantsHoldableResultSet()
      • executeQuery

        public java.sql.ResultSet executeQuery​(java.lang.String sql)
                                        throws java.sql.SQLException
        Specified by:
        executeQuery in interface java.sql.Statement
        Throws:
        java.sql.SQLException
      • getSingleResultSet

        protected java.sql.ResultSet getSingleResultSet()
                                                 throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • executeUpdate

        public int executeUpdate​(java.lang.String sql)
                          throws java.sql.SQLException
        Specified by:
        executeUpdate in interface java.sql.Statement
        Throws:
        java.sql.SQLException
      • checkNoResultUpdate

        protected final void checkNoResultUpdate()
                                          throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • execute

        public boolean execute​(java.lang.String sql)
                        throws java.sql.SQLException
        Specified by:
        execute in interface java.sql.Statement
        Throws:
        java.sql.SQLException
      • executeWithFlags

        public boolean executeWithFlags​(java.lang.String sql,
                                        int flags)
                                 throws java.sql.SQLException
        Description copied from interface: BaseStatement
        Execute a query, passing additional query flags.
        Specified by:
        executeWithFlags in interface BaseStatement
        Parameters:
        sql - the query to execute (JDBC-style query)
        flags - additional QueryExecutor flags for execution; these are bitwise-ORed into the default flags.
        Returns:
        true if there is a result set
        Throws:
        java.sql.SQLException - if something goes wrong.
      • executeWithFlags

        public boolean executeWithFlags​(CachedQuery simpleQuery,
                                        int flags)
                                 throws java.sql.SQLException
        Description copied from interface: BaseStatement
        Execute a query, passing additional query flags.
        Specified by:
        executeWithFlags in interface BaseStatement
        Parameters:
        simpleQuery - the query to execute (native to PostgreSQL)
        flags - additional QueryExecutor flags for execution; these are bitwise-ORed into the default flags.
        Returns:
        true if there is a result set
        Throws:
        java.sql.SQLException - if something goes wrong.
      • executeWithFlags

        public boolean executeWithFlags​(int flags)
                                 throws java.sql.SQLException
        Description copied from interface: BaseStatement
        Execute a prepared query, passing additional query flags.
        Specified by:
        executeWithFlags in interface BaseStatement
        Parameters:
        flags - additional QueryExecutor flags for execution; these are bitwise-ORed into the default flags.
        Returns:
        true if there is a result set
        Throws:
        java.sql.SQLException - if something goes wrong.
      • closeForNextExecution

        protected void closeForNextExecution()
                                      throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • isOneShotQuery

        protected boolean isOneShotQuery​(CachedQuery cachedQuery)
        Returns true if query is unlikely to be reused.
        Parameters:
        cachedQuery - to check (null if current query)
        Returns:
        true if query is unlikely to be reused
      • execute

        protected final void execute​(CachedQuery cachedQuery,
                                     ParameterList queryParameters,
                                     int flags)
                              throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • setCursorName

        public void setCursorName​(java.lang.String name)
                           throws java.sql.SQLException
        Specified by:
        setCursorName in interface java.sql.Statement
        Throws:
        java.sql.SQLException
      • getUpdateCount

        public int getUpdateCount()
                           throws java.sql.SQLException
        Specified by:
        getUpdateCount in interface java.sql.Statement
        Throws:
        java.sql.SQLException
      • getMoreResults

        public boolean getMoreResults()
                               throws java.sql.SQLException
        Specified by:
        getMoreResults in interface java.sql.Statement
        Throws:
        java.sql.SQLException
      • getMaxRows

        public int getMaxRows()
                       throws java.sql.SQLException
        Specified by:
        getMaxRows in interface java.sql.Statement
        Throws:
        java.sql.SQLException
      • setMaxRows

        public void setMaxRows​(int max)
                        throws java.sql.SQLException
        Specified by:
        setMaxRows in interface java.sql.Statement
        Throws:
        java.sql.SQLException
      • setEscapeProcessing

        public void setEscapeProcessing​(boolean enable)
                                 throws java.sql.SQLException
        Specified by:
        setEscapeProcessing in interface java.sql.Statement
        Throws:
        java.sql.SQLException
      • getQueryTimeout

        public int getQueryTimeout()
                            throws java.sql.SQLException
        Specified by:
        getQueryTimeout in interface java.sql.Statement
        Throws:
        java.sql.SQLException
      • setQueryTimeout

        public void setQueryTimeout​(int seconds)
                             throws java.sql.SQLException
        Specified by:
        setQueryTimeout in interface java.sql.Statement
        Throws:
        java.sql.SQLException
      • getQueryTimeoutMs

        public long getQueryTimeoutMs()
                               throws java.sql.SQLException
        The queryTimeout limit is the number of milliseconds the driver will wait for a Statement to execute. If the limit is exceeded, a SQLException is thrown.
        Returns:
        the current query timeout limit in milliseconds; 0 = unlimited
        Throws:
        java.sql.SQLException - if a database access error occurs
      • setQueryTimeoutMs

        public void setQueryTimeoutMs​(long millis)
                               throws java.sql.SQLException
        Sets the queryTimeout limit.
        Parameters:
        millis - - the new query timeout limit in milliseconds
        Throws:
        java.sql.SQLException - if a database access error occurs
      • addWarning

        public 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

        Parameters:
        warn - warning to add
      • getWarnings

        public java.sql.SQLWarning getWarnings()
                                        throws java.sql.SQLException
        Specified by:
        getWarnings in interface java.sql.Statement
        Throws:
        java.sql.SQLException
      • getMaxFieldSize

        public int getMaxFieldSize()
                            throws java.sql.SQLException
        Specified by:
        getMaxFieldSize in interface java.sql.Statement
        Throws:
        java.sql.SQLException
      • setMaxFieldSize

        public void setMaxFieldSize​(int max)
                             throws java.sql.SQLException
        Specified by:
        setMaxFieldSize in interface java.sql.Statement
        Throws:
        java.sql.SQLException
      • clearWarnings

        public 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.

        Specified by:
        clearWarnings in interface java.sql.Statement
        Throws:
        java.sql.SQLException
      • getResultSet

        public java.sql.ResultSet getResultSet()
                                        throws java.sql.SQLException
        Specified by:
        getResultSet in interface java.sql.Statement
        Throws:
        java.sql.SQLException
      • close

        public final void close()
                         throws java.sql.SQLException
        Note: even though Statement is automatically closed when it is garbage collected, it is better to close it explicitly to lower resource consumption.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.sql.Statement
        Throws:
        java.sql.SQLException
      • closeImpl

        protected void closeImpl()
                          throws java.sql.SQLException
        This is guaranteed to be called exactly once even in case of concurrent close() calls.
        Throws:
        java.sql.SQLException - in case of error
      • getLastOID

        public long getLastOID()
                        throws java.sql.SQLException
        Description copied from interface: PGStatement
        Returns the Last inserted/updated oid.
        Specified by:
        getLastOID in interface PGStatement
        Returns:
        OID of last insert
        Throws:
        java.sql.SQLException - if something goes wrong
      • setPrepareThreshold

        public void setPrepareThreshold​(int newThreshold)
                                 throws java.sql.SQLException
        Description copied from interface: PGStatement

        Sets 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.

        Specified by:
        setPrepareThreshold in interface PGStatement
        Parameters:
        newThreshold - the new threshold for this statement
        Throws:
        java.sql.SQLException - if an exception occurs while changing the threshold
      • setUseServerPrepare

        public void setUseServerPrepare​(boolean flag)
                                 throws java.sql.SQLException
        Description copied from interface: PGStatement
        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).
        Specified by:
        setUseServerPrepare in interface PGStatement
        Parameters:
        flag - use server prepare
        Throws:
        java.sql.SQLException - if something goes wrong
      • isUseServerPrepare

        public boolean isUseServerPrepare()
        Description copied from interface: PGStatement
        Checks if this statement will be executed as a server-prepared statement. A return value of true indicates that the next execution of the statement will be done as a server-prepared statement, assuming the underlying protocol supports it.
        Specified by:
        isUseServerPrepare in interface PGStatement
        Returns:
        true if the next reuse of this statement will use a server-prepared statement
      • checkClosed

        protected void checkClosed()
                            throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • addBatch

        public void addBatch​(java.lang.String sql)
                      throws java.sql.SQLException
        Specified by:
        addBatch in interface java.sql.Statement
        Throws:
        java.sql.SQLException
      • clearBatch

        public void clearBatch()
                        throws java.sql.SQLException
        Specified by:
        clearBatch in interface java.sql.Statement
        Throws:
        java.sql.SQLException
      • executeBatch

        public int[] executeBatch()
                           throws java.sql.SQLException
        Specified by:
        executeBatch in interface java.sql.Statement
        Throws:
        java.sql.SQLException
      • cancel

        public void cancel()
                    throws java.sql.SQLException
        Specified by:
        cancel in interface java.sql.Statement
        Throws:
        java.sql.SQLException
      • getConnection

        public java.sql.Connection getConnection()
                                          throws java.sql.SQLException
        Specified by:
        getConnection in interface java.sql.Statement
        Throws:
        java.sql.SQLException
      • getFetchDirection

        public int getFetchDirection()
        Specified by:
        getFetchDirection in interface java.sql.Statement
      • getResultSetConcurrency

        public int getResultSetConcurrency()
        Specified by:
        getResultSetConcurrency in interface java.sql.Statement
      • getResultSetType

        public int getResultSetType()
        Specified by:
        getResultSetType in interface java.sql.Statement
      • setFetchDirection

        public void setFetchDirection​(int direction)
                               throws java.sql.SQLException
        Specified by:
        setFetchDirection in interface java.sql.Statement
        Throws:
        java.sql.SQLException
      • setFetchSize

        public void setFetchSize​(int rows)
                          throws java.sql.SQLException
        Specified by:
        setFetchSize in interface java.sql.Statement
        Throws:
        java.sql.SQLException
      • getForceBinaryTransfer

        protected boolean getForceBinaryTransfer()
      • getLargeUpdateCount

        public long getLargeUpdateCount()
                                 throws java.sql.SQLException
        Specified by:
        getLargeUpdateCount in interface java.sql.Statement
        Throws:
        java.sql.SQLException
      • setLargeMaxRows

        public void setLargeMaxRows​(long max)
                             throws java.sql.SQLException
        Specified by:
        setLargeMaxRows in interface java.sql.Statement
        Throws:
        java.sql.SQLException
      • getLargeMaxRows

        public long getLargeMaxRows()
                             throws java.sql.SQLException
        Specified by:
        getLargeMaxRows in interface java.sql.Statement
        Throws:
        java.sql.SQLException
      • executeLargeBatch

        public long[] executeLargeBatch()
                                 throws java.sql.SQLException
        Specified by:
        executeLargeBatch in interface java.sql.Statement
        Throws:
        java.sql.SQLException
      • executeLargeUpdate

        public long executeLargeUpdate​(java.lang.String sql)
                                throws java.sql.SQLException
        Specified by:
        executeLargeUpdate in interface java.sql.Statement
        Throws:
        java.sql.SQLException
      • executeLargeUpdate

        public long executeLargeUpdate​(java.lang.String sql,
                                       int autoGeneratedKeys)
                                throws java.sql.SQLException
        Specified by:
        executeLargeUpdate in interface java.sql.Statement
        Throws:
        java.sql.SQLException
      • executeLargeUpdate

        public long executeLargeUpdate​(java.lang.String sql,
                                       int[] columnIndexes)
                                throws java.sql.SQLException
        Specified by:
        executeLargeUpdate in interface java.sql.Statement
        Throws:
        java.sql.SQLException
      • executeLargeUpdate

        public long executeLargeUpdate​(java.lang.String sql,
                                       java.lang.String[] columnNames)
                                throws java.sql.SQLException
        Specified by:
        executeLargeUpdate in interface java.sql.Statement
        Throws:
        java.sql.SQLException
      • isClosed

        public boolean isClosed()
                         throws java.sql.SQLException
        Specified by:
        isClosed in interface java.sql.Statement
        Throws:
        java.sql.SQLException
      • setPoolable

        public void setPoolable​(boolean poolable)
                         throws java.sql.SQLException
        Specified by:
        setPoolable in interface java.sql.Statement
        Throws:
        java.sql.SQLException
      • isPoolable

        public boolean isPoolable()
                           throws java.sql.SQLException
        Specified by:
        isPoolable in interface java.sql.Statement
        Throws:
        java.sql.SQLException
      • isWrapperFor

        public boolean isWrapperFor​(java.lang.Class<?> iface)
                             throws java.sql.SQLException
        Specified by:
        isWrapperFor in interface java.sql.Wrapper
        Throws:
        java.sql.SQLException
      • unwrap

        public <T> T unwrap​(java.lang.Class<T> iface)
                     throws java.sql.SQLException
        Specified by:
        unwrap in interface java.sql.Wrapper
        Throws:
        java.sql.SQLException
      • closeOnCompletion

        public void closeOnCompletion()
                               throws java.sql.SQLException
        Specified by:
        closeOnCompletion in interface java.sql.Statement
        Throws:
        java.sql.SQLException
      • isCloseOnCompletion

        public boolean isCloseOnCompletion()
                                    throws java.sql.SQLException
        Specified by:
        isCloseOnCompletion in interface java.sql.Statement
        Throws:
        java.sql.SQLException
      • checkCompletion

        protected void checkCompletion()
                                throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • getMoreResults

        public boolean getMoreResults​(int current)
                               throws java.sql.SQLException
        Specified by:
        getMoreResults in interface java.sql.Statement
        Throws:
        java.sql.SQLException
      • getGeneratedKeys

        public java.sql.ResultSet getGeneratedKeys()
                                            throws java.sql.SQLException
        Specified by:
        getGeneratedKeys in interface java.sql.Statement
        Throws:
        java.sql.SQLException
      • executeUpdate

        public int executeUpdate​(java.lang.String sql,
                                 int autoGeneratedKeys)
                          throws java.sql.SQLException
        Specified by:
        executeUpdate in interface java.sql.Statement
        Throws:
        java.sql.SQLException
      • executeUpdate

        public int executeUpdate​(java.lang.String sql,
                                 int[] columnIndexes)
                          throws java.sql.SQLException
        Specified by:
        executeUpdate in interface java.sql.Statement
        Throws:
        java.sql.SQLException
      • executeUpdate

        public int executeUpdate​(java.lang.String sql,
                                 java.lang.String[] columnNames)
                          throws java.sql.SQLException
        Specified by:
        executeUpdate in interface java.sql.Statement
        Throws:
        java.sql.SQLException
      • execute

        public boolean execute​(java.lang.String sql,
                               int autoGeneratedKeys)
                        throws java.sql.SQLException
        Specified by:
        execute in interface java.sql.Statement
        Throws:
        java.sql.SQLException
      • execute

        public boolean execute​(java.lang.String sql,
                               int[] columnIndexes)
                        throws java.sql.SQLException
        Specified by:
        execute in interface java.sql.Statement
        Throws:
        java.sql.SQLException
      • execute

        public boolean execute​(java.lang.String sql,
                               java.lang.String[] columnNames)
                        throws java.sql.SQLException
        Specified by:
        execute in interface java.sql.Statement
        Throws:
        java.sql.SQLException
      • getResultSetHoldability

        public int getResultSetHoldability()
                                    throws java.sql.SQLException
        Specified by:
        getResultSetHoldability in interface java.sql.Statement
        Throws:
        java.sql.SQLException
      • createDriverResultSet

        public java.sql.ResultSet createDriverResultSet​(Field[] fields,
                                                        java.util.List<Tuple> tuples)
                                                 throws java.sql.SQLException
        Description copied from interface: BaseStatement
        Create a synthetic resultset from data provided by the driver.
        Specified by:
        createDriverResultSet in interface BaseStatement
        Parameters:
        fields - the column metadata for the resultset
        tuples - the resultset data
        Returns:
        the new ResultSet
        Throws:
        java.sql.SQLException - if something goes wrong
      • transformQueriesAndParameters

        protected void transformQueriesAndParameters()
                                              throws java.sql.SQLException
        Throws:
        java.sql.SQLException