Class AbstractFbStatement
- All Implemented Interfaces:
FbStatement,ExceptionListenable
- Direct Known Subclasses:
AbstractFbWireStatement,JnaStatement
- Since:
- 3.0
- Author:
- Mark Rotteveel
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final ExceptionListenerDispatcherprotected final StatementListenerDispatcher -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal voidaddExceptionListener(ExceptionListener listener) Adds an exception listener to this object.final voidaddStatementListener(StatementListener statementListener) Registers aStatementListener.protected final voidChecks if this statement is not inStatementState.CLOSED,StatementState.CLOSING,StatementState.NEWorStatementState.ERROR, and throws anSQLExceptionif it is.protected final voidcheckStatementValid(StatementState ignoreState) Performs the same check ascheckStatementValid(), but considersignoreStateas valid.voidclose()Close and deallocate this statement.final voidCloses the cursor associated with this statement, leaving the statement itself allocated.final voidcloseCursor(boolean transactionEnd) Closes the cursor associated with this statement, leaving the statement itself allocated.protected ExecutionPlanProcessorprotected SqlCountProcessorfinal voidensureClosedCursor(boolean transactionEnd) Ensures that the statement cursor is closed.protected voidfinalize()protected abstract voidfree(int option) Frees the currently allocated statement (either close the cursor withISCConstants.DSQL_closeor drop the statement handle usingISCConstants.DSQL_drop.protected longfinal Stringfinal Stringfinal RowDescriptorDeprecated.byte[]final RowDescriptorfinal RowDescriptorRetrieves the SQL counts for the last execution of this statement.final <T> TgetSqlInfo(byte[] requestItems, int bufferLength, InfoProcessor<T> infoProcessor) Request statement info.getState()byte[]protected final WarningMessageCallbackprotected final ObjectGet synchronization object.longGets the current statement timeout for this statement.protected final TransactionListenerGets theTransactionListenerinstance for this statement.final StatementTypegetType()protected final booleanprotected final booleanprotected final booleanprotected booleanisPrepareAllowed(StatementState state) Is a call toFbStatement.prepare(String)allowed for the suppliedStatementState.protected abstract booleanisValidTransactionClass(Class<? extends FbTransaction> transactionClass) Method to decide if a transaction implementation class is valid for the statement implementation.protected voidparseStatementInfo(byte[] statementInfoResponse) Parse the statement info response instatementInfoResponse.protected final voidqueueRowData(RowValue rowData) Queues row data for consumptionfinal voidremoveExceptionListener(ExceptionListener listener) Removes an exception listener to this object.final voidremoveStatementListener(StatementListener statementListener) Removes aStatementListener.protected final voidreset()Reset statement state, equivalent to callingreset(boolean)withfalseprotected voidreset(boolean resetAll) Resets the statement for next execution.protected final voidresetAll()Reset statement state and clear parameter description, equivalent to callingreset(boolean)withtrueprotected final voidsetAllRowsFetched(boolean allRowsFetched) Sets theallRowsFetchedproperty.protected voidsetFieldDescriptor(RowDescriptor fieldDescriptor) Deprecated.protected voidsetParameterDescriptor(RowDescriptor parameterDescriptor) Sets the parameter descriptor.protected voidsetRowDescriptor(RowDescriptor rowDescriptor) Sets the (result set) row descriptor.voidsetTimeout(long statementTimeout) Sets the statement timeout.final voidsetTransaction(FbTransaction newTransaction) Associates a transaction with this statementprotected voidsetType(StatementType type) Sets the StatementTypeprotected final OperationCloseHandleSignals the start of an execute for this statement.protected final OperationCloseHandleSignals the start of a fetch for this statement.protected final voidswitchState(StatementState newState) Sets the StatementState.final voidvalidateParameters(RowValue parameters) Validates if the number of parameters matches the expected number and types, and if all values have been set.Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.firebirdsql.gds.ng.FbStatement
emptyRowDescriptor, execute, fetchRows, getDatabase, getDefaultSqlInfoSize, getHandle, getMaxSqlInfoSize, getSqlInfo, prepare, setCursorName
-
Field Details
-
statementListenerDispatcher
-
exceptionListenerDispatcher
-
-
Constructor Details
-
AbstractFbStatement
-
-
Method Details
-
getTransactionListener
Gets theTransactionListenerinstance 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.- Returns:
- The transaction listener instance for this statement.
-
getStatementWarningCallback
-
getSynchronizationObject
Get synchronization object.- Returns:
- object, cannot be
null.
-
close
Description copied from interface:FbStatementClose and deallocate this statement.- Specified by:
closein interfaceFbStatement- Throws:
SQLException
-
closeCursor
Description copied from interface:FbStatementCloses the cursor associated with this statement, leaving the statement itself allocated.Equivalent to calling
FbStatement.closeCursor(boolean)withfalse.- Specified by:
closeCursorin interfaceFbStatement- Throws:
SQLException
-
closeCursor
Description copied from interface:FbStatementCloses the cursor associated with this statement, leaving the statement itself allocated.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.- Specified by:
closeCursorin interfaceFbStatement- Parameters:
transactionEnd- Close is in response to a transaction end.- Throws:
SQLException
-
ensureClosedCursor
Description copied from interface:FbStatementEnsures that the statement cursor is closed. Resets a statement so it is ready to be reused for re-execute or prepare.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.
- Specified by:
ensureClosedCursorin interfaceFbStatement- Parameters:
transactionEnd- Close is in response to a transaction end- Throws:
SQLException- If this statement is closed or the cursor could not be closed.
-
getState
- Specified by:
getStatein interfaceFbStatement- Returns:
- The current state of this statement
-
switchState
Sets the StatementState.- Parameters:
newState- New state- Throws:
SQLException- When the state is changed to an illegal next state
-
getType
- Specified by:
getTypein interfaceFbStatement- Returns:
- The statement type
-
setType
Sets the StatementType- Parameters:
type- New type
-
queueRowData
Queues row data for consumption- Parameters:
rowData- Row data
-
setAllRowsFetched
protected final void setAllRowsFetched(boolean allRowsFetched) Sets theallRowsFetchedproperty.When set to true all registered
StatementListenerinstances are notified for theStatementListener.allRowsFetched(FbStatement)event.- Parameters:
allRowsFetched-true: all rows fetched,falsenot all rows fetched.
-
isAllRowsFetched
protected final boolean isAllRowsFetched() -
reset
protected final void reset()Reset statement state, equivalent to callingreset(boolean)withfalse -
resetAll
protected final void resetAll()Reset statement state and clear parameter description, equivalent to callingreset(boolean)withtrue -
reset
protected void reset(boolean resetAll) Resets the statement for next execution. Implementation in derived class must synchronize ongetSynchronizationObject()and callsuper.reset(resetAll)- Parameters:
resetAll- Also reset field and parameter info
-
isPrepareAllowed
Is a call toFbStatement.prepare(String)allowed for the suppliedStatementState.- Parameters:
state- The statement state- Returns:
truecall toprepareis allowed
-
getParameterDescriptor
- Specified by:
getParameterDescriptorin interfaceFbStatement- Returns:
- descriptor of the parameters of this statement
-
setParameterDescriptor
Sets the parameter descriptor.- Parameters:
parameterDescriptor- Parameter descriptor
-
getFieldDescriptor
Deprecated.- Specified by:
getFieldDescriptorin interfaceFbStatement- Returns:
- descriptor of the fields returned by this statement
-
setFieldDescriptor
Deprecated.UsesetRowDescriptor(RowDescriptor)instead; will be removed in Jaybird 5Sets the (result set) field descriptor.- Parameters:
fieldDescriptor- Field descriptor
-
getRowDescriptor
- Specified by:
getRowDescriptorin interfaceFbStatement- Returns:
- descriptor of the row returned by this statement
-
setRowDescriptor
Sets the (result set) row descriptor.- Parameters:
rowDescriptor- Row descriptor
-
getStatementInfoRequestItems
public byte[] getStatementInfoRequestItems()- Returns:
- The (full) statement info request items.
- See Also:
-
getParameterDescriptionInfoRequestItems
public byte[] getParameterDescriptionInfoRequestItems()- Returns:
- The
isc_info_sql_describe_varsinfo request items. - See Also:
-
getSqlInfo
public final <T> T getSqlInfo(byte[] requestItems, int bufferLength, InfoProcessor<T> infoProcessor) throws SQLException Request statement info.- Specified by:
getSqlInfoin interfaceFbStatement- Parameters:
requestItems- Array of info items to requestbufferLength- Response buffer length to useinfoProcessor- Implementation ofInfoProcessorto transform the info response- Returns:
- Transformed info response of type T
- Throws:
SQLException- For errors retrieving or transforming the response.
-
getExecutionPlan
- Specified by:
getExecutionPlanin interfaceFbStatement- Returns:
- The execution plan of the currently prepared statement
- Throws:
SQLException- If this statement is closed.
-
getExplainedExecutionPlan
- Specified by:
getExplainedExecutionPlanin interfaceFbStatement- Returns:
- The detailed execution plan of the currently prepared statement
- Throws:
SQLException- If this statement is closed.
-
createExecutionPlanProcessor
- Returns:
- New instance of
ExecutionPlanProcessor(or subclass) for this statement.
-
getSqlCounts
Description copied from interface:FbStatementRetrieves the SQL counts for the last execution of this statement.The retrieved SQL counts are also notified to all registered
StatementListeners.In general the
FbStatementwill (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).- Specified by:
getSqlCountsin interfaceFbStatement- Returns:
- The SQL counts of the last execution of this statement
- Throws:
SQLException- If this statement is closed, or if this statement is in stateStatementState.CURSOR_OPENand not all rows have been fetched.
-
createSqlCountProcessor
- Returns:
- New instance of
SqlCountProcessor(or subclass) for this statement.
-
free
Frees the currently allocated statement (either close the cursor withISCConstants.DSQL_closeor drop the statement handle usingISCConstants.DSQL_drop.- Parameters:
option- Free option- Throws:
SQLException
-
validateParameters
Description copied from interface:FbStatementValidates if the number of parameters matches the expected number and types, and if all values have been set.- Specified by:
validateParametersin interfaceFbStatement- Parameters:
parameters- Parameter values to validate- Throws:
SQLException- When the number or type of parameters does not matchFbStatement.getParameterDescriptor(), or when a parameter has not been set.
-
addStatementListener
Description copied from interface:FbStatementRegisters aStatementListener.- Specified by:
addStatementListenerin interfaceFbStatement- Parameters:
statementListener- The row listener
-
removeStatementListener
Description copied from interface:FbStatementRemoves aStatementListener.- Specified by:
removeStatementListenerin interfaceFbStatement- Parameters:
statementListener- The row listener
-
addExceptionListener
Description copied from interface:ExceptionListenableAdds an exception listener to this object.Implementations use
WeakReference.- Specified by:
addExceptionListenerin interfaceExceptionListenable- Parameters:
listener- Listener to register
-
removeExceptionListener
Description copied from interface:ExceptionListenableRemoves an exception listener to this object.- Specified by:
removeExceptionListenerin interfaceExceptionListenable- Parameters:
listener- Listener to remove
-
checkStatementValid
Checks if this statement is not inStatementState.CLOSED,StatementState.CLOSING,StatementState.NEWorStatementState.ERROR, and throws anSQLExceptionif it is.- Throws:
SQLException- When this statement is closed or in error state.
-
checkStatementValid
Performs the same check ascheckStatementValid(), but considersignoreStateas valid.- Parameters:
ignoreState- The invalid state (seecheckStatementValid()to ignore- Throws:
SQLException- When this statement is closed or in error state.
-
finalize
-
getTransaction
- Specified by:
getTransactionin interfaceFbStatement- Returns:
- Transaction currently associated with this statement
-
isValidTransactionClass
Method to decide if a transaction implementation class is valid for the statement implementation.Eg a
V10Statementwill only work with anFbWireTransactionimplementation.- Parameters:
transactionClass- Class of the transaction- Returns:
truewhen the transaction class is valid for the statement implementation.
-
setTransaction
Description copied from interface:FbStatementAssociates a transaction with this statement- Specified by:
setTransactionin interfaceFbStatement- Parameters:
newTransaction- The transaction- Throws:
SQLException
-
setTimeout
Description copied from interface:FbStatementSets the statement timeout.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.
- Specified by:
setTimeoutin interfaceFbStatement- Parameters:
statementTimeout- Timeout value in milliseconds- Throws:
SQLException- If the value is less than zero, this statement is closed, or a database access error occurs
-
getTimeout
Description copied from interface:FbStatementGets the current statement timeout for this statement.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.
- Specified by:
getTimeoutin interfaceFbStatement- Returns:
- The configured timeout in milliseconds; read the documentation in
FbStatement.setTimeout(long) - Throws:
SQLException- If this statement is closed, or a database access error occurs- See Also:
-
getAllowedTimeout
- Returns:
- The timeout value, or
0if the timeout is larger than supported - Throws:
SQLException- If the statement is invalid
-
parseStatementInfo
Parse the statement info response instatementInfoResponse. If the response is truncated, a new request is done usinggetStatementInfoRequestItems()- Parameters:
statementInfoResponse- Statement info response- Throws:
SQLException
-
hasSingletonResult
protected final boolean hasSingletonResult()- Returns:
trueif this is a stored procedure (or other singleton result producing statement) with at least 1 output field
-
hasFields
protected final boolean hasFields()- Returns:
trueif this statement has at least one output field (either singleton or result set)
-
signalExecute
Signals the start of an execute for this statement.- Returns:
OperationCloseHandlehandle for the operation
-
signalFetch
Signals the start of a fetch for this statement.- Returns:
OperationCloseHandlehandle for the operation
-
setRowDescriptor(RowDescriptor)instead; will be removed in Jaybird 5