Package org.apache.derby.client.am
Class ClientStatement
- java.lang.Object
-
- org.apache.derby.client.am.ClientStatement
-
- All Implemented Interfaces:
java.lang.AutoCloseable
,java.sql.Statement
,java.sql.Wrapper
,StatementCallbackInterface
,UnitOfWorkListener
- Direct Known Subclasses:
ClientPreparedStatement
public class ClientStatement extends java.lang.Object implements java.sql.Statement, StatementCallbackInterface
-
-
Field Summary
Fields Modifier and Type Field Description (package private) Agent
agent_
(package private) int
autoGeneratedKeys_
(package private) java.util.ArrayList<java.lang.Object>
batch_
Cursor
cachedCursor_
Cursor
cachedSingletonRowData_
private boolean
closeOnCompletion_
private boolean
closingResultSets_
(package private) ClientConnection
connection_
java.lang.String
cursorAttributesToSendOnPrepare_
(package private) java.lang.String
cursorName_
protected boolean
doWriteTimeout
(package private) static int
executeMethod__
(package private) static int
executeQueryMethod__
(package private) static int
executeUpdateMethod__
(package private) int
fetchDirection_
private static long
fetchedRowBase
For use in debugging setLargeMaxRows() method added by JDBC 4.2(package private) int
fetchSize_
(package private) int[]
generatedKeysColumnIndexes_
(package private) java.lang.String[]
generatedKeysColumnNames_
(package private) ClientResultSet
generatedKeysResultSet_
private int
indexOfCurrentResultSet_
private static int
INSIDE_BRACKETED_COMMENT
private static int
INSIDE_SIMPLECOMMENT
(package private) boolean
isAutoCommittableStatement_
(package private) static int
isCall__
(package private) boolean
isCatalogQuery_
(package private) static int
isDeleteSql__
(package private) static int
isInsertSql__
protected boolean
isPoolable
(package private) boolean
isPreparedStatement_
(package private) static int
isQuery__
(package private) static int
isUpdate__
(package private) static int
isUpdateSql__
private MaterialStatement
materialStatement_
(package private) int
maxFieldSize_
(package private) long
maxRows_
(package private) boolean
openOnClient_
private static int
OUTSIDE
State constants used by the FSM inside getStatementToken.private java.sql.Statement
owner
The owner of this statement, if any.(package private) ClientPreparedStatement
preparedStatementForAutoGeneratedKeys_
(package private) ClientResultSet
resultSet_
int
resultSetConcurrency_
(package private) int
resultSetHoldability_
(package private) ClientResultSet[]
resultSetList_
(package private) ColumnMetaData
resultSetMetaData_
int
resultSetType_
private Section
section_
private Section
setSpecialRegisterSection_
This variable keeps track of a Section dediacted to writeSpecialRegister.(package private) Cursor
singletonRowData_
protected int
sqlMode_
(package private) int
sqlUpdateMode_
(package private) int
timeout_
protected static java.lang.String
TIMEOUT_STATEMENT
protected java.util.ArrayList<java.lang.String>
timeoutArrayList
(package private) long
updateCount_
private SqlWarning
warnings_
-
Constructor Summary
Constructors Modifier Constructor Description private
ClientStatement()
ClientStatement(Agent agent, ClientConnection connection)
ClientStatement(Agent agent, ClientConnection connection, int type, int concurrency, int holdability, int autoGeneratedKeys, java.lang.String[] columnNames, int[] columnIndexes)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
accumulateWarning(SqlWarning e)
void
addBatch(java.lang.String sql)
(package private) java.lang.String
cacheCursorAttributesToSendOnPrepare()
void
cancel()
(package private) void
checkAutoGeneratedKeysParameters()
(package private) void
checkForAppropriateSqlMode(int executeType, int sqlMode)
(package private) void
checkForClosedStatement()
protected void
checkForDuplicateCursorName()
private void
checkForInvalidBatchedSql(java.lang.String sql)
protected void
checkForStoredProcResultSetCount(int executeType)
Checks that a stored procedure returns the correct number of result sets given its execute type.private void
checkResultSetCount(int executeType)
Checks that the number of result sets returned by the statement is consistent with the executed type.void
clearBatch()
void
clearWarnings()
(package private) void
clearWarningsX()
void
close()
private void
closeEverythingExceptResultSets(boolean removeListener)
Close all resources except for ResultSets.(package private) void
closeMeOnCompletion()
void
closeOnCompletion()
(package private) void
closeX()
An untraced version ofclose
.void
completeExecute(Sqlca sqlca)
void
completeExecuteCall(Sqlca sqlca, Cursor singletonParams)
void
completeExecuteCall(Sqlca sqlca, Cursor singletonParams, ClientResultSet[] resultSets)
void
completeExecuteCallOpenQuery(Sqlca sqlca, ClientResultSet resultSet, ColumnMetaData resultSetMetaData, Section generatedSection)
void
completeExecuteImmediate(Sqlca sqlca)
void
completeExecuteSetStatement(Sqlca sqlca)
void
completeLocalCommit(java.util.Iterator listenerIterator)
void
completeLocalRollback(java.util.Iterator listenerIterator)
void
completeOpenQuery(Sqlca sqlca, ClientResultSet resultSet)
void
completePrepare(Sqlca sqlca)
void
completePrepareDescribeOutput(ColumnMetaData resultSetMetaData, Sqlca sqlca)
int
completeSqlca(Sqlca sqlca)
(package private) java.lang.String
escape(java.lang.String sql)
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()
private long[]
executeBatchX()
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)
private ClientResultSet
executeQueryX(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)
private long
executeUpdateX(java.lang.String sql)
(package private) boolean
executeX(java.lang.String sql)
(package private) java.lang.String[]
extractCursorNameFromWhereCurrentOf(java.lang.String sql)
protected void
finalize()
private void
flowClose()
private void
flowCloseOutsideUOW()
private void
flowCloseRetrievedResultSets()
private void
flowCloseRetrievedResultSetsOutsideUOW()
private void
flowExecute(int executeType, java.lang.String sql)
private void
flowExecuteBatch(long[] updateCounts)
java.sql.Connection
getConnection()
ConnectionCallbackInterface
getConnectionCallbackInterface()
int
getFetchDirection()
int
getFetchSize()
java.sql.ResultSet
getGeneratedKeys()
ColumnMetaData
getGuessedResultSetMetaData()
protected java.lang.String
getJdbcStatementInterfaceName()
Returns the name of the java.sql interface implemented by this class.long
getLargeMaxRows()
long
getLargeUpdateCount()
MaterialStatement
getMaterialStatement()
int
getMaxFieldSize()
int
getMaxRows()
boolean
getMoreResults()
boolean
getMoreResults(int current)
private boolean
getMoreResultsX(int current)
(package private) java.sql.Statement
getOwner()
Returns the owner of this statement, if any.int
getQueryTimeout()
java.sql.ResultSet
getResultSet()
int
getResultSetConcurrency()
int
getResultSetHoldability()
int
getResultSetType()
Section
getSection()
Provides public access for section_.protected SqlWarning
getSqlWarnings()
private java.lang.String
getStatementToken(java.lang.String sql)
Step past any initial non-significant characters and comments to find first significant SQL token so we can classify statement.int
getUpdateCount()
java.sql.SQLWarning
getWarnings()
protected void
initResetPreparedStatement()
private void
initResetStatement()
private void
initStatement()
private void
initStatement(int type, int concurrency, int holdability, int autoGeneratedKeys, java.lang.String[] columnNames, int[] columnIndexes)
private void
initStatement(Agent agent, ClientConnection connection)
boolean
isClosed()
Tell whether the statement has been closed or not.boolean
isCloseOnCompletion()
private java.lang.String
isolateAnyInitialIdentifier(java.lang.String sql)
Minion of getStatementToken.private boolean
isOpen(ClientResultSet rs)
boolean
isPoolable()
Returns the value of the poolable hint, indicating whether pooling is requested.boolean
isQueryMode()
boolean
isWrapperFor(java.lang.Class<?> iface)
Returns false unlessiface
is implementedvoid
listenToUnitOfWork()
private void
mapCursorNameToResultSet()
private void
markAutoCommitted()
Mark all ResultSets associated with this statement as auto-committed.(package private) void
markClosed()
This method cleans up client-side resources held by this Statement.(package private) void
markClosed(boolean removeListener)
This method cleans up client-side resources held by this Statement.private void
markPrepared()
private void
markPreparedStatementForAutoGeneratedKeysClosed()
(package private) void
markResultSetsClosed(boolean removeListener)
Mark all ResultSets associated with this statement as closed.(package private) void
parseSqlAndSetSqlModes(java.lang.String sql)
(package private) void
parseStorProcReturnedScrollableRowset()
private void
parseUpdateSql(java.lang.String firstToken)
protected static ClientPreparedStatement
prepareAutoGeneratedKeysStatement(ClientConnection cc)
(package private) void
readClose(boolean allowAutoCommits)
(package private) void
readCloseResultSets(boolean allowAutoCommits)
private void
readCloseResultSets(int number, boolean allowAutoCommits)
(package private) void
readExecuteCall()
private void
readExecuteImmediate()
private void
readExecuteImmediateForBatch(java.lang.String sql)
(package private) void
readOpenQuery()
(package private) void
readPrepare()
(package private) void
readPrepareDescribeOutput()
(package private) void
readSetSpecialRegister()
protected void
removeClientCursorNameFromCache()
void
reset(boolean fullReset)
(package private) void
resetCursorNameAndRemoveFromWhereCurrentOfMappings()
(package private) void
resetForReuse()
Resets the statement for reuse in a statement pool.(package private) void
resetResultSetList()
private void
resetStatement()
(package private) void
resetStatement(Agent agent, ClientConnection connection)
void
resetStatement(Agent agent, ClientConnection connection, int type, int concurrency, int holdability, int autoGeneratedKeys, java.lang.String[] columnNames, int[] columnIndexes)
private void
resetUserControllableAttributes()
Resets attributes that can be modified by the user through theStatement
interface to default values.(package private) void
resultSetCommitting(ClientResultSet closingRS)
Convenience method for resultSetCommitting(ClientResultSet, boolean)(package private) boolean
resultSetCommitting(ClientResultSet closingRS, boolean writeChain)
Method that checks to see if any other ResultSets are open.void
setCursorName(java.lang.String name)
void
setEscapeProcessing(boolean enable)
void
setFetchDirection(int direction)
static void
setFetchedRowBase(long newBase)
Debug method used to test the setLargeMaxRows() method added by JDBC 4.2.void
setFetchSize(int rows)
void
setLargeMaxRows(long maxRows)
void
setMaterialStatement(MaterialStatement materialStatement)
void
setMaxFieldSize(int max)
void
setMaxRows(int maxRows)
protected void
setOwner(java.sql.Statement owner)
Designates the owner of this statement, typically a logical statement.void
setPoolable(boolean poolable)
Requests that a Statement be pooled or not.void
setQueryTimeout(int seconds)
protected void
setSection(Section s)
Assigns a new value (even null) to section_.protected void
setupCursorNameCacheAndMappings()
void
setUpdateCount(long updateCount)
protected java.lang.String
substituteClientCursorNameWithServerCursorName(java.lang.String sql, Section section)
<T> T
unwrap(java.lang.Class<T> iface)
Returnsthis
if this class implements the specified interface.private boolean
willTickleServer(int number, boolean allowAutoCommits)
(package private) void
writeClose(boolean allowAutoCommits)
(package private) boolean
writeCloseResultSets(boolean allowAutoCommits)
The connection close processing passes allowAutoCommits=false because if we drove an auto-commits after each statement close, then when we issue close requests on non-held cursors the server would complain that the non-held cursor was already closed from the previous statement's auto-commit.private boolean
writeCloseResultSets(int number, boolean allowAutoCommits)
(package private) void
writeExecuteCall(boolean outputExpected, java.lang.String procedureName, Section section, int fetchSize, boolean suppressResultSets, int resultSetType, ColumnMetaData parameterMetaData, java.lang.Object[] inputs)
private Section
writeExecuteCall(java.lang.String sql, boolean isBatch)
private void
writeExecuteImmediate(java.lang.String sql, Section section)
(package private) void
writeOpenQuery(Section section, int fetchSize, int resultSetType)
(package private) void
writePrepare(java.lang.String sql, Section section)
(package private) void
writePrepareDescribeOutput(java.lang.String sql, Section section)
(package private) void
writeSetSpecialRegister(java.util.ArrayList sqlsttList)
-
-
-
Field Detail
-
fetchedRowBase
private static long fetchedRowBase
For use in debugging setLargeMaxRows() method added by JDBC 4.2
-
materialStatement_
private MaterialStatement materialStatement_
-
connection_
ClientConnection connection_
-
section_
private Section section_
-
agent_
Agent agent_
-
owner
private java.sql.Statement owner
The owner of this statement, if any.
-
resultSet_
ClientResultSet resultSet_
-
updateCount_
long updateCount_
-
executeQueryMethod__
static final int executeQueryMethod__
- See Also:
- Constant Field Values
-
executeUpdateMethod__
static final int executeUpdateMethod__
- See Also:
- Constant Field Values
-
executeMethod__
static final int executeMethod__
- See Also:
- Constant Field Values
-
sqlMode_
protected int sqlMode_
-
isQuery__
static final int isQuery__
- See Also:
- Constant Field Values
-
isCall__
static final int isCall__
- See Also:
- Constant Field Values
-
isUpdate__
static final int isUpdate__
- See Also:
- Constant Field Values
-
sqlUpdateMode_
int sqlUpdateMode_
-
isInsertSql__
static final int isInsertSql__
- See Also:
- Constant Field Values
-
isDeleteSql__
static final int isDeleteSql__
- See Also:
- Constant Field Values
-
isUpdateSql__
static final int isUpdateSql__
- See Also:
- Constant Field Values
-
resultSetMetaData_
ColumnMetaData resultSetMetaData_
-
cachedCursor_
public Cursor cachedCursor_
-
cachedSingletonRowData_
public Cursor cachedSingletonRowData_
-
isPreparedStatement_
boolean isPreparedStatement_
-
cursorName_
java.lang.String cursorName_
-
openOnClient_
boolean openOnClient_
-
indexOfCurrentResultSet_
private int indexOfCurrentResultSet_
-
resultSetList_
ClientResultSet[] resultSetList_
-
TIMEOUT_STATEMENT
protected static final java.lang.String TIMEOUT_STATEMENT
- See Also:
- Constant Field Values
-
timeoutArrayList
protected java.util.ArrayList<java.lang.String> timeoutArrayList
-
doWriteTimeout
protected boolean doWriteTimeout
-
timeout_
int timeout_
-
maxRows_
long maxRows_
-
maxFieldSize_
int maxFieldSize_
-
isAutoCommittableStatement_
boolean isAutoCommittableStatement_
-
isCatalogQuery_
boolean isCatalogQuery_
-
batch_
final java.util.ArrayList<java.lang.Object> batch_
-
resultSetType_
public int resultSetType_
-
resultSetConcurrency_
public int resultSetConcurrency_
-
resultSetHoldability_
int resultSetHoldability_
-
fetchSize_
int fetchSize_
-
fetchDirection_
int fetchDirection_
-
singletonRowData_
Cursor singletonRowData_
-
cursorAttributesToSendOnPrepare_
public java.lang.String cursorAttributesToSendOnPrepare_
-
preparedStatementForAutoGeneratedKeys_
ClientPreparedStatement preparedStatementForAutoGeneratedKeys_
-
generatedKeysResultSet_
ClientResultSet generatedKeysResultSet_
-
generatedKeysColumnNames_
java.lang.String[] generatedKeysColumnNames_
-
generatedKeysColumnIndexes_
int[] generatedKeysColumnIndexes_
-
autoGeneratedKeys_
int autoGeneratedKeys_
-
warnings_
private SqlWarning warnings_
-
isPoolable
protected boolean isPoolable
-
closeOnCompletion_
private boolean closeOnCompletion_
-
closingResultSets_
private boolean closingResultSets_
-
setSpecialRegisterSection_
private Section setSpecialRegisterSection_
This variable keeps track of a Section dediacted to writeSpecialRegister. It gets initialized the first time a Section is needed, and freed when the Statement is closed.
-
OUTSIDE
private static final int OUTSIDE
State constants used by the FSM inside getStatementToken.
-
INSIDE_SIMPLECOMMENT
private static final int INSIDE_SIMPLECOMMENT
- See Also:
- Constant Field Values
-
INSIDE_BRACKETED_COMMENT
private static final int INSIDE_BRACKETED_COMMENT
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ClientStatement
private ClientStatement()
-
ClientStatement
public ClientStatement(Agent agent, ClientConnection connection) throws SqlException
- Throws:
SqlException
-
ClientStatement
public ClientStatement(Agent agent, ClientConnection connection, int type, int concurrency, int holdability, int autoGeneratedKeys, java.lang.String[] columnNames, int[] columnIndexes) throws SqlException
- Throws:
SqlException
-
-
Method Detail
-
setFetchedRowBase
public static void setFetchedRowBase(long newBase)
Debug method used to test the setLargeMaxRows() method added by JDBC 4.2. This method is a NOP on a production (insane) build of Derby.
-
getMaterialStatement
public MaterialStatement getMaterialStatement()
- Returns:
- the materialStatement
-
setMaterialStatement
public void setMaterialStatement(MaterialStatement materialStatement)
- Parameters:
materialStatement
- the materialStatement to set
-
resetStatement
private void resetStatement()
-
initStatement
private void initStatement()
-
initResetStatement
private void initResetStatement()
-
initResetPreparedStatement
protected void initResetPreparedStatement()
-
resetUserControllableAttributes
private void resetUserControllableAttributes()
Resets attributes that can be modified by the user through theStatement
interface to default values.
-
reset
public void reset(boolean fullReset) throws SqlException
- Throws:
SqlException
-
resetForReuse
void resetForReuse() throws SqlException
Resets the statement for reuse in a statement pool.Intended to be used only by prepared or callable statements, as
Statement
objects aren't pooled.The following actions are taken:
- Batches are cleared.
- Warnings are cleared.
- Open result set are closed on the client and the server.
- Cached cursor names are cleared.
- Statement for fetching auto-generated keys is closed.
- Special registers are reset.
- User controllable attributes are reset to defaults, for instance query timeout and max rows to fetch.
- Throws:
SqlException
- if resetting the statement fails
-
resetStatement
void resetStatement(Agent agent, ClientConnection connection) throws SqlException
- Throws:
SqlException
-
initStatement
private void initStatement(Agent agent, ClientConnection connection)
-
resetStatement
public void resetStatement(Agent agent, ClientConnection connection, int type, int concurrency, int holdability, int autoGeneratedKeys, java.lang.String[] columnNames, int[] columnIndexes) throws SqlException
- Throws:
SqlException
-
initStatement
private void initStatement(int type, int concurrency, int holdability, int autoGeneratedKeys, java.lang.String[] columnNames, int[] columnIndexes) throws SqlException
- Throws:
SqlException
-
finalize
protected void finalize() throws java.lang.Throwable
- Overrides:
finalize
in classjava.lang.Object
- Throws:
java.lang.Throwable
-
getSqlWarnings
protected SqlWarning getSqlWarnings()
-
executeQuery
public java.sql.ResultSet executeQuery(java.lang.String sql) throws java.sql.SQLException
- Specified by:
executeQuery
in interfacejava.sql.Statement
- Throws:
java.sql.SQLException
-
executeQueryX
private ClientResultSet executeQueryX(java.lang.String sql) throws SqlException
- Throws:
SqlException
-
executeUpdate
public int executeUpdate(java.lang.String sql) throws java.sql.SQLException
- Specified by:
executeUpdate
in interfacejava.sql.Statement
- Throws:
java.sql.SQLException
-
executeLargeUpdate
public long executeLargeUpdate(java.lang.String sql) throws java.sql.SQLException
- Specified by:
executeLargeUpdate
in interfacejava.sql.Statement
- Throws:
java.sql.SQLException
-
executeUpdateX
private long executeUpdateX(java.lang.String sql) throws SqlException
- Throws:
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 boolean isClosed() throws java.sql.SQLException
Tell whether the statement has been closed or not.- Specified by:
isClosed
in interfacejava.sql.Statement
- Returns:
true
if closed,false
otherwise.- Throws:
java.sql.SQLException
- if a database access error occurs (according to spec). Never thrown by this implementation.
-
close
public void close() throws java.sql.SQLException
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.sql.Statement
- Throws:
java.sql.SQLException
-
closeX
void closeX() throws SqlException
An untraced version ofclose
. This method cleans up client-side resources and also sends commands to network server to perform clean up. This should not be called in the finalizer. Difference betweenfinalize
andclose
is that close method does these things additionally (Changes done as part of DERBY-210): 1) Sends commands to the server to close the result sets. 2) Sends commands to the server to close the result sets of the generated keys query. 3) Sends a commit if autocommit is on and it is appropriate. 4) Explicitly removes the statement from connection_.openStatements_ and CommitAndRollbackListeners_ by passing true to markClosed. We may need to do 1) in finalizer too. This is being tracked in DERBY-1021- Throws:
SqlException
-
isPoolable
public boolean isPoolable() throws java.sql.SQLException
Returns the value of the poolable hint, indicating whether pooling is requested.- Specified by:
isPoolable
in interfacejava.sql.Statement
- Returns:
- The value of the poolable hint.
- Throws:
java.sql.SQLException
- if the Statement has been closed.
-
setPoolable
public void setPoolable(boolean poolable) throws java.sql.SQLException
Requests that a Statement be pooled or not.- Specified by:
setPoolable
in interfacejava.sql.Statement
- Parameters:
poolable
- requests that the Statement be pooled if true and not be pooled if false.- Throws:
java.sql.SQLException
- if the Statement has been closed.
-
getMaxFieldSize
public int getMaxFieldSize() throws java.sql.SQLException
- Specified by:
getMaxFieldSize
in interfacejava.sql.Statement
- Throws:
java.sql.SQLException
-
setMaxFieldSize
public void setMaxFieldSize(int max) throws java.sql.SQLException
- Specified by:
setMaxFieldSize
in interfacejava.sql.Statement
- Throws:
java.sql.SQLException
-
getMaxRows
public int getMaxRows() throws java.sql.SQLException
- Specified by:
getMaxRows
in interfacejava.sql.Statement
- Throws:
java.sql.SQLException
-
getLargeMaxRows
public long getLargeMaxRows() throws java.sql.SQLException
- Specified by:
getLargeMaxRows
in interfacejava.sql.Statement
- Throws:
java.sql.SQLException
-
setMaxRows
public void setMaxRows(int maxRows) throws java.sql.SQLException
- Specified by:
setMaxRows
in interfacejava.sql.Statement
- Throws:
java.sql.SQLException
-
setLargeMaxRows
public void setLargeMaxRows(long maxRows) throws java.sql.SQLException
- Specified by:
setLargeMaxRows
in interfacejava.sql.Statement
- Throws:
java.sql.SQLException
-
setEscapeProcessing
public void setEscapeProcessing(boolean enable) throws java.sql.SQLException
- Specified by:
setEscapeProcessing
in interfacejava.sql.Statement
- Throws:
java.sql.SQLException
-
getQueryTimeout
public int getQueryTimeout() throws java.sql.SQLException
- Specified by:
getQueryTimeout
in interfacejava.sql.Statement
- Throws:
java.sql.SQLException
-
setQueryTimeout
public void setQueryTimeout(int seconds) throws java.sql.SQLException
- Specified by:
setQueryTimeout
in interfacejava.sql.Statement
- Throws:
java.sql.SQLException
-
cancel
public void cancel() throws java.sql.SQLException
- Specified by:
cancel
in interfacejava.sql.Statement
- Throws:
java.sql.SQLException
-
getWarnings
public java.sql.SQLWarning getWarnings() throws java.sql.SQLException
- Specified by:
getWarnings
in interfacejava.sql.Statement
- Throws:
java.sql.SQLException
-
clearWarnings
public void clearWarnings() throws java.sql.SQLException
- Specified by:
clearWarnings
in interfacejava.sql.Statement
- Throws:
java.sql.SQLException
-
clearWarningsX
final void clearWarningsX()
-
setCursorName
public void setCursorName(java.lang.String name) throws java.sql.SQLException
- Specified by:
setCursorName
in interfacejava.sql.Statement
- Throws:
java.sql.SQLException
-
execute
public boolean execute(java.lang.String sql) throws java.sql.SQLException
- Specified by:
execute
in interfacejava.sql.Statement
- Throws:
java.sql.SQLException
-
executeX
boolean executeX(java.lang.String sql) throws SqlException
- Throws:
SqlException
-
getResultSet
public java.sql.ResultSet getResultSet() throws java.sql.SQLException
- Specified by:
getResultSet
in interfacejava.sql.Statement
- Throws:
java.sql.SQLException
-
getUpdateCount
public int getUpdateCount() throws java.sql.SQLException
- Specified by:
getUpdateCount
in interfacejava.sql.Statement
- Throws:
java.sql.SQLException
-
getLargeUpdateCount
public long getLargeUpdateCount() throws java.sql.SQLException
- Specified by:
getLargeUpdateCount
in interfacejava.sql.Statement
- Throws:
java.sql.SQLException
-
getMoreResults
public boolean getMoreResults() throws java.sql.SQLException
- Specified by:
getMoreResults
in interfacejava.sql.Statement
- Throws:
java.sql.SQLException
-
setFetchDirection
public void setFetchDirection(int direction) throws java.sql.SQLException
- Specified by:
setFetchDirection
in interfacejava.sql.Statement
- Throws:
java.sql.SQLException
-
getFetchDirection
public int getFetchDirection() throws java.sql.SQLException
- Specified by:
getFetchDirection
in interfacejava.sql.Statement
- Throws:
java.sql.SQLException
-
setFetchSize
public void setFetchSize(int rows) throws java.sql.SQLException
- Specified by:
setFetchSize
in interfacejava.sql.Statement
- Throws:
java.sql.SQLException
-
getFetchSize
public int getFetchSize() throws java.sql.SQLException
- Specified by:
getFetchSize
in interfacejava.sql.Statement
- Throws:
java.sql.SQLException
-
getResultSetConcurrency
public int getResultSetConcurrency() throws java.sql.SQLException
- Specified by:
getResultSetConcurrency
in interfacejava.sql.Statement
- Throws:
java.sql.SQLException
-
getResultSetType
public int getResultSetType() throws java.sql.SQLException
- Specified by:
getResultSetType
in interfacejava.sql.Statement
- Throws:
java.sql.SQLException
-
addBatch
public void addBatch(java.lang.String sql) throws java.sql.SQLException
- Specified by:
addBatch
in interfacejava.sql.Statement
- Throws:
java.sql.SQLException
-
clearBatch
public void clearBatch() throws java.sql.SQLException
- Specified by:
clearBatch
in interfacejava.sql.Statement
- Throws:
java.sql.SQLException
-
executeBatch
public int[] executeBatch() throws java.sql.SQLException
- Specified by:
executeBatch
in interfacejava.sql.Statement
- Throws:
java.sql.SQLException
-
executeLargeBatch
public long[] executeLargeBatch() throws java.sql.SQLException
- Specified by:
executeLargeBatch
in interfacejava.sql.Statement
- Throws:
java.sql.SQLException
-
executeBatchX
private long[] executeBatchX() throws SqlException, java.sql.BatchUpdateException
- Throws:
SqlException
java.sql.BatchUpdateException
-
getConnection
public java.sql.Connection getConnection() throws java.sql.SQLException
- Specified by:
getConnection
in interfacejava.sql.Statement
- Throws:
java.sql.SQLException
-
getMoreResults
public boolean getMoreResults(int current) throws java.sql.SQLException
- Specified by:
getMoreResults
in interfacejava.sql.Statement
- Throws:
java.sql.SQLException
-
getMoreResultsX
private boolean getMoreResultsX(int current) throws SqlException
- Throws:
SqlException
-
getGeneratedKeys
public java.sql.ResultSet getGeneratedKeys() throws java.sql.SQLException
- Specified by:
getGeneratedKeys
in interfacejava.sql.Statement
- Throws:
java.sql.SQLException
-
executeUpdate
public int executeUpdate(java.lang.String sql, int autoGeneratedKeys) throws java.sql.SQLException
- Specified by:
executeUpdate
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 interfacejava.sql.Statement
- Throws:
java.sql.SQLException
-
executeUpdate
public int executeUpdate(java.lang.String sql, int[] columnIndexes) throws java.sql.SQLException
- Specified by:
executeUpdate
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 interfacejava.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 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 interfacejava.sql.Statement
- Throws:
java.sql.SQLException
-
execute
public 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 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 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
-
getResultSetHoldability
public int getResultSetHoldability() throws java.sql.SQLException
- Specified by:
getResultSetHoldability
in interfacejava.sql.Statement
- Throws:
java.sql.SQLException
-
writeSetSpecialRegister
void writeSetSpecialRegister(java.util.ArrayList sqlsttList) throws SqlException
- Throws:
SqlException
-
readSetSpecialRegister
void readSetSpecialRegister() throws SqlException
- Throws:
SqlException
-
writeExecuteImmediate
private void writeExecuteImmediate(java.lang.String sql, Section section) throws SqlException
- Throws:
SqlException
-
readExecuteImmediate
private void readExecuteImmediate() throws SqlException
- Throws:
SqlException
-
completeExecuteImmediate
public void completeExecuteImmediate(Sqlca sqlca)
- Specified by:
completeExecuteImmediate
in interfaceStatementCallbackInterface
-
readExecuteImmediateForBatch
private void readExecuteImmediateForBatch(java.lang.String sql) throws SqlException
- Throws:
SqlException
-
writePrepareDescribeOutput
void writePrepareDescribeOutput(java.lang.String sql, Section section) throws SqlException
- Throws:
SqlException
-
readPrepareDescribeOutput
void readPrepareDescribeOutput() throws SqlException
- Throws:
SqlException
-
completePrepareDescribeOutput
public void completePrepareDescribeOutput(ColumnMetaData resultSetMetaData, Sqlca sqlca)
- Specified by:
completePrepareDescribeOutput
in interfaceStatementCallbackInterface
-
writePrepare
void writePrepare(java.lang.String sql, Section section) throws SqlException
- Throws:
SqlException
-
readPrepare
void readPrepare() throws SqlException
- Throws:
SqlException
-
completePrepare
public void completePrepare(Sqlca sqlca)
- Specified by:
completePrepare
in interfaceStatementCallbackInterface
-
writeOpenQuery
void writeOpenQuery(Section section, int fetchSize, int resultSetType) throws SqlException
- Throws:
SqlException
-
readOpenQuery
void readOpenQuery() throws SqlException
- Throws:
SqlException
-
completeOpenQuery
public void completeOpenQuery(Sqlca sqlca, ClientResultSet resultSet)
- Specified by:
completeOpenQuery
in interfaceStatementCallbackInterface
-
completeExecuteCallOpenQuery
public void completeExecuteCallOpenQuery(Sqlca sqlca, ClientResultSet resultSet, ColumnMetaData resultSetMetaData, Section generatedSection)
- Specified by:
completeExecuteCallOpenQuery
in interfaceStatementCallbackInterface
-
writeExecuteCall
void writeExecuteCall(boolean outputExpected, java.lang.String procedureName, Section section, int fetchSize, boolean suppressResultSets, int resultSetType, ColumnMetaData parameterMetaData, java.lang.Object[] inputs) throws SqlException
- Throws:
SqlException
-
readExecuteCall
void readExecuteCall() throws SqlException
- Throws:
SqlException
-
completeExecuteCall
public void completeExecuteCall(Sqlca sqlca, Cursor singletonParams, ClientResultSet[] resultSets)
- Specified by:
completeExecuteCall
in interfaceStatementCallbackInterface
-
completeExecuteCall
public void completeExecuteCall(Sqlca sqlca, Cursor singletonParams)
- Specified by:
completeExecuteCall
in interfaceStatementCallbackInterface
-
completeExecute
public void completeExecute(Sqlca sqlca)
- Specified by:
completeExecute
in interfaceStatementCallbackInterface
-
setUpdateCount
public void setUpdateCount(long updateCount)
-
setOwner
protected final void setOwner(java.sql.Statement owner)
Designates the owner of this statement, typically a logical statement.- Parameters:
owner
- the owning statement, if any
-
getOwner
final java.sql.Statement getOwner()
Returns the owner of this statement, if any.- Returns:
- The designated owner of this statement, or
null
if none.
-
willTickleServer
private boolean willTickleServer(int number, boolean allowAutoCommits) throws SqlException
- Throws:
SqlException
-
flowClose
private void flowClose() throws SqlException
- Throws:
SqlException
-
flowCloseOutsideUOW
private void flowCloseOutsideUOW() throws SqlException
- Throws:
SqlException
-
writeClose
final void writeClose(boolean allowAutoCommits) throws SqlException
- Throws:
SqlException
-
readClose
final void readClose(boolean allowAutoCommits) throws SqlException
- Throws:
SqlException
-
writeCloseResultSets
final boolean writeCloseResultSets(boolean allowAutoCommits) throws SqlException
The connection close processing passes allowAutoCommits=false because if we drove an auto-commits after each statement close, then when we issue close requests on non-held cursors the server would complain that the non-held cursor was already closed from the previous statement's auto-commit. So the solution is to never auto-commit statements during connection close processing. Here's the operative explanation: Given a sequence of open statements S1, S2, .... a logic problem is occurring after S1 close-query drives an auto-commit, and S2 close-query is driven against a non-held cursor. The first auto-commit driven by S1 triggers a callback that closes S2's non-held cursor, and so the subsequent S2 close-query request generates an error from the server saying that the cursor is already closed. This is fixed by passing a flag to our statement close processing that prevents driving additional auto-commits after each statement close. Connection close drives its own final auto-commit.- Parameters:
allowAutoCommits
-- Throws:
SqlException
-
writeCloseResultSets
private boolean writeCloseResultSets(int number, boolean allowAutoCommits) throws SqlException
- Throws:
SqlException
-
readCloseResultSets
final void readCloseResultSets(boolean allowAutoCommits) throws SqlException
- Throws:
SqlException
-
readCloseResultSets
private void readCloseResultSets(int number, boolean allowAutoCommits) throws SqlException
- Throws:
SqlException
-
flowCloseRetrievedResultSets
private void flowCloseRetrievedResultSets() throws SqlException
- Throws:
SqlException
-
flowCloseRetrievedResultSetsOutsideUOW
private void flowCloseRetrievedResultSetsOutsideUOW() throws SqlException
- Throws:
SqlException
-
completeSqlca
public int completeSqlca(Sqlca sqlca)
- Specified by:
completeSqlca
in interfaceStatementCallbackInterface
-
completeExecuteSetStatement
public void completeExecuteSetStatement(Sqlca sqlca)
- Specified by:
completeExecuteSetStatement
in interfaceStatementCallbackInterface
-
markClosed
void markClosed()
This method cleans up client-side resources held by this Statement. The Statement will not be removed from the open statements list and PreparedStatement will also not be removed from the commit and rollback listeners list inorg.apache.derby.client.am.Connection
. This method is called from: 1. finalize() - For the finalizer to be called, the Statement should not have any references and so it should have been already removed from the lists. 2.org.apache.derby.client.am.Connection#markStatementsClosed
This method explicitly removes the Statement from open statements list. 3. To close positioned update statements - These statements are not added to the list of open statements.
-
markClosed
void markClosed(boolean removeListener)
This method cleans up client-side resources held by this Statement. If removeListener is true, the Statement is removed from open statements list and PreparedStatement is also removed from commit and rollback listeners list. This is called from the close methods.- Parameters:
removeListener
- if true the Statement will be removed from the open statements list and PreparedStatement will also be removed from commit and rollback listeners list inorg.apache.derby.client.am.Connection
.
-
closeEverythingExceptResultSets
private void closeEverythingExceptResultSets(boolean removeListener)
Close all resources except for ResultSets. This code was factored out of markClosed() so that closeMeOnCompletion() could close the Statement without having to re-close the already closed ResultSets.
-
markPreparedStatementForAutoGeneratedKeysClosed
private void markPreparedStatementForAutoGeneratedKeysClosed()
-
markResultSetsClosed
final void markResultSetsClosed(boolean removeListener)
Mark all ResultSets associated with this statement as closed.- Parameters:
removeListener
- if true the ResultSets will be removed from the commit and rollback listeners list inorg.apache.derby.client.am.Connection
.
-
flowExecute
private void flowExecute(int executeType, java.lang.String sql) throws SqlException
- Throws:
SqlException
-
flowExecuteBatch
private void flowExecuteBatch(long[] updateCounts) throws SqlException, java.sql.BatchUpdateException
- Throws:
SqlException
java.sql.BatchUpdateException
-
writeExecuteCall
private Section writeExecuteCall(java.lang.String sql, boolean isBatch) throws SqlException
- Throws:
SqlException
-
listenToUnitOfWork
public void listenToUnitOfWork()
- Specified by:
listenToUnitOfWork
in interfaceUnitOfWorkListener
-
completeLocalCommit
public void completeLocalCommit(java.util.Iterator listenerIterator)
- Specified by:
completeLocalCommit
in interfaceUnitOfWorkListener
-
completeLocalRollback
public void completeLocalRollback(java.util.Iterator listenerIterator)
- Specified by:
completeLocalRollback
in interfaceUnitOfWorkListener
-
accumulateWarning
public void accumulateWarning(SqlWarning e)
- Specified by:
accumulateWarning
in interfaceStatementCallbackInterface
-
markPrepared
private void markPrepared()
-
getJdbcStatementInterfaceName
protected java.lang.String getJdbcStatementInterfaceName()
Returns the name of the java.sql interface implemented by this class.- Returns:
- name of java.sql interface
-
parseSqlAndSetSqlModes
void parseSqlAndSetSqlModes(java.lang.String sql) throws SqlException
- Throws:
SqlException
-
isolateAnyInitialIdentifier
private java.lang.String isolateAnyInitialIdentifier(java.lang.String sql)
Minion of getStatementToken. If the input string starts with an identifier consisting of letters only (like "select", "update"..),return it, else return supplied string.- Parameters:
sql
- input string- Returns:
- identifier or unmodified string
- See Also:
getStatementToken(java.lang.String)
-
getStatementToken
private java.lang.String getStatementToken(java.lang.String sql) throws SqlException
Step past any initial non-significant characters and comments to find first significant SQL token so we can classify statement.- Returns:
- first significant SQL token
- Throws:
SqlException
- std exception policy
-
parseUpdateSql
private void parseUpdateSql(java.lang.String firstToken)
-
checkForAppropriateSqlMode
final void checkForAppropriateSqlMode(int executeType, int sqlMode) throws SqlException
- Throws:
SqlException
-
checkResultSetCount
private void checkResultSetCount(int executeType) throws SqlException
Checks that the number of result sets returned by the statement is consistent with the executed type.executeQuery()
should return exactly one result set andexecuteUpdate()
none. Raises an exception if the result set count does not match the execute type.- Parameters:
executeType
- one ofexecuteQueryMethod__
,executeUpdateMethod__
andexecuteMethod__
- Throws:
SqlException
- if the number of result sets does not match the execute type
-
checkForStoredProcResultSetCount
protected final void checkForStoredProcResultSetCount(int executeType) throws SqlException
Checks that a stored procedure returns the correct number of result sets given its execute type. If the number is incorrect, make sure the transaction is rolled back when auto commit is enabled.- Parameters:
executeType
- one ofexecuteQueryMethod__
,executeUpdateMethod__
andexecuteMethod__
- Throws:
SqlException
- if the number of result sets does not match the execute type- See Also:
checkResultSetCount(int)
-
checkForClosedStatement
final void checkForClosedStatement() throws SqlException
- Throws:
SqlException
-
checkForInvalidBatchedSql
private void checkForInvalidBatchedSql(java.lang.String sql) throws SqlException
- Throws:
SqlException
-
checkForDuplicateCursorName
protected void checkForDuplicateCursorName() throws SqlException
- Throws:
SqlException
-
setupCursorNameCacheAndMappings
protected void setupCursorNameCacheAndMappings()
-
extractCursorNameFromWhereCurrentOf
java.lang.String[] extractCursorNameFromWhereCurrentOf(java.lang.String sql)
-
substituteClientCursorNameWithServerCursorName
protected java.lang.String substituteClientCursorNameWithServerCursorName(java.lang.String sql, Section section) throws SqlException
- Throws:
SqlException
-
getConnectionCallbackInterface
public ConnectionCallbackInterface getConnectionCallbackInterface()
- Specified by:
getConnectionCallbackInterface
in interfaceStatementCallbackInterface
-
resetCursorNameAndRemoveFromWhereCurrentOfMappings
void resetCursorNameAndRemoveFromWhereCurrentOfMappings()
-
mapCursorNameToResultSet
private void mapCursorNameToResultSet()
-
parseStorProcReturnedScrollableRowset
void parseStorProcReturnedScrollableRowset() throws SqlException
- Throws:
SqlException
-
escape
java.lang.String escape(java.lang.String sql) throws SqlException
- Throws:
SqlException
-
cacheCursorAttributesToSendOnPrepare
java.lang.String cacheCursorAttributesToSendOnPrepare() throws SqlException
- Throws:
SqlException
-
prepareAutoGeneratedKeysStatement
protected static ClientPreparedStatement prepareAutoGeneratedKeysStatement(ClientConnection cc) throws SqlException
- Throws:
SqlException
-
checkAutoGeneratedKeysParameters
void checkAutoGeneratedKeysParameters() throws SqlException
- Throws:
SqlException
-
getGuessedResultSetMetaData
public ColumnMetaData getGuessedResultSetMetaData()
- Specified by:
getGuessedResultSetMetaData
in interfaceStatementCallbackInterface
-
isQueryMode
public boolean isQueryMode()
-
removeClientCursorNameFromCache
protected void removeClientCursorNameFromCache()
-
resultSetCommitting
void resultSetCommitting(ClientResultSet closingRS) throws SqlException
Convenience method for resultSetCommitting(ClientResultSet, boolean)- Parameters:
closingRS
- The ResultSet to be closed- Throws:
SqlException
- See Also:
resultSetCommitting(ClientResultSet, boolean)
-
resultSetCommitting
boolean resultSetCommitting(ClientResultSet closingRS, boolean writeChain) throws SqlException
Method that checks to see if any other ResultSets are open. If not proceeds with the autocommit.- Parameters:
closingRS
- The ResultSet to be closedwriteChain
- A Boolean indicating whether this method is part of a chain of write from client to Server- Throws:
SqlException
-
markAutoCommitted
private void markAutoCommitted()
Mark all ResultSets associated with this statement as auto-committed.
-
closeOnCompletion
public void closeOnCompletion() throws java.sql.SQLException
- Specified by:
closeOnCompletion
in interfacejava.sql.Statement
- Throws:
java.sql.SQLException
-
isCloseOnCompletion
public boolean isCloseOnCompletion() throws java.sql.SQLException
- Specified by:
isCloseOnCompletion
in interfacejava.sql.Statement
- Throws:
java.sql.SQLException
-
closeMeOnCompletion
void closeMeOnCompletion()
-
isOpen
private boolean isOpen(ClientResultSet rs) throws java.sql.SQLException
- Throws:
java.sql.SQLException
-
resetResultSetList
void resetResultSetList()
-
getSection
public Section getSection()
Provides public access for section_. This is necessary as the section concept is shared between client.am and net. Seems like it really belongs in net as it is tied to the particular protocol used.- Returns:
- section_
-
setSection
protected void setSection(Section s)
Assigns a new value (even null) to section_. The existing section_ (if any) is freed.- Parameters:
s
- the section_ to set.
-
-