* PUBLIC:
* Return the session by name, loading the configuration from the file
* specified in the loader, using the loading options provided on the loader.
*/
public AbstractSession getSession(XMLSessionConfigLoader loader) {
AbstractSession session = (AbstractSession)getSessions().get(loader.getSessionName());
boolean shouldRefreshSession = loader.shouldRefresh();
if (loader.shouldCheckClassLoader() && (session != null) && !session.getDatasourcePlatform().getConversionManager().getLoader().equals(loader.getClassLoader())) {
//bug 3766808 if a different classloader is being used then a reload of the session should
//be completed otherwise failures may occur
shouldRefreshSession = true;
}
if ((session == null) || shouldRefreshSession) {
// PERF: Avoid synchronization for normal get.
synchronized (this) {
// Must re-assert checks inside synchronization.
session = (AbstractSession)getSessions().get(loader.getSessionName());
if (loader.shouldCheckClassLoader() && (session != null) && !session.getDatasourcePlatform().getConversionManager().getLoader().equals(loader.getClassLoader())) {
//bug 3766808 if a different classloader is being used then a reload of the session should
//be completed otherwise failures may occur
shouldRefreshSession = true;
}
if ((session == null) || shouldRefreshSession) {
if (session != null) {
if (session.isDatabaseSession() && session.isConnected()) {
// Must handles errors from logout as session maybe hosed.
try {
((DatabaseSession)session).logout();
} catch (Throwable ignore) {
AbstractSessionLog.getLog().logThrowable(SessionLog.WARNING, ignore);
}
}
getSessions().remove(loader.getSessionName());
}
if (loader.load(this, loader.getClassLoader())) {
session = (AbstractSession)getSessions().get(loader.getSessionName());
}
}
}
}
// Connect the session if specified.
if (session == null) {
logAndThrowException(SessionLog.WARNING, ValidationException.noSessionFound(loader.getSessionName(), loader.getResourcePath()));
} else if (loader.shouldLogin() && !session.isConnected()) {
// PERF: Avoid synchronization for normal get.
synchronized (this) {
// Must re-assert checks inside synchronization.
if (loader.shouldLogin() && !session.isConnected()) {
((DatabaseSession)session).login();
}
}
}