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(java.lang.Object syncObject) |
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.
|
protected void |
finalize() |
protected abstract void |
free(int option)
Frees the currently allocated statement (either close the cursor with
ISCConstants.DSQL_close or drop the statement
handle using ISCConstants.DSQL_drop . |
protected long |
getAllowedTimeout() |
java.lang.String |
getExecutionPlan() |
java.lang.String |
getExplainedExecutionPlan() |
RowDescriptor |
getFieldDescriptor()
Deprecated.
|
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() |
protected java.lang.Object |
getSynchronizationObject()
Get synchronization object.
|
long |
getTimeout()
Gets the current statement timeout for this statement.
|
FbTransaction |
getTransaction() |
protected TransactionListener |
getTransactionListener()
Gets the
TransactionListener instance for this statement. |
StatementType |
getType() |
protected boolean |
hasFields() |
protected boolean |
hasSingletonResult() |
protected boolean |
isAllRowsFetched() |
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 |
setAllRowsFetched(boolean allRowsFetched)
Sets the
allRowsFetched property. |
protected void |
setFieldDescriptor(RowDescriptor fieldDescriptor)
Deprecated.
Use
setRowDescriptor(RowDescriptor) instead; will be removed in Jaybird 5 |
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 |
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, wait
emptyRowDescriptor, execute, fetchRows, getDatabase, getDefaultSqlInfoSize, getHandle, getMaxSqlInfoSize, getSqlInfo, prepare, setCursorName
protected 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()
protected final java.lang.Object getSynchronizationObject()
null
.public void close() throws java.sql.SQLException
FbStatement
close
in interface FbStatement
java.sql.SQLException
public final void closeCursor() throws java.sql.SQLException
FbStatement
Equivalent to calling FbStatement.closeCursor(boolean)
with false
.
closeCursor
in interface FbStatement
java.sql.SQLException
public final void closeCursor(boolean transactionEnd) throws java.sql.SQLException
FbStatement
When this method is called in preparation of a commit or rollback (see transactionEnd
), then
implementations may opt to not close the cursor on the server if the server closes the cursor automatically.
closeCursor
in interface FbStatement
transactionEnd
- Close is in response to a transaction end.java.sql.SQLException
public final void ensureClosedCursor(boolean transactionEnd) throws java.sql.SQLException
FbStatement
Implementations should only close an open cursor and log this fact with a stacktrace on debug. This is a stopgap measure for situations where the code using this statement handle has not been able to properly close the cursor.
ensureClosedCursor
in interface FbStatement
transactionEnd
- Close is in response to a transaction endjava.sql.SQLException
- If this statement is closed or the cursor could not be closed.public StatementState getState()
getState
in interface FbStatement
protected final void switchState(StatementState newState) throws java.sql.SQLException
newState
- New statejava.sql.SQLException
- When the state is changed to an illegal next statepublic final StatementType getType()
getType
in interface FbStatement
protected void setType(StatementType type)
type
- New typeprotected final void queueRowData(RowValue rowData)
rowData
- Row dataprotected final void setAllRowsFetched(boolean allRowsFetched)
allRowsFetched
property.
When set to true all registered StatementListener
instances are notified
for the StatementListener.allRowsFetched(FbStatement)
event.
allRowsFetched
- true
: all rows fetched, false
not all rows fetched.protected final boolean isAllRowsFetched()
protected final void reset()
reset(boolean)
with false
protected final void resetAll()
reset(boolean)
with true
protected void reset(boolean resetAll)
getSynchronizationObject()
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 FbStatement
protected void setParameterDescriptor(RowDescriptor parameterDescriptor)
parameterDescriptor
- Parameter descriptor@Deprecated public final RowDescriptor getFieldDescriptor()
getFieldDescriptor
in interface FbStatement
@Deprecated protected void setFieldDescriptor(RowDescriptor fieldDescriptor)
setRowDescriptor(RowDescriptor)
instead; will be removed in Jaybird 5fieldDescriptor
- Field descriptorpublic final RowDescriptor getRowDescriptor()
getRowDescriptor
in interface FbStatement
protected void setRowDescriptor(RowDescriptor rowDescriptor)
rowDescriptor
- Row descriptorpublic byte[] getStatementInfoRequestItems()
getParameterDescriptionInfoRequestItems()
public byte[] getParameterDescriptionInfoRequestItems()
isc_info_sql_describe_vars
info request items.getStatementInfoRequestItems()
public final <T> T getSqlInfo(byte[] requestItems, int bufferLength, InfoProcessor<T> infoProcessor) throws java.sql.SQLException
getSqlInfo
in interface FbStatement
requestItems
- 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 java.lang.String getExecutionPlan() throws java.sql.SQLException
getExecutionPlan
in interface FbStatement
java.sql.SQLException
- If this statement is closed.public final java.lang.String getExplainedExecutionPlan() throws java.sql.SQLException
getExplainedExecutionPlan
in interface FbStatement
java.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 StatementListener
s.
In general the FbStatement
will (should) retrieve and notify listeners of the SQL counts automatically at times were
it is relevant (eg after executing a statement that does not produce multiple rows, or after fetching all rows).
getSqlCounts
in interface FbStatement
java.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.SQLException
public final void validateParameters(RowValue parameters) throws java.sql.SQLException
FbStatement
validateParameters
in interface FbStatement
parameters
- 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)
FbStatement
StatementListener
.addStatementListener
in interface FbStatement
statementListener
- The row listenerpublic final void removeStatementListener(StatementListener statementListener)
FbStatement
StatementListener
.removeStatementListener
in interface FbStatement
statementListener
- The row listenerpublic final void addExceptionListener(ExceptionListener listener)
ExceptionListenable
Implementations use WeakReference
.
addExceptionListener
in interface ExceptionListenable
listener
- Listener to registerpublic final void removeExceptionListener(ExceptionListener listener)
ExceptionListenable
removeExceptionListener
in interface ExceptionListenable
listener
- 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.Object
java.lang.Throwable
public FbTransaction getTransaction()
getTransaction
in interface FbStatement
protected 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
FbStatement
setTransaction
in interface FbStatement
newTransaction
- The transactionjava.sql.SQLException
public 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 FbStatement
statementTimeout
- 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
FbStatement
This 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 FbStatement
FbStatement.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.SQLException
protected 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-2021 Jaybird (Firebird JDBC/JCA) team. All rights reserved.