Class BrokeredStatement

java.lang.Object
org.apache.derby.iapi.jdbc.BrokeredStatement
All Implemented Interfaces:
AutoCloseable, Statement, Wrapper, EngineStatement
Direct Known Subclasses:
BrokeredPreparedStatement

public class BrokeredStatement extends Object implements EngineStatement
A Statement implementation that forwards all of its requests to an underlying Statement. This class implements the JDBC 4.1 interface.
  • Field Details

    • control

      final BrokeredStatementControl control
      My control. Use the controlCheck() method to obtain the control when calling a check method. This will result in the correct exception being thrown if the statement is already closed.
    • resultSetType

      final int resultSetType
    • resultSetConcurrency

      final int resultSetConcurrency
    • resultSetHoldability

      final int resultSetHoldability
    • cursorName

      private String cursorName
      My state
    • escapeProcessing

      private Boolean escapeProcessing
  • Constructor Details

  • Method Details

    • addBatch

      public final void addBatch(String sql) throws SQLException
      Specified by:
      addBatch in interface Statement
      Throws:
      SQLException
    • clearBatch

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

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

      public final void cancel() throws SQLException
      Specified by:
      cancel in interface Statement
      Throws:
      SQLException
    • execute

      public final boolean execute(String sql) throws SQLException
      Specified by:
      execute in interface Statement
      Throws:
      SQLException
    • executeQuery

      public final ResultSet executeQuery(String sql) throws SQLException
      Specified by:
      executeQuery in interface Statement
      Throws:
      SQLException
    • executeUpdate

      public final int executeUpdate(String sql) throws SQLException
      Specified by:
      executeUpdate in interface Statement
      Throws:
      SQLException
    • close

      public void close() throws SQLException
      In many cases, it is desirable to immediately release a Statements's database and JDBC resources instead of waiting for this to happen when it is automatically closed; the close method provides this immediate release.

      Note: A Statement is automatically closed when it is garbage collected. When a Statement is closed its current ResultSet, if one exists, is also closed.

      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Statement
      Throws:
      SQLException - thrown on failure.
    • getConnection

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

      public final int getFetchDirection() throws SQLException
      Specified by:
      getFetchDirection in interface Statement
      Throws:
      SQLException
    • getFetchSize

      public final int getFetchSize() throws SQLException
      Specified by:
      getFetchSize in interface Statement
      Throws:
      SQLException
    • getMaxFieldSize

      public final int getMaxFieldSize() throws SQLException
      Specified by:
      getMaxFieldSize in interface Statement
      Throws:
      SQLException
    • getMaxRows

      public final int getMaxRows() throws SQLException
      Specified by:
      getMaxRows in interface Statement
      Throws:
      SQLException
    • getResultSetConcurrency

      public final int getResultSetConcurrency() throws SQLException
      Specified by:
      getResultSetConcurrency in interface Statement
      Throws:
      SQLException
    • setMaxFieldSize

      public final void setMaxFieldSize(int max) throws SQLException
      The maxFieldSize limit (in bytes) is set to limit the size of data that can be returned for any column value; it only applies to BINARY, VARBINARY, LONGVARBINARY, CHAR, VARCHAR, and LONGVARCHAR fields. If the limit is exceeded, the excess data is silently discarded.
      Specified by:
      setMaxFieldSize in interface Statement
      Parameters:
      max - the new max column size limit; zero means unlimited
      Throws:
      SQLException - thrown on failure.
    • setMaxRows

      public final void setMaxRows(int max) throws SQLException
      The maxRows limit is set to limit the number of rows that any ResultSet can contain. If the limit is exceeded, the excess rows are silently dropped.
      Specified by:
      setMaxRows in interface Statement
      Parameters:
      max - the new max rows limit; zero means unlimited
      Throws:
      SQLException - thrown on failure.
    • setEscapeProcessing

      public final void setEscapeProcessing(boolean enable) throws SQLException
      If escape scanning is on (the default) the driver will do escape substitution before sending the SQL to the database.
      Specified by:
      setEscapeProcessing in interface Statement
      Parameters:
      enable - true to enable; false to disable
      Throws:
      SQLException - thrown on failure.
    • getWarnings

      public final SQLWarning getWarnings() throws SQLException
      The first warning reported by calls on this Statement is returned. A Statment's execute methods clear its SQLWarning chain. Subsequent Statement warnings will be chained to this SQLWarning.

      The warning chain is automatically cleared each time a statement is (re)executed.

      Note: If you are processing a ResultSet then any warnings associated with ResultSet reads will be chained on the ResultSet object.

      Specified by:
      getWarnings in interface Statement
      Returns:
      the first SQLWarning or null
      Throws:
      SQLException - thrown on failure.
    • clearWarnings

      public final void clearWarnings() throws SQLException
      After this call getWarnings returns null until a new warning is reported for this Statement.
      Specified by:
      clearWarnings in interface Statement
      Throws:
      SQLException - thrown on failure.
    • setCursorName

      public final void setCursorName(String name) throws SQLException
      setCursorName defines the SQL cursor name that will be used by subsequent Statement execute methods. This name can then be used in SQL positioned update/delete statements to identify the current row in the ResultSet generated by this getStatement(). If the database doesn't support positioned update/delete, this method is a noop.

      Note: By definition, positioned update/delete execution must be done by a different Statement than the one which generated the ResultSet being used for positioning. Also, cursor names must be unique within a Connection.

      Specified by:
      setCursorName in interface Statement
      Parameters:
      name - the new cursor name.
      Throws:
      SQLException
    • getResultSet

      public final ResultSet getResultSet() throws SQLException
      getResultSet returns the current result as a ResultSet. It should only be called once per result.
      Specified by:
      getResultSet in interface Statement
      Returns:
      the current result as a ResultSet; null if the result is an update count or there are no more results or the statement was closed.
      Throws:
      SQLException
      See Also:
    • getUpdateCount

      public final int getUpdateCount() throws SQLException
      getUpdateCount returns the current result as an update count; if the result is a ResultSet or there are no more results -1 is returned. It should only be called once per result.

      The only way to tell for sure that the result is an update count is to first test to see if it is a ResultSet. If it is not a ResultSet it is either an update count or there are no more results.

      Specified by:
      getUpdateCount in interface Statement
      Returns:
      the current result as an update count; -1 if it is a ResultSet or there are no more results
      Throws:
      SQLException
      See Also:
    • getMoreResults

      public final boolean getMoreResults() throws SQLException
      getMoreResults moves to a Statement's next result. It returns true if this result is a ResultSet. getMoreResults also implicitly closes any current ResultSet obtained with getResultSet. There are no more results when (!getMoreResults() && (getUpdateCount() == -1)
      Specified by:
      getMoreResults in interface Statement
      Returns:
      true if the next result is a ResultSet; false if it is an update count or there are no more results
      Throws:
      SQLException - thrown on failure.
      See Also:
    • getResultSetType

      public final int getResultSetType() throws SQLException
      JDBC 2.0 Determine the result set type.
      Specified by:
      getResultSetType in interface Statement
      Throws:
      SQLException - Feature not implemented for now.
    • setFetchDirection

      public final void setFetchDirection(int direction) throws SQLException
      JDBC 2.0 Give a hint as to the direction in which the rows in a result set will be processed. The hint applies only to result sets created using this Statement object. The default value is ResultSet.FETCH_FORWARD.
      Specified by:
      setFetchDirection in interface Statement
      Parameters:
      direction - the initial direction for processing rows
      Throws:
      SQLException - if a database-access error occurs or direction is not one of ResultSet.FETCH_FORWARD, ResultSet.FETCH_REVERSE, or ResultSet.FETCH_UNKNOWN
    • setFetchSize

      public final void setFetchSize(int rows) throws SQLException
      JDBC 2.0 Give the JDBC driver a hint as to the number of rows that should be fetched from the database when more rows are needed. The number of rows specified only affects result sets created using this getStatement(). If the value specified is zero, then the hint is ignored. The default value is zero.
      Specified by:
      setFetchSize in interface Statement
      Parameters:
      rows - the number of rows to fetch
      Throws:
      SQLException - if a database-access error occurs, or the condition 0 <= rows <= this.getMaxRows() is not satisfied.
    • getQueryTimeout

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

      public final void setQueryTimeout(int seconds) throws SQLException
      Specified by:
      setQueryTimeout in interface Statement
      Throws:
      SQLException
    • execute

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

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

      public final boolean execute(String sql, String[] columnNames) throws SQLException
      Specified by:
      execute in interface Statement
      Throws:
      SQLException
    • executeUpdate

      public final int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException
      Specified by:
      executeUpdate in interface Statement
      Throws:
      SQLException
    • executeUpdate

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

      public final int executeUpdate(String sql, String[] columnNames) throws SQLException
      Specified by:
      executeUpdate in interface Statement
      Throws:
      SQLException
    • getMoreResults

      public final boolean getMoreResults(int current) throws SQLException
      JDBC 3.0 Moves to this Statement obect's next result, deals with any current ResultSet object(s) according to the instructions specified by the given flag, and returns true if the next result is a ResultSet object
      Specified by:
      getMoreResults in interface Statement
      Parameters:
      current - - one of the following Statement constants indicating what should happen to current ResultSet objects obtained using the method getResultSetCLOSE_CURRENT_RESULT, KEEP_CURRENT_RESULT, or CLOSE_ALL_RESULTS
      Returns:
      true if the next result is a ResultSet; false if it is an update count or there are no more results
      Throws:
      SQLException - thrown on failure.
      See Also:
    • getGeneratedKeys

      public final ResultSet getGeneratedKeys() throws SQLException
      JDBC 3.0 Retrieves any auto-generated keys created as a result of executing this Statement object. If this Statement object did not generate any keys, an empty ResultSet object is returned. If this Statement is a non-insert statement, an exception will be thrown.
      Specified by:
      getGeneratedKeys in interface Statement
      Returns:
      a ResultSet object containing the auto-generated key(s) generated by the execution of this Statement object
      Throws:
      SQLException - if a database access error occurs
    • getResultSetHoldability

      public final int getResultSetHoldability() throws SQLException
      Return the holdability of ResultSets created by this Statement. If this Statement is active in a global transaction the CLOSE_CURSORS_ON_COMMIT will be returned regardless of the holdability it was created with. In a local transaction the original create holdabilty will be returned.
      Specified by:
      getResultSetHoldability in interface Statement
      Throws:
      SQLException
    • createDuplicateStatement

      public Statement createDuplicateStatement(Connection conn, Statement oldStatement) throws SQLException
      Throws:
      SQLException
    • setStatementState

      void setStatementState(Statement oldStatement, Statement newStatement) throws SQLException
      Throws:
      SQLException
    • getStatement

      public Statement getStatement() throws SQLException
      Throws:
      SQLException
    • wrapResultSet

      final ResultSet wrapResultSet(ResultSet rs)
      Provide the control access to every ResultSet we return. If required the control can wrap the ResultSet, but it (the control) must ensure a underlying ResultSet is only wrapped once, if say java.sql.Statement.getResultSet is returned twice.
      Parameters:
      rs - ResultSet being returned, can be null.
    • controlCheck

      final BrokeredStatementControl controlCheck() throws SQLException
      Get the BrokeredStatementControl in order to perform a check. Obtained indirectly to ensure that the correct exception is thrown if the Statement has been closed.
      Throws:
      SQLException
    • isWrapperFor

      public boolean isWrapperFor(Class iface) throws SQLException
      Returns false unless iface is implemented
      Specified by:
      isWrapperFor in interface Wrapper
      Parameters:
      iface - a Class defining an interface.
      Returns:
      true if this implements the interface or directly or indirectly wraps an object that does.
      Throws:
      SQLException - if an error occurs while determining whether this is a wrapper for an object with the given interface.
    • unwrap

      public <T> T unwrap(Class<T> iface) throws SQLException
      Returns this if this class implements the specified interface.
      Specified by:
      unwrap in interface Wrapper
      Parameters:
      iface - a class defining an interface
      Returns:
      an object that implements the interface
      Throws:
      SQLException - if no object is found that implements the interface
    • isClosed

      public final boolean isClosed() throws SQLException
      Checks if the statement is closed.
      Specified by:
      isClosed in interface Statement
      Returns:
      true if the statement is closed, false otherwise
      Throws:
      SQLException - if an error occurs
    • checkIfClosed

      protected final void checkIfClosed() throws SQLException
      Checks if the statement is closed and throws an exception if it is.
      Throws:
      SQLException - if the statement is closed
    • unableToUnwrap

      final SQLException unableToUnwrap(Class iface)
      Return an exception that reports that an unwrap operation has failed because the object couldn't be cast to the specified interface.
      Parameters:
      iface - the class or interface passed in to the failed unwrap call
      Returns:
      an exception indicating that unwrap failed
    • isPoolable

      public final boolean isPoolable() throws SQLException
      Forwards to the real Statement.
      Specified by:
      isPoolable in interface Statement
      Returns:
      true if the underlying Statement is poolable, false otherwise.
      Throws:
      SQLException - if the forwarding call fails.
    • setPoolable

      public final void setPoolable(boolean poolable) throws SQLException
      Forwards to the real Statement.
      Specified by:
      setPoolable in interface Statement
      Parameters:
      poolable - the new value for the poolable hint.
      Throws:
      SQLException - if the forwarding call fails.
    • closeOnCompletion

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

      public boolean isCloseOnCompletion() throws SQLException
      Specified by:
      isCloseOnCompletion in interface EngineStatement
      Specified by:
      isCloseOnCompletion in interface Statement
      Throws:
      SQLException
    • executeLargeBatch

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

      public long executeLargeUpdate(String sql) throws SQLException
      Specified by:
      executeLargeUpdate in interface EngineStatement
      Specified by:
      executeLargeUpdate in interface Statement
      Throws:
      SQLException
    • executeLargeUpdate

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

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

      public long executeLargeUpdate(String sql, String[] columnNames) throws SQLException
      Specified by:
      executeLargeUpdate in interface EngineStatement
      Specified by:
      executeLargeUpdate in interface Statement
      Throws:
      SQLException
    • getLargeMaxRows

      public long getLargeMaxRows() throws SQLException
      Specified by:
      getLargeMaxRows in interface EngineStatement
      Specified by:
      getLargeMaxRows in interface Statement
      Throws:
      SQLException
    • getLargeUpdateCount

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

      public void setLargeMaxRows(long max) throws SQLException
      Specified by:
      setLargeMaxRows in interface EngineStatement
      Specified by:
      setLargeMaxRows in interface Statement
      Throws:
      SQLException