public abstract class AbstractFbStatement extends java.lang.Object implements FbStatement
| Modifier and Type | Field and Description |
|---|---|
protected ExceptionListenerDispatcher |
exceptionListenerDispatcher |
protected StatementListenerDispatcher |
statementListenerDispatcher |
| Modifier | Constructor and Description |
|---|---|
protected |
AbstractFbStatement() |
| Modifier and Type | Method and Description |
|---|---|
void |
addExceptionListener(ExceptionListener listener)
Adds an exception listener to this object.
|
void |
addStatementListener(StatementListener statementListener)
Registers a
StatementListener. |
protected void |
checkStatementValid()
Checks if this statement is not in
StatementState.CLOSED, StatementState.CLOSING,
StatementState.NEW or StatementState.ERROR, and throws an SQLException if it is. |
protected void |
checkStatementValid(StatementState ignoreState)
Performs the same check as
checkStatementValid(), but considers ignoreState as valid. |
void |
close()
Close and deallocate this statement.
|
void |
closeCursor()
Closes the cursor associated with this statement, leaving the
statement itself allocated.
|
void |
closeCursor(boolean transactionEnd)
Closes the cursor associated with this statement, leaving the statement itself allocated.
|
protected ExecutionPlanProcessor |
createExecutionPlanProcessor() |
protected SqlCountProcessor |
createSqlCountProcessor() |
void |
ensureClosedCursor(boolean transactionEnd)
Ensures that the statement cursor is closed.
|
void |
fetchScroll(FetchType fetchType,
int fetchSize,
int position)
Requests this statement to fetch rows using the specified fetch type.
|
protected void |
fetchScrollImpl(FetchType fetchType,
int fetchSize,
int position)
Implementation of
fetchScroll(FetchType, int, int). |
protected void |
finalize() |
protected void |
forceState(StatementState newState)
Forces the statement to the specified state without throwing an exception if this is not a valid transition.
|
protected abstract void |
free(int option)
Frees the currently allocated statement.
|
protected long |
getAllowedTimeout() |
byte[] |
getCursorInfo(byte[] requestItems,
int bufferLength)
Request cursor info.
|
<T> T |
getCursorInfo(byte[] requestItems,
int bufferLength,
InfoProcessor<T> infoProcessor)
Request cursor info.
|
protected byte[] |
getCursorInfoImpl(byte[] requestItems,
int bufferLength)
Implementation of
getCursorInfo(byte[], int). |
java.lang.String |
getExecutionPlan() |
java.lang.String |
getExplainedExecutionPlan() |
byte[] |
getParameterDescriptionInfoRequestItems() |
RowDescriptor |
getParameterDescriptor() |
RowDescriptor |
getRowDescriptor() |
SqlCountHolder |
getSqlCounts()
Retrieves the SQL counts for the last execution of this statement.
|
<T> T |
getSqlInfo(byte[] requestItems,
int bufferLength,
InfoProcessor<T> infoProcessor)
Request statement info.
|
StatementState |
getState() |
byte[] |
getStatementInfoRequestItems() |
protected WarningMessageCallback |
getStatementWarningCallback() |
long |
getTimeout()
Gets the current statement timeout for this statement.
|
FbTransaction |
getTransaction() |
protected TransactionListener |
getTransactionListener()
Gets the
TransactionListener instance for this statement. |
StatementType |
getType() |
boolean |
hasFetched()
Has at least one fetch been executed on the current cursor?
|
protected boolean |
hasFields() |
protected boolean |
hasSingletonResult() |
protected boolean |
isAfterLast() |
protected boolean |
isBeforeFirst() |
protected boolean |
isPrepareAllowed(StatementState state)
Is a call to
FbStatement.prepare(String) allowed for the supplied StatementState. |
protected abstract boolean |
isValidTransactionClass(java.lang.Class<? extends FbTransaction> transactionClass)
Method to decide if a transaction implementation class is valid for the statement implementation.
|
protected void |
parseStatementInfo(byte[] statementInfoResponse)
Parse the statement info response in
statementInfoResponse. |
protected void |
queueRowData(RowValue rowData)
Queues row data for consumption
|
void |
removeExceptionListener(ExceptionListener listener)
Removes an exception listener to this object.
|
void |
removeStatementListener(StatementListener statementListener)
Removes a
StatementListener. |
protected void |
reset()
Reset statement state, equivalent to calling
reset(boolean) with false. |
protected void |
reset(boolean resetAll)
Resets the statement for next execution.
|
protected void |
resetAll()
Reset statement state and clear parameter description, equivalent to calling
reset(boolean) with
true. |
protected void |
setAfterLast()
Marks the cursor position as after-last.
|
protected void |
setBeforeFirst()
Marks the cursor position as before-first.
|
protected void |
setParameterDescriptor(RowDescriptor parameterDescriptor)
Sets the parameter descriptor.
|
protected void |
setRowDescriptor(RowDescriptor rowDescriptor)
Sets the (result set) row descriptor.
|
void |
setTimeout(long statementTimeout)
Sets the statement timeout.
|
void |
setTransaction(FbTransaction newTransaction)
Associates a transaction with this statement
|
protected void |
setType(StatementType type)
Sets the StatementType
|
protected OperationCloseHandle |
signalExecute()
Signals the start of an execute for this statement.
|
protected OperationCloseHandle |
signalFetch()
Signals the start of a fetch for this statement.
|
protected void |
switchState(StatementState newState)
Sets the StatementState.
|
void |
unprepare()
Attempts to unprepare the currently prepared statement.
|
void |
validateParameters(RowValue parameters)
Validates if the number of parameters matches the expected number and types, and if all values have been set.
|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitbatchCancel, batchExecute, clearCursorFlag, createBatchParameterBuffer, deferredBatchCreate, deferredBatchRelease, deferredBatchSend, emptyRowDescriptor, execute, fetchRows, getDatabase, getDefaultSqlInfoSize, getHandle, getMaxSqlInfoSize, getSqlInfo, isCursorFlagSet, prepare, setCursorFlag, setCursorName, supportBatchUpdates, supportsCursorInfo, supportsFetchScroll, withLockprotected final StatementListenerDispatcher statementListenerDispatcher
protected final ExceptionListenerDispatcher exceptionListenerDispatcher
protected final TransactionListener getTransactionListener()
TransactionListener instance for this statement.
This method should only be called by this object itself. Subclasses may provide their own transaction listener,
but the instance returned by this method should be the same for the lifetime of this FbStatement.
protected final WarningMessageCallback getStatementWarningCallback()
public final boolean hasFetched()
FbStatementhasFetched in interface FbStatementtrue if at least one fetch has been executed on the current cursor, false otherwise
(including if nothing has been executed, or the current statement has no cursor)public void close()
throws java.sql.SQLException
FbStatementclose in interface java.lang.AutoCloseableclose in interface FbStatementjava.sql.SQLExceptionpublic final void closeCursor()
throws java.sql.SQLException
FbStatement
Equivalent to calling FbStatement.closeCursor(boolean) with false.
closeCursor in interface FbStatementjava.sql.SQLExceptionpublic final void closeCursor(boolean transactionEnd)
throws java.sql.SQLException
FbStatement
When this method is called in preparation of a commit, rollback or another operation which will close the cursor
(see transactionEnd), then implementations may opt to not close the cursor on the server as the server
closes the cursor automatically, or the statement as a whole is closed by the implementation.
closeCursor in interface FbStatementtransactionEnd - close is in response to a transaction end or another operation which will close the cursorjava.sql.SQLExceptionpublic final void ensureClosedCursor(boolean transactionEnd)
throws java.sql.SQLException
FbStatementensureClosedCursor in interface FbStatementtransactionEnd - Close is in response to a transaction endjava.sql.SQLException - If this statement is closed or the cursor could not be closed.public void unprepare()
throws java.sql.SQLException
FbStatement
For Firebird versions that do not support DSQL_unprepare, the implementation should attempt to close the
cursor (using FbStatement.closeCursor()).
unprepare in interface FbStatementjava.sql.SQLException - If a database access error occurspublic final StatementState getState()
getState in interface FbStatementprotected final void switchState(StatementState newState) throws java.sql.SQLException
newState - New statejava.sql.SQLException - When the state is changed to an illegal next stateprotected void forceState(StatementState newState)
Does nothing if current state is CLOSED.
newState - New stateswitchState(StatementState)public final StatementType getType()
getType in interface FbStatementprotected void setType(StatementType type)
type - New typeprotected final void queueRowData(RowValue rowData)
rowData - Row dataprotected final void setBeforeFirst()
All registered StatementListener instances are notified for
the StatementListener.beforeFirst(FbStatement) event.
protected final boolean isBeforeFirst()
protected final void setAfterLast()
All registered StatementListener instances are notified for
the StatementListener.afterLast(FbStatement) event.
protected final boolean isAfterLast()
protected final void reset()
reset(boolean) with false.protected final void resetAll()
reset(boolean) with
true.protected void reset(boolean resetAll)
FbStatement.withLock() and call super.reset(resetAll)resetAll - Also reset field and parameter infoprotected boolean isPrepareAllowed(StatementState state)
FbStatement.prepare(String) allowed for the supplied StatementState.state - The statement statetrue call to prepare is allowedpublic final RowDescriptor getParameterDescriptor()
getParameterDescriptor in interface FbStatementprotected void setParameterDescriptor(RowDescriptor parameterDescriptor)
parameterDescriptor - Parameter descriptorpublic final RowDescriptor getRowDescriptor()
getRowDescriptor in interface FbStatementprotected void setRowDescriptor(RowDescriptor rowDescriptor)
rowDescriptor - Row descriptorpublic byte[] getStatementInfoRequestItems()
getParameterDescriptionInfoRequestItems()public byte[] getParameterDescriptionInfoRequestItems()
isc_info_sql_describe_vars info request items.getStatementInfoRequestItems()public final void fetchScroll(FetchType fetchType, int fetchSize, int position) throws java.sql.SQLException
FbStatement
The default implementation only supports FetchType.NEXT by redirecting to FbStatement.fetchRows(int) and
throws an SQLFeatureNotSupported for other types.
The caller is responsible for tracking and correcting for server-side positional state, taking into account any
rows already fetched. For example, if 100 rows have been fetched with NEXT or PRIOR, and 80
rows are still in the local buffer, the server-side position is actually 80 rows ahead (or behind). The next
fetch with RELATIVE will need to correct this in position, and a PRIOR after
a NEXT or a NEXT after a PRIOR will need to reposition with RELATIVE or
ABSOLUTE, or know how many rows to ignore from the fetched batch.
fetchScroll in interface FbStatementfetchType - Fetch typefetchSize - Number of rows to fetch (must be > 0) (ignored by server for types other than
FetchType.NEXT and FetchType.PRIOR)position - Absolute or relative position for the row to fetch (ignored by server for types other than
FetchType.ABSOLUTE and FetchType.RELATIVE)java.sql.SQLFeatureNotSupportedException - For types other than FetchType.NEXT if the protocol version or the implementation does not
support scroll fetchjava.sql.SQLException - For database access errors, when called on a closed statement, when no cursor is open or for server-side
error conditionsFbStatement.supportsFetchScroll()protected void fetchScrollImpl(FetchType fetchType, int fetchSize, int position) throws java.sql.SQLException
fetchScroll(FetchType, int, int).
An implementation should not notify exceptionListenerDispatcher, as that is already handled in
fetchScroll(FetchType, int, int).
The implementation of fetchScroll(FetchType, int, int) redirects FetchType.NEXT to
FbStatement.fetchRows(int). The implementation does need to handle NEXT, but only when actually implementing
the other scroll direction.
java.sql.SQLFeatureNotSupportedException - If the protocol version or the implementation does not support scroll fetch (even for NEXT)java.sql.SQLException - For database access errors, when called on a closed statement, when no cursor is open, or for serverside
error conditionsfetchScroll(FetchType, int, int),
FbStatement.supportsFetchScroll()public final <T> T getSqlInfo(byte[] requestItems,
int bufferLength,
InfoProcessor<T> infoProcessor)
throws java.sql.SQLException
getSqlInfo in interface FbStatementrequestItems - Array of info items to requestbufferLength - Response buffer length to useinfoProcessor - Implementation of InfoProcessor to transform
the info responsejava.sql.SQLException - For errors retrieving or transforming the response.public final <T> T getCursorInfo(byte[] requestItems,
int bufferLength,
InfoProcessor<T> infoProcessor)
throws java.sql.SQLException
FbStatementgetCursorInfo in interface FbStatementrequestItems - Array of info items to requestbufferLength - Response buffer length to useinfoProcessor - Implementation of InfoProcessor to transform
the info responsejava.sql.SQLException - For errors retrieving or transforming the responsejava.sql.SQLFeatureNotSupportedException - If requesting cursor info is not supported (Firebird 4.0 or earlier, or native implementation)FbStatement.supportsCursorInfo()public final byte[] getCursorInfo(byte[] requestItems,
int bufferLength)
throws java.sql.SQLException
FbStatementgetCursorInfo in interface FbStatementrequestItems - Array of info items to requestbufferLength - Response buffer length to usejava.sql.SQLException - For errors retrieving or transforming the responsejava.sql.SQLFeatureNotSupportedException - If requesting cursor info is not supported (Firebird 4.0 or earlier, or native implementation)protected byte[] getCursorInfoImpl(byte[] requestItems,
int bufferLength)
throws java.sql.SQLException
getCursorInfo(byte[], int).
An implementation should not notify exceptionListenerDispatcher, as that is already handled in
getCursorInfo(byte[], int).
java.sql.SQLException - For errors retrieving or transforming the responsejava.sql.SQLFeatureNotSupportedException - If requesting cursor info is not supported (Firebird 4.0 or earlier, or native implementation)getCursorInfo(byte[], int),
FbStatement.supportsCursorInfo()public final java.lang.String getExecutionPlan()
throws java.sql.SQLException
getExecutionPlan in interface FbStatementjava.sql.SQLException - If this statement is closed.public final java.lang.String getExplainedExecutionPlan()
throws java.sql.SQLException
getExplainedExecutionPlan in interface FbStatementjava.sql.SQLException - If this statement is closed.protected ExecutionPlanProcessor createExecutionPlanProcessor()
ExecutionPlanProcessor (or subclass) for this statement.public SqlCountHolder getSqlCounts() throws java.sql.SQLException
FbStatement
The retrieved SQL counts are also notified to all registered StatementListeners.
In general the FbStatement will (should) retrieve and notify listeners of the SQL counts automatically
at times where it is relevant (eg after executing a statement that does not produce multiple rows, or after
fetching all rows).
getSqlCounts in interface FbStatementjava.sql.SQLException - If this statement is closed, or if this statement is in state StatementState.CURSOR_OPEN and not
all rows have been fetched.protected SqlCountProcessor createSqlCountProcessor()
SqlCountProcessor (or subclass) for this statement.protected abstract void free(int option)
throws java.sql.SQLException
ISCConstants.DSQL_close or drop
the statement handle using ISCConstants.DSQL_drop.option - Free optionjava.sql.SQLExceptionpublic final void validateParameters(RowValue parameters) throws java.sql.SQLException
FbStatementvalidateParameters in interface FbStatementparameters - Parameter values to validatejava.sql.SQLException - When the number or type of parameters does not match FbStatement.getParameterDescriptor(), or when a
parameter has not been set.public final void addStatementListener(StatementListener statementListener)
FbStatementStatementListener.addStatementListener in interface FbStatementstatementListener - The row listenerpublic final void removeStatementListener(StatementListener statementListener)
FbStatementStatementListener.removeStatementListener in interface FbStatementstatementListener - The row listenerpublic final void addExceptionListener(ExceptionListener listener)
ExceptionListenable
Implementations use WeakReference.
addExceptionListener in interface ExceptionListenablelistener - Listener to registerpublic final void removeExceptionListener(ExceptionListener listener)
ExceptionListenableremoveExceptionListener in interface ExceptionListenablelistener - Listener to removeprotected final void checkStatementValid()
throws java.sql.SQLException
StatementState.CLOSED, StatementState.CLOSING,
StatementState.NEW or StatementState.ERROR, and throws an SQLException if it is.java.sql.SQLException - When this statement is closed or in error state.protected final void checkStatementValid(StatementState ignoreState) throws java.sql.SQLException
checkStatementValid(), but considers ignoreState as valid.ignoreState - The invalid state (see checkStatementValid() to ignorejava.sql.SQLException - When this statement is closed or in error state.protected void finalize()
throws java.lang.Throwable
finalize in class java.lang.Objectjava.lang.Throwablepublic FbTransaction getTransaction()
getTransaction in interface FbStatementprotected abstract boolean isValidTransactionClass(java.lang.Class<? extends FbTransaction> transactionClass)
Eg a V10Statement will only work with an
FbWireTransaction implementation.
transactionClass - Class of the transactiontrue when the transaction class is valid for the statement implementation.public final void setTransaction(FbTransaction newTransaction) throws java.sql.SQLException
FbStatementsetTransaction in interface FbStatementnewTransaction - The transactionjava.sql.SQLExceptionpublic void setTimeout(long statementTimeout)
throws java.sql.SQLException
FbStatement
The statement timeout value is ignored in implementations that do not support timeouts. If the provided
timeout value is greater than supported (eg greater than 4294967295 milliseconds on Firebird 4), the
implementation should behave as if zero (0) was set, but still report the original value.
The configured timeout only affects subsequent executes on this statement. The timeout includes time spent between reading from the result set.
setTimeout in interface FbStatementstatementTimeout - Timeout value in millisecondsjava.sql.SQLException - If the value is less than zero, this statement is closed, or a database access error occurspublic long getTimeout()
throws java.sql.SQLException
FbStatementThis method will only return the current statement timeout value for this method, it will not consider attachment or connection level timeouts. This is an implementation decision that might change in a point release.
getTimeout in interface FbStatementFbStatement.setTimeout(long)java.sql.SQLException - If this statement is closed, or a database access error occursFbStatement.setTimeout(long)protected long getAllowedTimeout()
throws java.sql.SQLException
0 if the timeout is larger than supportedjava.sql.SQLException - If the statement is invalidprotected void parseStatementInfo(byte[] statementInfoResponse)
throws java.sql.SQLException
statementInfoResponse. If the response is truncated, a new
request is done using getStatementInfoRequestItems()statementInfoResponse - Statement info responsejava.sql.SQLExceptionprotected final boolean hasSingletonResult()
true if this is a stored procedure (or other singleton result producing statement) with at least 1 output fieldprotected final boolean hasFields()
true if this statement has at least one output field (either singleton or result set)protected final OperationCloseHandle signalExecute()
OperationCloseHandle handle for the operationprotected final OperationCloseHandle signalFetch()
OperationCloseHandle handle for the operationCopyright © 2001-2024 Jaybird (Firebird JDBC) team. All rights reserved.