📄 genericstatementcontext.java
字号:
*/ if (subqueryTrackingArray == null) { if (topResultSet == null) { subqueryTrackingArray = new NoPutResultSet[numSubqueries]; materializedSubqueries = new NoPutResultSet[numSubqueries]; } else { subqueryTrackingArray = topResultSet.getSubqueryTrackingArray(numSubqueries); } } subqueryTrackingArray[subqueryNumber] = subqueryResultSet; if (materializedSubqueries != null) { materializedSubqueries[subqueryNumber] = subqueryResultSet; } } /** * Get the subquery tracking array for this query. * (Useful for runtime statistics.) * * @return NoPutResultSet[] The (sparse) array of tops of subquery ResultSet trees * @exception StandardException thrown on error. */ public NoPutResultSet[] getSubqueryTrackingArray() throws StandardException { pleaseBeOnStack(); return subqueryTrackingArray; } /** * Track a Dependency within this StatementContext. * (We need to clear any dependencies added within this * context on an error. * * @param dy The dependency to track. * * @return Nothing. * @exception StandardException thrown on error. */ public void addDependency(Dependency dy) throws StandardException { pleaseBeOnStack(); if (dependencies == null) { dependencies = new ArrayList(); } dependencies.add(dy); } /** * Returns whether we started from within the context of a trigger * or not. * * @return true if we are in a trigger context */ public boolean inTrigger() { return parentInTrigger; } // // Context interface // /** * Close down the top ResultSet, if relevant, and rollback to the * internal savepoint, if one was set. * * @exception StandardException thrown on error. REVISIT: don't want * cleanupOnError's to throw exceptions. */ public void cleanupOnError(Throwable error) throws StandardException { if (SanityManager.DEBUG) { if (SanityManager.DEBUG_ON("traceSavepoints")) { SanityManager.DEBUG_PRINT( "GenericStatementContext.cleanupOnError()", String.valueOf( hashCode() ) ); } } /* ** If it isn't a StandardException, then assume ** xact severity. It is probably an unexpected ** java error somewhere in the language. */ int severity = (error instanceof StandardException) ? ((StandardException) error).getSeverity() : ExceptionSeverity.STATEMENT_SEVERITY; /** * Don't clean up this statement context if it's not in use. * This can happen if you get an error while calling one of * the JDBC getxxxx() methods on a ResultSet, since no statement * context is pushed when those calls occur. */ if (! inUse) { return; } /* Clean up the ResultSet, if one exists */ if (topResultSet != null) { topResultSet.cleanUp(); } /* Close down any open subqueries */ if (subqueryTrackingArray != null) { for (int index = 0; index < subqueryTrackingArray.length; index++) { /* Remember, the array is sparse, so only check * non-null entries. */ if (subqueryTrackingArray[index] != null) { subqueryTrackingArray[index].cleanUp(); } } } /* Clean up any dependencies */ if (dependencies != null) { DependencyManager dmgr = lcc.getDataDictionary().getDependencyManager(); for (Iterator iterator = dependencies.iterator(); iterator.hasNext(); ) { Dependency dy = (Dependency) iterator.next(); dmgr.clearInMemoryDependency(dy); } dependencies = null; } if (severity <= ExceptionSeverity.STATEMENT_SEVERITY && setSavePoint) { if (SanityManager.DEBUG) { if (SanityManager.DEBUG_ON("traceSavepoints")) { SanityManager.DEBUG_PRINT( "GenericStatementContext.cleanupOnError", "rolling back to: " + internalSavePointName); } } lcc.internalRollbackToSavepoint( internalSavePointName, false, null); clearSavePoint(); } if (severity >= ExceptionSeverity.TRANSACTION_SEVERITY ) { // transaction severity errors roll back the transaction. /* ** We call clearSavePoint() above only for statement errors. ** We don't call clearSavePoint() for transaction errors because ** the savepoint will be rolled back anyway. So in this case, ** we need to indicate that the savepoint is not set. */ setSavePoint = false; } /* Pop the context */ lcc.popStatementContext(this, error); } /** * @see Context#isLastHandler */ public boolean isLastHandler(int severity) { return inUse && !rollbackParentContext && ((severity == ExceptionSeverity.STATEMENT_SEVERITY) || (severity == ExceptionSeverity.NO_APPLICABLE_SEVERITY)); } /** * Reports whether this StatementContext is on the context stack. * * @return true if this StatementContext is on the context stack. false otherwise. */ public boolean onStack() { return inUse; } /** * 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. * * @return true if needs to be atomic */ public boolean isAtomic() { return isAtomic; } /** * 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. * * @return the statement text */ public String getStatementText() { return stmtText; } // // class implementation // /** * Raise an exception if this Context is not in use, that is, on the * Context Stack. * * @exception StandardException thrown on error. */ private void pleaseBeOnStack() throws StandardException { if ( !inUse ) { throw StandardException.newException(SQLState.LANG_DEAD_STATEMENT); } } public boolean inUse() { return inUse; } public void setSQLAllowed(short allow, boolean force) { // cannot override a stricter setting. // -1 is no routine restriction in place // 0 is least restrictive // 4 is most if (force || (allow > sqlAllowed)) sqlAllowed = allow; } public short getSQLAllowed() { if (!inUse) return org.apache.derby.catalog.types.RoutineAliasInfo.NO_SQL; return sqlAllowed; } /** * 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. */ public void setParentRollback() { rollbackParentContext = true; } /** Set to indicate statement is system code. For example a system procedure, view, function etc. */ public void setSystemCode() { isSystemCode = true; } /** Return true if this statement is system code. */ public boolean getSystemCode() { return isSystemCode; } public StringBuffer appendErrorInfo() { StringBuffer sb = ((ContextImpl) lcc).appendErrorInfo(); if (sb != null) { sb.append("Failed Statement is: "); sb.append(getStatementText()); if (lcc.getLogStatementText() && (pvs != null) && pvs.getParameterCount() > 0) { String pvsString = " with " + pvs.getParameterCount() + " parameters " + pvs.toString(); sb.append(pvsString); } } return sb; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -