Class BrokeredStatement
- java.lang.Object
-
- org.apache.derby.iapi.jdbc.BrokeredStatement
-
- All Implemented Interfaces:
java.lang.AutoCloseable
,java.sql.Statement
,java.sql.Wrapper
,EngineStatement
- Direct Known Subclasses:
BrokeredPreparedStatement
public class BrokeredStatement extends java.lang.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 Summary
Fields Modifier and Type Field Description (package private) BrokeredStatementControl
control
My control.private java.lang.String
cursorName
My stateprivate java.lang.Boolean
escapeProcessing
(package private) int
resultSetConcurrency
(package private) int
resultSetHoldability
(package private) int
resultSetType
-
Constructor Summary
Constructors Constructor Description BrokeredStatement(BrokeredStatementControl control)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addBatch(java.lang.String sql)
void
cancel()
protected void
checkIfClosed()
Checks if the statement is closed and throws an exception if it is.void
clearBatch()
void
clearWarnings()
After this call getWarnings returns null until a new warning is reported for this Statement.void
close()
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.void
closeOnCompletion()
(package private) BrokeredStatementControl
controlCheck()
Get the BrokeredStatementControl in order to perform a check.java.sql.Statement
createDuplicateStatement(java.sql.Connection conn, java.sql.Statement oldStatement)
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(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)
java.sql.Connection
getConnection()
int
getFetchDirection()
int
getFetchSize()
java.sql.ResultSet
getGeneratedKeys()
JDBC 3.0 Retrieves any auto-generated keys created as a result of executing this Statement object.long
getLargeMaxRows()
long
getLargeUpdateCount()
int
getMaxFieldSize()
int
getMaxRows()
boolean
getMoreResults()
getMoreResults moves to a Statement's next result.boolean
getMoreResults(int current)
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 objectint
getQueryTimeout()
java.sql.ResultSet
getResultSet()
getResultSet returns the current result as a ResultSet.int
getResultSetConcurrency()
int
getResultSetHoldability()
Return the holdability of ResultSets created by this Statement.int
getResultSetType()
JDBC 2.0 Determine the result set type.java.sql.Statement
getStatement()
int
getUpdateCount()
getUpdateCount returns the current result as an update count; if the result is a ResultSet or there are no more results -1 is returned.java.sql.SQLWarning
getWarnings()
The first warning reported by calls on this Statement is returned.boolean
isClosed()
Checks if the statement is closed.boolean
isCloseOnCompletion()
boolean
isPoolable()
Forwards to the real Statement.boolean
isWrapperFor(java.lang.Class iface)
Returns false unlessiface
is implementedvoid
setCursorName(java.lang.String name)
setCursorName defines the SQL cursor name that will be used by subsequent Statement execute methods.void
setEscapeProcessing(boolean enable)
If escape scanning is on (the default) the driver will do escape substitution before sending the SQL to the database.void
setFetchDirection(int direction)
JDBC 2.0 Give a hint as to the direction in which the rows in a result set will be processed.void
setFetchSize(int rows)
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.void
setLargeMaxRows(long max)
void
setMaxFieldSize(int max)
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.void
setMaxRows(int max)
The maxRows limit is set to limit the number of rows that any ResultSet can contain.void
setPoolable(boolean poolable)
Forwards to the real Statement.void
setQueryTimeout(int seconds)
(package private) void
setStatementState(java.sql.Statement oldStatement, java.sql.Statement newStatement)
(package private) java.sql.SQLException
unableToUnwrap(java.lang.Class iface)
Return an exception that reports that an unwrap operation has failed because the object couldn't be cast to the specified interface.<T> T
unwrap(java.lang.Class<T> iface)
Returnsthis
if this class implements the specified interface.(package private) java.sql.ResultSet
wrapResultSet(java.sql.ResultSet rs)
Provide the control access to every ResultSet we return.
-
-
-
Field Detail
-
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 java.lang.String cursorName
My state
-
escapeProcessing
private java.lang.Boolean escapeProcessing
-
-
Constructor Detail
-
BrokeredStatement
BrokeredStatement(BrokeredStatementControl control) throws java.sql.SQLException
- Throws:
java.sql.SQLException
-
-
Method Detail
-
addBatch
public final void addBatch(java.lang.String sql) throws java.sql.SQLException
- Specified by:
addBatch
in interfacejava.sql.Statement
- Throws:
java.sql.SQLException
-
clearBatch
public final void clearBatch() throws java.sql.SQLException
- Specified by:
clearBatch
in interfacejava.sql.Statement
- Throws:
java.sql.SQLException
-
executeBatch
public final int[] executeBatch() throws java.sql.SQLException
- Specified by:
executeBatch
in interfacejava.sql.Statement
- Throws:
java.sql.SQLException
-
cancel
public final void cancel() throws java.sql.SQLException
- Specified by:
cancel
in interfacejava.sql.Statement
- Throws:
java.sql.SQLException
-
execute
public final boolean execute(java.lang.String sql) throws java.sql.SQLException
- Specified by:
execute
in interfacejava.sql.Statement
- Throws:
java.sql.SQLException
-
executeQuery
public final java.sql.ResultSet executeQuery(java.lang.String sql) throws java.sql.SQLException
- Specified by:
executeQuery
in interfacejava.sql.Statement
- Throws:
java.sql.SQLException
-
executeUpdate
public final int executeUpdate(java.lang.String sql) throws java.sql.SQLException
- Specified by:
executeUpdate
in interfacejava.sql.Statement
- Throws:
java.sql.SQLException
-
close
public void close() throws java.sql.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 interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.sql.Statement
- Throws:
java.sql.SQLException
- thrown on failure.
-
getConnection
public final java.sql.Connection getConnection() throws java.sql.SQLException
- Specified by:
getConnection
in interfacejava.sql.Statement
- Throws:
java.sql.SQLException
-
getFetchDirection
public final int getFetchDirection() throws java.sql.SQLException
- Specified by:
getFetchDirection
in interfacejava.sql.Statement
- Throws:
java.sql.SQLException
-
getFetchSize
public final int getFetchSize() throws java.sql.SQLException
- Specified by:
getFetchSize
in interfacejava.sql.Statement
- Throws:
java.sql.SQLException
-
getMaxFieldSize
public final int getMaxFieldSize() throws java.sql.SQLException
- Specified by:
getMaxFieldSize
in interfacejava.sql.Statement
- Throws:
java.sql.SQLException
-
getMaxRows
public final int getMaxRows() throws java.sql.SQLException
- Specified by:
getMaxRows
in interfacejava.sql.Statement
- Throws:
java.sql.SQLException
-
getResultSetConcurrency
public final int getResultSetConcurrency() throws java.sql.SQLException
- Specified by:
getResultSetConcurrency
in interfacejava.sql.Statement
- Throws:
java.sql.SQLException
-
setMaxFieldSize
public final void setMaxFieldSize(int max) throws java.sql.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 interfacejava.sql.Statement
- Parameters:
max
- the new max column size limit; zero means unlimited- Throws:
java.sql.SQLException
- thrown on failure.
-
setMaxRows
public final void setMaxRows(int max) throws java.sql.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 interfacejava.sql.Statement
- Parameters:
max
- the new max rows limit; zero means unlimited- Throws:
java.sql.SQLException
- thrown on failure.
-
setEscapeProcessing
public final void setEscapeProcessing(boolean enable) throws java.sql.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 interfacejava.sql.Statement
- Parameters:
enable
- true to enable; false to disable- Throws:
java.sql.SQLException
- thrown on failure.
-
getWarnings
public final java.sql.SQLWarning getWarnings() throws java.sql.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 interfacejava.sql.Statement
- Returns:
- the first SQLWarning or null
- Throws:
java.sql.SQLException
- thrown on failure.
-
clearWarnings
public final void clearWarnings() throws java.sql.SQLException
After this call getWarnings returns null until a new warning is reported for this Statement.- Specified by:
clearWarnings
in interfacejava.sql.Statement
- Throws:
java.sql.SQLException
- thrown on failure.
-
setCursorName
public final void setCursorName(java.lang.String name) throws java.sql.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 interfacejava.sql.Statement
- Parameters:
name
- the new cursor name.- Throws:
java.sql.SQLException
-
getResultSet
public final java.sql.ResultSet getResultSet() throws java.sql.SQLException
getResultSet returns the current result as a ResultSet. It should only be called once per result.- Specified by:
getResultSet
in interfacejava.sql.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:
java.sql.SQLException
- See Also:
execute(java.lang.String)
-
getUpdateCount
public final int getUpdateCount() throws java.sql.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 interfacejava.sql.Statement
- Returns:
- the current result as an update count; -1 if it is a ResultSet or there are no more results
- Throws:
java.sql.SQLException
- See Also:
execute(java.lang.String)
-
getMoreResults
public final boolean getMoreResults() throws java.sql.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 interfacejava.sql.Statement
- Returns:
- true if the next result is a ResultSet; false if it is an update count or there are no more results
- Throws:
java.sql.SQLException
- thrown on failure.- See Also:
execute(java.lang.String)
-
getResultSetType
public final int getResultSetType() throws java.sql.SQLException
JDBC 2.0 Determine the result set type.- Specified by:
getResultSetType
in interfacejava.sql.Statement
- Throws:
java.sql.SQLException
- Feature not implemented for now.
-
setFetchDirection
public final void setFetchDirection(int direction) throws java.sql.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 interfacejava.sql.Statement
- Parameters:
direction
- the initial direction for processing rows- Throws:
java.sql.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 java.sql.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 interfacejava.sql.Statement
- Parameters:
rows
- the number of rows to fetch- Throws:
java.sql.SQLException
- if a database-access error occurs, or the condition 0 <= rows <= this.getMaxRows() is not satisfied.
-
getQueryTimeout
public final int getQueryTimeout() throws java.sql.SQLException
- Specified by:
getQueryTimeout
in interfacejava.sql.Statement
- Throws:
java.sql.SQLException
-
setQueryTimeout
public final void setQueryTimeout(int seconds) throws java.sql.SQLException
- Specified by:
setQueryTimeout
in interfacejava.sql.Statement
- Throws:
java.sql.SQLException
-
execute
public final boolean execute(java.lang.String sql, int autoGeneratedKeys) throws java.sql.SQLException
- Specified by:
execute
in interfacejava.sql.Statement
- Throws:
java.sql.SQLException
-
execute
public final boolean execute(java.lang.String sql, int[] columnIndexes) throws java.sql.SQLException
- Specified by:
execute
in interfacejava.sql.Statement
- Throws:
java.sql.SQLException
-
execute
public final boolean execute(java.lang.String sql, java.lang.String[] columnNames) throws java.sql.SQLException
- Specified by:
execute
in interfacejava.sql.Statement
- Throws:
java.sql.SQLException
-
executeUpdate
public final int executeUpdate(java.lang.String sql, int autoGeneratedKeys) throws java.sql.SQLException
- Specified by:
executeUpdate
in interfacejava.sql.Statement
- Throws:
java.sql.SQLException
-
executeUpdate
public final int executeUpdate(java.lang.String sql, int[] columnIndexes) throws java.sql.SQLException
- Specified by:
executeUpdate
in interfacejava.sql.Statement
- Throws:
java.sql.SQLException
-
executeUpdate
public final int executeUpdate(java.lang.String sql, java.lang.String[] columnNames) throws java.sql.SQLException
- Specified by:
executeUpdate
in interfacejava.sql.Statement
- Throws:
java.sql.SQLException
-
getMoreResults
public final boolean getMoreResults(int current) throws java.sql.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 interfacejava.sql.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:
java.sql.SQLException
- thrown on failure.- See Also:
execute(java.lang.String)
-
getGeneratedKeys
public final java.sql.ResultSet getGeneratedKeys() throws java.sql.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 interfacejava.sql.Statement
- Returns:
- a ResultSet object containing the auto-generated key(s) generated by the execution of this Statement object
- Throws:
java.sql.SQLException
- if a database access error occurs
-
getResultSetHoldability
public final int getResultSetHoldability() throws java.sql.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 interfacejava.sql.Statement
- Throws:
java.sql.SQLException
-
createDuplicateStatement
public java.sql.Statement createDuplicateStatement(java.sql.Connection conn, java.sql.Statement oldStatement) throws java.sql.SQLException
- Throws:
java.sql.SQLException
-
setStatementState
void setStatementState(java.sql.Statement oldStatement, java.sql.Statement newStatement) throws java.sql.SQLException
- Throws:
java.sql.SQLException
-
getStatement
public java.sql.Statement getStatement() throws java.sql.SQLException
- Throws:
java.sql.SQLException
-
wrapResultSet
final java.sql.ResultSet wrapResultSet(java.sql.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 java.sql.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:
java.sql.SQLException
-
isWrapperFor
public boolean isWrapperFor(java.lang.Class iface) throws java.sql.SQLException
Returns false unlessiface
is implemented- Specified by:
isWrapperFor
in interfacejava.sql.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:
java.sql.SQLException
- if an error occurs while determining whether this is a wrapper for an object with the given interface.
-
unwrap
public <T> T unwrap(java.lang.Class<T> iface) throws java.sql.SQLException
Returnsthis
if this class implements the specified interface.- Specified by:
unwrap
in interfacejava.sql.Wrapper
- Parameters:
iface
- a class defining an interface- Returns:
- an object that implements the interface
- Throws:
java.sql.SQLException
- if no object is found that implements the interface
-
isClosed
public final boolean isClosed() throws java.sql.SQLException
Checks if the statement is closed.- Specified by:
isClosed
in interfacejava.sql.Statement
- Returns:
true
if the statement is closed,false
otherwise- Throws:
java.sql.SQLException
- if an error occurs
-
checkIfClosed
protected final void checkIfClosed() throws java.sql.SQLException
Checks if the statement is closed and throws an exception if it is.- Throws:
java.sql.SQLException
- if the statement is closed
-
unableToUnwrap
final java.sql.SQLException unableToUnwrap(java.lang.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 java.sql.SQLException
Forwards to the real Statement.- Specified by:
isPoolable
in interfacejava.sql.Statement
- Returns:
- true if the underlying Statement is poolable, false otherwise.
- Throws:
java.sql.SQLException
- if the forwarding call fails.
-
setPoolable
public final void setPoolable(boolean poolable) throws java.sql.SQLException
Forwards to the real Statement.- Specified by:
setPoolable
in interfacejava.sql.Statement
- Parameters:
poolable
- the new value for the poolable hint.- Throws:
java.sql.SQLException
- if the forwarding call fails.
-
closeOnCompletion
public void closeOnCompletion() throws java.sql.SQLException
- Specified by:
closeOnCompletion
in interfaceEngineStatement
- Specified by:
closeOnCompletion
in interfacejava.sql.Statement
- Throws:
java.sql.SQLException
-
isCloseOnCompletion
public boolean isCloseOnCompletion() throws java.sql.SQLException
- Specified by:
isCloseOnCompletion
in interfaceEngineStatement
- Specified by:
isCloseOnCompletion
in interfacejava.sql.Statement
- Throws:
java.sql.SQLException
-
executeLargeBatch
public long[] executeLargeBatch() throws java.sql.SQLException
- Specified by:
executeLargeBatch
in interfaceEngineStatement
- Specified by:
executeLargeBatch
in interfacejava.sql.Statement
- Throws:
java.sql.SQLException
-
executeLargeUpdate
public long executeLargeUpdate(java.lang.String sql) throws java.sql.SQLException
- Specified by:
executeLargeUpdate
in interfaceEngineStatement
- Specified by:
executeLargeUpdate
in interfacejava.sql.Statement
- Throws:
java.sql.SQLException
-
executeLargeUpdate
public long executeLargeUpdate(java.lang.String sql, int autoGeneratedKeys) throws java.sql.SQLException
- Specified by:
executeLargeUpdate
in interfaceEngineStatement
- Specified by:
executeLargeUpdate
in interfacejava.sql.Statement
- Throws:
java.sql.SQLException
-
executeLargeUpdate
public long executeLargeUpdate(java.lang.String sql, int[] columnIndexes) throws java.sql.SQLException
- Specified by:
executeLargeUpdate
in interfaceEngineStatement
- Specified by:
executeLargeUpdate
in interfacejava.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 interfaceEngineStatement
- Specified by:
executeLargeUpdate
in interfacejava.sql.Statement
- Throws:
java.sql.SQLException
-
getLargeMaxRows
public long getLargeMaxRows() throws java.sql.SQLException
- Specified by:
getLargeMaxRows
in interfaceEngineStatement
- Specified by:
getLargeMaxRows
in interfacejava.sql.Statement
- Throws:
java.sql.SQLException
-
getLargeUpdateCount
public long getLargeUpdateCount() throws java.sql.SQLException
- Specified by:
getLargeUpdateCount
in interfaceEngineStatement
- Specified by:
getLargeUpdateCount
in interfacejava.sql.Statement
- Throws:
java.sql.SQLException
-
setLargeMaxRows
public void setLargeMaxRows(long max) throws java.sql.SQLException
- Specified by:
setLargeMaxRows
in interfaceEngineStatement
- Specified by:
setLargeMaxRows
in interfacejava.sql.Statement
- Throws:
java.sql.SQLException
-
-