Some users have reported unexpected behavior when connecting to Active Directory applications as a result of a misunderstanding about the use the getContext() method.
context.getContext() is a method provided by the SailPointContext interface to allow an implementer to create a private context. That is, a context completely independent from the current thread's primary context and, by extension, its Hibernate session.
As a result of this independence, the new context creates a fresh object cache from scratch, including new connections and a new blank cache. This has performance implications, as resources are allocated and the connection pool can be depleted.
While there are limited situations where getContext() may have some utility, it is best practice to avoid its use entirely in a production environment.
There's no need to call context.getContext() to simply operate on context objects. The SailPointContext interface can be seamlessly cast or directly manipulated, as in the following examples:
someMethod(InternalContext internalContext) {
SailPointContext context = internalContext;
// Operate on context
}
someMethod(SailPointContext context) {
// Operate on context
}
someMethod(internalContext); // Call someMethod, which casts 'internalContext' automatically.
To create a private context, callers should always use SailPointFactory.createPrivateContext().
When creating any manner of private context, you must take action to release the context when you're done with it, as in the following example:
someMethod(InternalContext internalContext) {
SailPointContext context = internalContext.getContext();
// Operate on 'context'
sailpoint.api.SailPointFactory.releasePrivateContext(context); //Release 'context'
}
One advantage of a properly created and released this private context is to potentially clobber the Hibernate cache without causing a disruption to the original session. Consider the following example:
SailPointContext private = SailPointFactory.createPrivateContext();
private.getObjects(Identity.class, new QueryOptions()); // fetches all of the Identities in the system
// iterate through these Identities; private now has 10,000 Identities in its hibernate cache
sailpoint.api.SailPointFactory.releasePrivateContext(private); // release private
// context does not have 10,000 Identities in its hibernate cache