//get the project from the cache
Project project = projectCacheAccessor.retrieveProject(predeployProperties, classLoaderToUse, session.getSessionLog());
if (project!=null) {
try {
DatabaseSessionImpl tempSession = (DatabaseSessionImpl)project.createServerSession();
tempSession.setName(this.sessionName);
tempSession.setSessionLog(session.getSessionLog());
tempSession.getSessionLog().setSession(tempSession);
if (this.staticWeaveInfo != null) {
tempSession.setLogLevel(this.staticWeaveInfo.getLogLevel());
}
tempSession.setProfiler(session.getProfiler());
tempSession.setRefreshMetadataListener(this);
session = tempSession;
// reusing the serverPlatform from the existing session would have been preferred,
// but its session is only set through the ServerPlatform constructor.
updateServerPlatform(predeployProperties, classLoaderToUse);
shouldBuildProject = false;
} catch (Exception e) {
//need a better exception here
throw new PersistenceException(e);
}
}
}
if (isSessionLoadedFromSessionsXML) {
if (this.compositeEmSetupImpl == null && this.staticWeaveInfo == null) {
JPAClassLoaderHolder privateClassLoaderHolder = session.getServerPlatform().getNewTempClassLoader(persistenceUnitInfo);
classLoaderToUse = privateClassLoaderHolder.getClassLoader();
} else {
classLoaderToUse = persistenceUnitInfo.getNewTempClassLoader();
}
// Loading session from sessions-xml.
String tempSessionName = sessionName;
if (isCompositeMember()) {
// composite member session name is always the same as puName
// need the session name specified in properties to read correct session from sessions.xml
tempSessionName = (String)predeployProperties.get(PersistenceUnitProperties.SESSION_NAME);
}
session.log(SessionLog.FINEST, SessionLog.PROPERTIES, "loading_session_xml", sessionsXMLStr, tempSessionName);
if (tempSessionName == null) {
throw EntityManagerSetupException.sessionNameNeedBeSpecified(persistenceUnitInfo.getPersistenceUnitName(), sessionsXMLStr);
}
XMLSessionConfigLoader xmlLoader = new XMLSessionConfigLoader(sessionsXMLStr);
// Do not register the session with the SessionManager at this point, create temporary session using a local SessionManager and private class loader.
// This allows for the project to be accessed without loading any of the classes to allow weaving.
// Note that this method assigns sessionName to session.
Session tempSession = new SessionManager().getSession(xmlLoader, tempSessionName, classLoaderToUse, false, false);
// Load path of sessions-xml resource before throwing error so user knows which sessions-xml file was found (may be multiple).
session.log(SessionLog.FINEST, SessionLog.PROPERTIES, "sessions_xml_path_where_session_load_from", xmlLoader.getSessionName(), xmlLoader.getResourcePath());
if (tempSession == null) {
throw ValidationException.noSessionFound(sessionName, sessionsXMLStr);
}
// Currently the session must be either a ServerSession or a SessionBroker, cannot be just a DatabaseSessionImpl.
if (tempSession.isServerSession() || tempSession.isSessionBroker()) {
session = (DatabaseSessionImpl) tempSession;
if (tempSessionName != sessionName) {
// set back the original session name
session.setName(sessionName);
}