Method from org.apache.derby.iapi.services.context.ContextManager Detail: |
public boolean cleanupOnError(Throwable error) {
if (shutdown)
return true;
if (errorStringBuilder == null)
errorStringBuilder = new ErrorStringBuilder(errorStream.getHeader());
ThreadDeath seenThreadDeath = null;
if (error instanceof ThreadDeath)
seenThreadDeath = (ThreadDeath) error;
if (error instanceof PassThroughException) {
error = error.getCause();
}
boolean reportError = reportError(error);
if (reportError)
{
ContextImpl lcc = null;
StringBuffer sb = null;
if (! shutdown)
{
// report an id for the message if possible
lcc = (ContextImpl) getContext(org.apache.derby.iapi.reference.ContextId.LANG_CONNECTION);
if (lcc != null) {
sb = lcc.appendErrorInfo();
}
}
String cleanup = "Cleanup action starting";
if (sb != null) {
sb.append(cleanup);
cleanup = sb.toString();
}
errorStringBuilder.appendln(cleanup);
if (!shutdown) // Do this only during normal processing.
{
ContextImpl sc = (ContextImpl) getContext(org.apache.derby.iapi.reference.ContextId.LANG_STATEMENT);
// Output the SQL statement that failed in the log file.
if (sc != null)
{
sb = sc.appendErrorInfo();
if (sb != null)
errorStringBuilder.appendln(sb.toString());
}
}
}
/*
REVISIT RESOLVE
Ensure that the traversal of the stack works in all
cases where contexts can pop themselves *and*
contexts can pop other contexts off the stack.
*/
forever: for (;;) {
int errorSeverity = error instanceof StandardException ?
((StandardException) error).getSeverity() :
ExceptionSeverity.NO_APPLICABLE_SEVERITY;
if (reportError) {
errorStringBuilder.stackTrace(error);
flushErrorString();
}
boolean lastHandler = false;
/*
Walk down the stack, calling
cleanup on each context. We use
the vector interface to do this.
*/
cleanup: for (int index = holder.size() - 1; index >= 0; index--) {
try {
if (lastHandler)
{
break;
}
Context ctx = ((Context) holder.get(index));
lastHandler = ctx.isLastHandler(errorSeverity);
ctx.cleanupOnError(error);
}
catch (StandardException se) {
if (error instanceof StandardException) {
if (se.getSeverity() > ((StandardException) error).getSeverity()) {
// Ok, error handling raised a more severe error,
// restart with the more severe error
error = se;
reportError = reportError(se);
if (reportError) {
errorStream.println("New exception raised during cleanup " + error.getMessage());
errorStream.flush();
}
continue forever;
}
}
if (reportError(se)) {
errorStringBuilder.appendln("Less severe exception raised during cleanup (ignored) " + se.getMessage());
errorStringBuilder.stackTrace(se);
flushErrorString();
}
/*
For a less severe error, keep with the last error
*/
continue cleanup;
}
catch (Throwable t) {
reportError = reportError(t);
if (error instanceof StandardException) {
/*
Ok, error handling raised a more severe error,
restart with the more severe error
A Throwable after a StandardException is always
more severe.
*/
error = t;
if (reportError) {
errorStream.println("New exception raised during cleanup " + error.getMessage());
errorStream.flush();
}
continue forever;
}
if (reportError) {
errorStringBuilder.appendln("Equally severe exception raised during cleanup (ignored) " + t.getMessage());
errorStringBuilder.stackTrace(t);
flushErrorString();
}
if (t instanceof ThreadDeath) {
if (seenThreadDeath != null)
throw seenThreadDeath;
seenThreadDeath = (ThreadDeath) t;
}
/*
For a less severe error, just continue with the last
error
*/
continue cleanup;
}
}
if (reportError) {
errorStream.println("Cleanup action completed");
errorStream.flush();
}
if (seenThreadDeath != null)
throw seenThreadDeath;
return false;
}
}
|
public Context getContext(String contextId) {
checkInterrupt();
final CtxStack idStack = (CtxStack) ctxTable.get(contextId);
if (SanityManager.DEBUG)
SanityManager.ASSERT( idStack == null ||
idStack.isEmpty() ||
idStack.top().getIdName() == contextId);
return (idStack==null?null:idStack.top());
}
Obtain the last pushed Context object of the type indicated by
the contextId argument. |
public final List getContextStack(String contextId) {
final CtxStack cs = (CtxStack) ctxTable.get(contextId);
return (cs==null?Collections.EMPTY_LIST:cs.getUnmodifiableList());
}
Return an unmodifiable list reference to the ArrayList backing
CtxStack object for this type of Contexts. This method allows
fast traversal of all Contexts on that stack. The first element
in the List corresponds to the bottom of the stack. The
assumption is that the Stack will not be modified while it is
being traversed. |
public Locale getMessageLocale() {
if (messageLocale != null)
return messageLocale;
else if (finder != null) {
try {
return finder.getCurrentLocale();
} catch (StandardException se) {
}
}
return Locale.getDefault();
}
|
final boolean isEmpty() {
return holder.isEmpty();
}
Is the ContextManager empty containing no Contexts. |
public void popContext() {
checkInterrupt();
// no contexts to remove, so we're done.
if (holder.isEmpty()) {
return;
}
// remove the top context from the global stack
Context theContext = (Context) holder.remove(holder.size()-1);
// now find its id and remove it from there, too
final String contextId = theContext.getIdName();
final CtxStack idStack = (CtxStack) ctxTable.get(contextId);
if (SanityManager.DEBUG) {
SanityManager.ASSERT( idStack != null &&
(! idStack.isEmpty()) &&
idStack.top().getIdName() == contextId);
}
idStack.pop();
}
Remove the last pushed Context object, regardless of type. If
there are no Context objects, no action is taken. |
void popContext(Context theContext) {
checkInterrupt();
if (SanityManager.DEBUG)
SanityManager.ASSERT(!holder.isEmpty());
// first, remove it from the global stack.
holder.remove(holder.lastIndexOf(theContext));
final String contextId = theContext.getIdName();
final CtxStack idStack = (CtxStack) ctxTable.get(contextId);
// now remove it from its id's stack.
idStack.remove(theContext);
}
Removes the specified Context object. If
the specified Context object does not exist, the call will fail. |
public void pushContext(Context newContext) {
checkInterrupt();
final String contextId = newContext.getIdName();
CtxStack idStack = (CtxStack) ctxTable.get(contextId);
// if the stack is null, create a new one.
if (idStack == null) {
idStack = new CtxStack();
ctxTable.put(contextId, idStack);
}
// add to top of id's stack
idStack.push(newContext);
// add to top of global stack too
holder.add(newContext);
}
Add a Context object to the ContextManager. The object is added
both to the holder list and to a stack for the specific type of
Context. |
synchronized boolean setInterrupted(Context c) {
boolean interruptMe = (c == null) || holder.contains(c);
if (interruptMe) {
this.shutdown = true;
}
return interruptMe;
}
|
public void setLocaleFinder(LocaleFinder finder) {
this.finder = finder;
}
Set the locale for this context. |
public void setMessageLocale(String localeID) throws StandardException {
this.messageLocale = Monitor.getLocaleFromString(localeID);
}
|