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. |
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 . |
java.lang.String |
getExecutionPlan() |
RowDescriptor |
getFieldDescriptor() |
byte[] |
getParameterDescriptionInfoRequestItems() |
RowDescriptor |
getParameterDescriptor() |
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.
|
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)
Sets the (result set) field descriptor.
|
protected void |
setParameterDescriptor(RowDescriptor parameterDescriptor)
Sets the parameter descriptor.
|
void |
setTransaction(FbTransaction newTransaction)
Associates a transaction with this statement
|
protected void |
setType(StatementType type)
Sets the StatementType
|
protected void |
switchState(StatementState newState)
Sets the StatementState.
|
protected 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 descriptorpublic final RowDescriptor getFieldDescriptor()
getFieldDescriptor
in interface FbStatement
protected void setFieldDescriptor(RowDescriptor fieldDescriptor)
fieldDescriptor
- Field 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.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
protected void validateParameters(RowValue parameters) throws java.sql.SQLException
parameters
- Parameter values to validatejava.sql.SQLException
- When the number or type of parameters does not match 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 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
protected 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)Copyright © 2001-2021 Jaybird (Firebird JDBC/JCA) team. All rights reserved.