Package org.apache.derby.impl.sql.conn
Class GenericStatementContext
- java.lang.Object
-
- org.apache.derby.iapi.services.context.ContextImpl
-
- org.apache.derby.impl.sql.conn.GenericStatementContext
-
- All Implemented Interfaces:
Context
,StatementContext
final class GenericStatementContext extends ContextImpl implements StatementContext
GenericStatementContext is pushed/popped around a statement prepare and execute so that any statement specific clean up can be performed.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
GenericStatementContext.CancelQueryTask
This is a TimerTask that is responsible for timing out statements, typically when an application has called Statement.setQueryTimeout().
-
Field Summary
Fields Modifier and Type Field Description private Activation
activation
The activation associated with this context, or nullprivate boolean
cancellationFlag
private GenericStatementContext.CancelQueryTask
cancelTask
private java.util.ArrayList<Dependency>
dependencies
private java.lang.String
internalSavePointName
private boolean
inUse
private boolean
isAtomic
private boolean
isForReadOnly
private boolean
isSystemCode
private LanguageConnectionContext
lcc
private NoPutResultSet[]
materializedSubqueries
private boolean
parentInTrigger
private ParameterValueSet
pvs
private boolean
rollbackParentContext
private boolean
setSavePoint
private short
sqlAllowed
Set to one of RoutineAliasInfo.private SQLSessionContext
sqlSessionContext
The SQLSessionContext associated with a statement context.private boolean
statementWasInvalidated
private java.lang.String
stmtText
private NoPutResultSet[]
subqueryTrackingArray
private ResultSet
topResultSet
-
Constructor Summary
Constructors Constructor Description GenericStatementContext(LanguageConnectionContext lcc)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addDependency(Dependency dy)
Track a Dependency within this StatementContext.java.lang.StringBuffer
appendErrorInfo()
void
cancel()
Cancels the statement which has allocated this StatementContext object.void
cleanupOnError(java.lang.Throwable error)
Close down the top ResultSet, if relevant, and rollback to the internal savepoint, if one was set.void
clearInUse()
Mark this context as not in use.void
clearSavePoint()
Clear the save point for the current statement.Activation
getActivation()
Get activation associated with this statement context, if any.short
getSQLAllowed()
Get the setting of the SQL allowed state.SQLSessionContext
getSQLSessionContext()
Get the current SQL session context.java.lang.String
getStatementText()
Return the text of the current statement.boolean
getStatementWasInvalidated()
Tells if this statement has been invalidated.NoPutResultSet[]
getSubqueryTrackingArray()
Get the subquery tracking array for this query.boolean
getSystemCode()
Return true if this statement is system code.private static TimerFactory
getTimerFactory()
boolean
inTrigger()
Returns whether we started from within the context of a trigger or not.boolean
inUse()
Is this statement context in use or not.boolean
isAtomic()
Indicates whether the statement needs to be executed atomically or not, i.e., whether a commit/rollback is permitted by a connection nested in this statement.boolean
isCancelled()
Tests whether the statement which has allocated this StatementContext object has been cancelled.boolean
isForReadOnly()
Is this statement for a read only, non-updatable ResultSetboolean
isLastHandler(int severity)
Return whether or not this context is the "last" handler for a the specified severity level.boolean
onStack()
Reports whether this StatementContext is on the context stack.private void
pleaseBeOnStack()
Raise an exception if this Context is not in use, that is, on the Context Stack.void
resetSavePoint()
Resets the savepoint to the current spot if it is set, otherwise, noop.void
setActivation(Activation a)
Mark this statement context as associated with this activation.void
setInUse(boolean parentInTrigger, boolean isAtomic, boolean isForReadOnly, java.lang.String stmtText, ParameterValueSet pvs, long timeoutMillis)
Mark this context as being in use.void
setParentRollback()
Indicate that, in the event of a statement-level exception, this context is NOT the last one that needs to be rolled back--rather, it is nested within some other statement context, and that other context needs to be rolled back, too.void
setSavePoint()
Set a save point for the current statement.void
setSQLAllowed(short allow, boolean force)
Set the level of SQL allowed in this and subsequent nested statements due to a routine call.void
setSQLSessionContext(SQLSessionContext ctx)
Set the current SQL session contextvoid
setSubqueryResultSet(int subqueryNumber, NoPutResultSet subqueryResultSet, int numSubqueries)
Set the appropriate entry in the subquery tracking array for the specified subquery.void
setSystemCode()
Set to indicate statement is system code.void
setTopResultSet(ResultSet topResultSet, NoPutResultSet[] subqueryTrackingArray)
Set the top ResultSet in the ResultSet tree for close down on an error.private void
stuffTopResultSet(ResultSet topResultSet, NoPutResultSet[] subqueryTrackingArray)
Private minion of setTopResultSet() and clearInUse()-
Methods inherited from class org.apache.derby.iapi.services.context.ContextImpl
getContextManager, getIdName, popMe, pushMe
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.derby.iapi.services.context.Context
getContextManager, getIdName, popMe, pushMe
-
-
-
-
Field Detail
-
setSavePoint
private boolean setSavePoint
-
internalSavePointName
private java.lang.String internalSavePointName
-
topResultSet
private ResultSet topResultSet
-
dependencies
private java.util.ArrayList<Dependency> dependencies
-
subqueryTrackingArray
private NoPutResultSet[] subqueryTrackingArray
-
materializedSubqueries
private NoPutResultSet[] materializedSubqueries
-
lcc
private final LanguageConnectionContext lcc
-
inUse
private boolean inUse
-
cancellationFlag
private volatile boolean cancellationFlag
-
cancelTask
private GenericStatementContext.CancelQueryTask cancelTask
-
parentInTrigger
private boolean parentInTrigger
-
isForReadOnly
private boolean isForReadOnly
-
isAtomic
private boolean isAtomic
-
isSystemCode
private boolean isSystemCode
-
rollbackParentContext
private boolean rollbackParentContext
-
statementWasInvalidated
private boolean statementWasInvalidated
-
stmtText
private java.lang.String stmtText
-
pvs
private ParameterValueSet pvs
-
sqlAllowed
private short sqlAllowed
Set to one of RoutineAliasInfo.{MODIFIES_SQL_DATA, READS_SQL_DATA, CONTAINS_SQL, NO_SQL}
-
activation
private Activation activation
The activation associated with this context, or null
-
sqlSessionContext
private SQLSessionContext sqlSessionContext
The SQLSessionContext associated with a statement context.
-
-
Constructor Detail
-
GenericStatementContext
GenericStatementContext(LanguageConnectionContext lcc)
-
-
Method Detail
-
getTimerFactory
private static TimerFactory getTimerFactory()
-
setInUse
public void setInUse(boolean parentInTrigger, boolean isAtomic, boolean isForReadOnly, java.lang.String stmtText, ParameterValueSet pvs, long timeoutMillis)
Description copied from interface:StatementContext
Mark this context as being in use.- Specified by:
setInUse
in interfaceStatementContext
- Parameters:
parentInTrigger
- true if the parent started in the context of a triggerisAtomic
- true if the statement must be executed atomicallyisForReadOnly
- true if the statement is for producing non-updatable resultsetstmtText
- the text of the statement. Needed for any language statement (currently, for any statement that can cause a trigger to fire). Please set this unless you are some funky jdbc setXXX method or something.pvs
- parameter value set, if it has onetimeoutMillis
- timeout value for the statement, in milliseconds. Zero means no timeout.
-
clearInUse
public void clearInUse()
Description copied from interface:StatementContext
Mark this context as not in use. This is important because we always leave the top statement context on the stack, and we don't want to clean it up if a statement level exception happens while the context is not in use.- Specified by:
clearInUse
in interfaceStatementContext
-
setSavePoint
public void setSavePoint() throws StandardException
Description copied from interface:StatementContext
Set a save point for the current statement. NOTE: This needs to be off of the StatementContext so that it gets cleared on a statement error.- Specified by:
setSavePoint
in interfaceStatementContext
- Throws:
StandardException
- Thrown on error- See Also:
StatementContext.setSavePoint()
-
resetSavePoint
public void resetSavePoint() throws StandardException
Resets the savepoint to the current spot if it is set, otherwise, noop. Used when a commit is done on a nested connection.- Specified by:
resetSavePoint
in interfaceStatementContext
- Throws:
StandardException
- Thrown on error- See Also:
StatementContext.resetSavePoint()
-
clearSavePoint
public void clearSavePoint() throws StandardException
Description copied from interface:StatementContext
Clear the save point for the current statement.- Specified by:
clearSavePoint
in interfaceStatementContext
- Throws:
StandardException
- Thrown on error- See Also:
StatementContext.clearSavePoint()
-
setTopResultSet
public void setTopResultSet(ResultSet topResultSet, NoPutResultSet[] subqueryTrackingArray) throws StandardException
Set the top ResultSet in the ResultSet tree for close down on an error.- Specified by:
setTopResultSet
in interfaceStatementContext
- Parameters:
topResultSet
- The top ResultSet in the ResultSet treesubqueryTrackingArray
- (Sparse) of tops of subquery ResultSet trees- Throws:
StandardException
- thrown on error.
-
stuffTopResultSet
private void stuffTopResultSet(ResultSet topResultSet, NoPutResultSet[] subqueryTrackingArray)
Private minion of setTopResultSet() and clearInUse()- Parameters:
topResultSet
- make this the top result setsubqueryTrackingArray
- where to keep track of subqueries in this statement
-
setSubqueryResultSet
public void setSubqueryResultSet(int subqueryNumber, NoPutResultSet subqueryResultSet, int numSubqueries) throws StandardException
Set the appropriate entry in the subquery tracking array for the specified subquery. Useful for closing down open subqueries on an exception.- Specified by:
setSubqueryResultSet
in interfaceStatementContext
- Parameters:
subqueryNumber
- The subquery # for this subquerysubqueryResultSet
- The ResultSet at the top of the subquerynumSubqueries
- The total # of subqueries in the entire query- Throws:
StandardException
- thrown on error.
-
getSubqueryTrackingArray
public NoPutResultSet[] getSubqueryTrackingArray() throws StandardException
Get the subquery tracking array for this query. (Useful for runtime statistics.)- Specified by:
getSubqueryTrackingArray
in interfaceStatementContext
- Returns:
- NoPutResultSet[] The (sparse) array of tops of subquery ResultSet trees
- Throws:
StandardException
- thrown on error.
-
addDependency
public void addDependency(Dependency dy) throws StandardException
Track a Dependency within this StatementContext. (We need to clear any dependencies added within this context on an error.- Specified by:
addDependency
in interfaceStatementContext
- Parameters:
dy
- The dependency to track.- Throws:
StandardException
- thrown on error.
-
inTrigger
public boolean inTrigger()
Returns whether we started from within the context of a trigger or not.- Specified by:
inTrigger
in interfaceStatementContext
- Returns:
- true if we are in a trigger context
-
cleanupOnError
public void cleanupOnError(java.lang.Throwable error) throws StandardException
Close down the top ResultSet, if relevant, and rollback to the internal savepoint, if one was set.- Specified by:
cleanupOnError
in interfaceContext
- Throws:
StandardException
- thrown on error. REVISIT: don't want cleanupOnError's to throw exceptions.
-
isLastHandler
public boolean isLastHandler(int severity)
Description copied from interface:Context
Return whether or not this context is the "last" handler for a the specified severity level. Previously, the context manager would march through all of the contexts in cleanupOnError() and call each of their cleanupOnError() methods. That did not work with server side JDBC, especially for a StatementException, because outer contexts could get cleaned up incorrectly. This functionality is specific to the Language system. Any non-language system contexts should return ExceptionSeverity.NOT_APPLICABLE_SEVERITY. NOTE: Both the LanguageConnectionContext and the JDBC Connection Context are interested in session level errors because they both have clean up to do. This method allows both of them to return false so that all such handlers under them can do their clean up.- Specified by:
isLastHandler
in interfaceContext
- Overrides:
isLastHandler
in classContextImpl
- See Also:
Context.isLastHandler(int)
-
onStack
public boolean onStack()
Reports whether this StatementContext is on the context stack.- Specified by:
onStack
in interfaceStatementContext
- Returns:
- true if this StatementContext is on the context stack. false otherwise.
-
isAtomic
public boolean isAtomic()
Indicates whether the statement needs to be executed atomically or not, i.e., whether a commit/rollback is permitted by a connection nested in this statement.- Specified by:
isAtomic
in interfaceStatementContext
- Returns:
- true if needs to be atomic
-
getStatementText
public java.lang.String getStatementText()
Return the text of the current statement. Note that this may be null. It is currently not set up correctly for ResultSets that aren't single row result sets (e.g SELECT), replication, and setXXXX/getXXXX jdbc methods.- Specified by:
getStatementText
in interfaceStatementContext
- Returns:
- the statement text
-
pleaseBeOnStack
private void pleaseBeOnStack() throws StandardException
Raise an exception if this Context is not in use, that is, on the Context Stack.- Throws:
StandardException
- thrown on error.
-
inUse
public boolean inUse()
Description copied from interface:StatementContext
Is this statement context in use or not.- Specified by:
inUse
in interfaceStatementContext
- Returns:
- true if in use
-
isForReadOnly
public boolean isForReadOnly()
Description copied from interface:StatementContext
Is this statement for a read only, non-updatable ResultSet- Specified by:
isForReadOnly
in interfaceStatementContext
- Returns:
- true if the statement is for creating a read only, non-updatable ResultSet
-
isCancelled
public boolean isCancelled()
Tests whether the statement which has allocated this StatementContext object has been cancelled. This method is typically called from the thread which is executing the statement, to test whether execution should continue or stop.- Specified by:
isCancelled
in interfaceStatementContext
- Returns:
- whether the statement which has allocated this StatementContext object has been cancelled.
-
cancel
public void cancel()
Cancels the statement which has allocated this StatementContext object. This is done by setting a flag in the StatementContext object. For this to have any effect, it is the responsibility of the executing statement to check this flag regularly.- Specified by:
cancel
in interfaceStatementContext
-
setSQLAllowed
public void setSQLAllowed(short allow, boolean force)
Description copied from interface:StatementContext
Set the level of SQL allowed in this and subsequent nested statements due to a routine call. Value must be one of RoutineAliasInfo.{MODIFIES_SQL_DATA, READS_SQL_DATA, CONTAINS_SQL, NO_SQL}- Specified by:
setSQLAllowed
in interfaceStatementContext
force
- set to true to override more restrictive setting. Used to reset the permissions after a function call.
-
getSQLAllowed
public short getSQLAllowed()
Description copied from interface:StatementContext
Get the setting of the SQL allowed state.- Specified by:
getSQLAllowed
in interfaceStatementContext
-
setParentRollback
public void setParentRollback()
Indicate that, in the event of a statement-level exception, this context is NOT the last one that needs to be rolled back--rather, it is nested within some other statement context, and that other context needs to be rolled back, too.- Specified by:
setParentRollback
in interfaceStatementContext
-
setSystemCode
public void setSystemCode()
Set to indicate statement is system code. For example a system procedure, view, function etc.- Specified by:
setSystemCode
in interfaceStatementContext
-
getSystemCode
public boolean getSystemCode()
Return true if this statement is system code.- Specified by:
getSystemCode
in interfaceStatementContext
-
appendErrorInfo
public java.lang.StringBuffer appendErrorInfo()
- Overrides:
appendErrorInfo
in classContextImpl
-
setActivation
public void setActivation(Activation a)
Description copied from interface:StatementContext
Mark this statement context as associated with this activation.- Specified by:
setActivation
in interfaceStatementContext
- Parameters:
a
- activation- See Also:
StatementContext.setActivation(Activation a)
-
getActivation
public Activation getActivation()
Description copied from interface:StatementContext
Get activation associated with this statement context, if any. Used to link up stack of activations of calls in nested connections, see GenericPreparedStatement#getActivation.- Specified by:
getActivation
in interfaceStatementContext
- See Also:
StatementContext.getActivation()
-
getSQLSessionContext
public SQLSessionContext getSQLSessionContext()
Description copied from interface:StatementContext
Get the current SQL session context.- Specified by:
getSQLSessionContext
in interfaceStatementContext
- Returns:
- the current SQL session context
- See Also:
StatementContext.getSQLSessionContext()
-
setSQLSessionContext
public void setSQLSessionContext(SQLSessionContext ctx)
Description copied from interface:StatementContext
Set the current SQL session context- Specified by:
setSQLSessionContext
in interfaceStatementContext
- Parameters:
ctx
- the SQL session context- See Also:
StatementContext.setSQLSessionContext(SQLSessionContext ctx)
-
getStatementWasInvalidated
public boolean getStatementWasInvalidated()
Description copied from interface:StatementContext
Tells if this statement has been invalidated.- Specified by:
getStatementWasInvalidated
in interfaceStatementContext
- Returns:
true
if the statement was invalidated.
-
-