Top Description Inners Fields Constructors Methods
org.apache.derby.iapi.services.context

public Class ContextManager

extends Object
Class Inheritance
Imports
org.apache.derby.shared.common.sanity.SanityManager, org.apache.derby.shared.common.stream.HeaderPrintWriter, org.apache.derby.shared.common.error.ErrorStringBuilder, .PassThroughException, .ShutdownException, .StandardException, .ExceptionUtil, .ExceptionSeverity, org.apache.derby.iapi.services.monitor.Monitor, org.apache.derby.shared.common.reference.Property, .ContextId, org.apache.derby.iapi.services.property.PropertyUtil, org.apache.derby.shared.common.i18n.LocaleFinder, org.apache.derby.shared.common.info.JVMInfo, java.sql.SQLException, java.util.HashMap, .ArrayList, .List, .Collections, .Locale

The ContextManager collects contexts as they are created. It maintains stacks of contexts by named ids, so that the top context of a given type can be returned. It also maintains a global stack so that contexts can be traversed in the order they were created.

The first implementation of the context manager assumes there is only one thread to worry about and that the user(s) of the class only create one instance of ContextManager.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
ContextManager.CtxStack

The CtxStack implement a stack on top of an ArrayList (to avoid the inherent overhead associated with java.util.Stack which is built on top of java.util.Vector, which is fully synchronized).

Field Summary

Modifier and TypeField and Description
pack-priv int
activeCount

Count of the number of setCurrentContextManager calls by a single thread, for nesting situations with a single active Contextmanager.

pack-priv Thread
activeThread

The thread that owns this ContextManager, set by ContextService.setCurrentContextManager and reset by resetCurrentContextManager.

private final HashMap<String, ContextManager.CtxStack>
ctxTable

HashMap that holds the Context objects.

private HeaderPrintWriter
private ErrorStringBuilder
private int
private LocaleFinder
private final ArrayList<Context>
holder

List of all Contexts

private int
private Locale
pack-priv final ContextService
private boolean
private String

Constructor Summary

AccessConstructor and Description
pack-priv
ContextManager(ContextService
the ContextService owning this ContextManager
csf
,
HeaderPrintWriter
error stream for reporting errors
stream
)

Constructs a new instance.

Method Summary

Modifier and TypeMethod and Description
private void
checkInterrupt()

Check to see if we have been interrupted.

public boolean

Returns:

true if the context manager is shutdown, false otherwise.
cleanupOnError
(Throwable
the error we want to clean up
error
,
boolean
true if extended diagnostics should be considered, false not interested of extended diagnostic information
diagActive
)

clean up error and print it to derby.log.

private void
flushErrorString()

Flush the built up error string to whereever it is supposed to go, and reset the error string

public Context

Returns:

The Context object with the corresponding contextId, or null if not found
getContext
(String
a String identifying the type of Context
contextId
)

Obtain the last pushed Context object of the type indicated by the contextId argument.

public final List<Context>

Returns:

an unmodifiable "view" of the ArrayList backing the stack
getContextStack
(String
the type of Context stack to return.
contextId
)

Return an unmodifiable list reference to the ArrayList backing CtxStack object for this type of Contexts.

public int

Returns:

int vendorcode/severity for the Throwable error - error/exception to extract vendorcode/severity. For error that we can not get severity, NO_APPLICABLE_SEVERITY will return.
getErrorSeverity
(Throwable
- Throwable error
error
)

return the severity of the exception.

public Locale
pack-priv final boolean
isEmpty()

Is the ContextManager empty containing no Contexts.

public void
popContext()

Remove the last pushed Context object, regardless of type.

pack-priv void
popContext(Context
the Context object to remove.
theContext
)

Removes the specified Context object.

public void
pushContext(Context
the new Context object
newContext
)

Add a Context object to the ContextManager.

private boolean
pack-priv synchronized boolean
public void
setLocaleFinder(LocaleFinder
The local finder
finder
)

Set the locale for this context.

public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

activeCountback to summary
pack-priv int activeCount

Count of the number of setCurrentContextManager calls by a single thread, for nesting situations with a single active Contextmanager. If nesting is occuring with multiple different ContextManagers then this value is set to -1 and nesting is represented by entries in a stack in the ThreadLocal variable, threadContextList.

See Also
ContextService#threadContextList
activeThreadback to summary
pack-priv Thread activeThread

The thread that owns this ContextManager, set by ContextService.setCurrentContextManager and reset by resetCurrentContextManager. Only a single thread can be active in a ContextManager at any time, and the thread only "owns" the ContextManager while it is executing code within Derby. In the JDBC case setCurrentContextManager is called at the start of a JBDC method and resetCurrentContextManager on completion. Nesting within the same thread is supported, such as server-side JDBC calls in a Java routine or procedure. In that case the activeCount will represent the level of nesting, in some situations.

See Also
ContextService#setCurrentContextManager(ContextManager), ContextService#resetCurrentContextManager(ContextManager), activeCount
ctxTableback to summary
private final HashMap<String, ContextManager.CtxStack> ctxTable

HashMap that holds the Context objects. The Contexts are stored with a String key.

See Also
ContextManager#pushContext(Context)
errorStreamback to summary
private HeaderPrintWriter errorStream
errorStringBuilderback to summary
private ErrorStringBuilder errorStringBuilder
extDiagSeverityLevelback to summary
private int extDiagSeverityLevel
finderback to summary
private LocaleFinder finder
holderback to summary
private final ArrayList<Context> holder

List of all Contexts

logSeverityLevelback to summary
private int logSeverityLevel
messageLocaleback to summary
private Locale messageLocale
owningCsfback to summary
pack-priv final ContextService owningCsf
shutdownback to summary
private boolean shutdown
threadDumpback to summary
private String threadDump

Constructor Detail

ContextManagerback to summary
pack-priv ContextManager(ContextService csf, HeaderPrintWriter stream)

Constructs a new instance. No CtxStacks are inserted into the hashMap as they will be allocated on demand.

Parameters
csf:ContextService

the ContextService owning this ContextManager

stream:HeaderPrintWriter

error stream for reporting errors

Method Detail

checkInterruptback to summary
private void checkInterrupt()

Check to see if we have been interrupted. If we have then a ShutdownException will be thrown. This will be either the one passed to interrupt or a generic one if some outside source interrupted the thread.

cleanupOnErrorback to summary
public boolean cleanupOnError(Throwable error, boolean diagActive)

clean up error and print it to derby.log. Extended diagnosis including thread dump to derby.log and javaDump if available, will print if the database is active and severity is greater than or equals to SESSTION_SEVERITY or as configured by derby.stream.error.extendedDiagSeverityLevel property

Parameters
error:Throwable

the error we want to clean up

diagActive:boolean

true if extended diagnostics should be considered, false not interested of extended diagnostic information

Returns:boolean

true if the context manager is shutdown, false otherwise.

Annotations
@SuppressWarnings:removal
flushErrorStringback to summary
private void flushErrorString()

Flush the built up error string to whereever it is supposed to go, and reset the error string

getContextback to summary
public Context getContext(String contextId)

Obtain the last pushed Context object of the type indicated by the contextId argument.

Parameters
contextId:String

a String identifying the type of Context

Returns:Context

The Context object with the corresponding contextId, or null if not found

getContextStackback to summary
public final List<Context> getContextStack(String contextId)

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.

Parameters
contextId:String

the type of Context stack to return.

Returns:List<Context>

an unmodifiable "view" of the ArrayList backing the stack

See Also
org.apache.derby.impl.sql.conn.GenericLanguageConnectionContext#resetSavepoints(), org.apache.derby.iapi.sql.conn.StatementContext#resetSavePoint()
getErrorSeverityback to summary
public int getErrorSeverity(Throwable error)

return the severity of the exception. Currently, this method does not determine a severity that is not StandardException or SQLException.

Parameters
error:Throwable

- Throwable error

Returns:int

int vendorcode/severity for the Throwable error - error/exception to extract vendorcode/severity. For error that we can not get severity, NO_APPLICABLE_SEVERITY will return.

getMessageLocaleback to summary
public Locale getMessageLocale()
isEmptyback to summary
pack-priv final boolean isEmpty()

Is the ContextManager empty containing no Contexts.

popContextback to summary
public void popContext()

Remove the last pushed Context object, regardless of type. If there are no Context objects, no action is taken.

popContextback to summary
pack-priv void popContext(Context theContext)

Removes the specified Context object. If the specified Context object does not exist, the call will fail.

Parameters
theContext:Context

the Context object to remove.

pushContextback to summary
public void pushContext(Context 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.

Parameters
newContext:Context

the new Context object

reportErrorback to summary
private boolean reportError(Throwable t)
setInterruptedback to summary
pack-priv synchronized boolean setInterrupted(Context c)
setLocaleFinderback to summary
public void setLocaleFinder(LocaleFinder finder)

Set the locale for this context.

Parameters
finder:LocaleFinder

The local finder

setMessageLocaleback to summary
public void setMessageLocale(String localeID) throws StandardException
org.apache.derby.iapi.services.context back to summary

private final Class ContextManager.CtxStack

extends Object
Class Inheritance
  • java.lang.Object
  • org.apache.derby.iapi.services.context.ContextManager.CtxStack

The CtxStack implement a stack on top of an ArrayList (to avoid the inherent overhead associated with java.util.Stack which is built on top of java.util.Vector, which is fully synchronized).

Field Summary

Modifier and TypeField and Description
private final ArrayList<Context>
stack_

Internal list with all the elements of the stack.

private Context
private final List<Context>
view_

Read-only view of the internal list.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
pack-priv List<Context>
pack-priv boolean
pack-priv void
pop()

pack-priv void
push(Context context)

pack-priv void
remove(Context context)

pack-priv Context
top()

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

stack_back to summary
private final ArrayList<Context> stack_

Internal list with all the elements of the stack.

top_back to summary
private Context top_
view_back to summary
private final List<Context> view_

Read-only view of the internal list.

Constructor Detail

CtxStackback to summary
private CtxStack()

Method Detail

getUnmodifiableListback to summary
pack-priv List<Context> getUnmodifiableList()
isEmptyback to summary
pack-priv boolean isEmpty()
popback to summary
pack-priv void pop()
pushback to summary
pack-priv void push(Context context)
removeback to summary
pack-priv void remove(Context context)
topback to summary
pack-priv Context top()