use of org.eclipse.persistence.internal.sessions.factories.model.project.ProjectConfig in project eclipselink by eclipse-ee4j.
the class SessionsFactory method createSession.
/**
* INTERNAL:
* Return a DatabaseSession object from it's config object using either
* the project classes or project XML files.
*/
protected DatabaseSessionImpl createSession(DatabaseSessionConfig sessionConfig, Login login) {
Project primaryProject;
if (sessionConfig.getPrimaryProject() != null) {
primaryProject = loadProjectConfig(sessionConfig.getPrimaryProject());
} else {
// Build a session from an empty project
primaryProject = new Project();
}
prepareProjectLogin(primaryProject, login);
DatabaseSessionImpl sessionToReturn = getSession(sessionConfig, primaryProject);
// to the mainProject
if (sessionConfig.getAdditionalProjects() != null) {
Enumeration<ProjectConfig> additionalProjects = sessionConfig.getAdditionalProjects().elements();
while (additionalProjects.hasMoreElements()) {
Project subProject = loadProjectConfig(additionalProjects.nextElement());
primaryProject.addDescriptors(subProject, sessionToReturn);
}
}
return sessionToReturn;
}
use of org.eclipse.persistence.internal.sessions.factories.model.project.ProjectConfig in project eclipselink by eclipse-ee4j.
the class ComicsConfigTestSuite method buildComicsSession.
public static DatabaseSession buildComicsSession() {
DynamicClassLoader dcl = new DynamicClassLoader(ComicsConfigTestSuite.class.getClassLoader());
new DynamicTypeBuilder(dcl.createDynamicClass("model.Issue"), null);
new DynamicTypeBuilder(dcl.createDynamicClass("model.Publisher"), null);
new DynamicTypeBuilder(dcl.createDynamicClass("model.Title"), null);
XMLSessionConfigLoader loader = new XMLSessionConfigLoader(COMICS_SESSION_XML) {
@Override
@SuppressWarnings("unchecked")
public boolean load(SessionManager sessionManager, ClassLoader loader) {
Document document = loadDocument(loader);
if (getExceptionStore().isEmpty()) {
if (document.getDocumentElement().getTagName().equals("sessions")) {
XMLContext context = new XMLContext(new XMLSessionConfigProject_11_1_1());
XMLUnmarshaller unmarshaller = context.createUnmarshaller();
SessionConfigs configs = (SessionConfigs) unmarshaller.unmarshal(document);
SessionsFactory factory = new SessionsFactory() {
@Override
protected Project loadProjectConfig(ProjectConfig projectConfig) {
if (projectConfig.isProjectXMLConfig()) {
projectConfig.setProjectString(PACKAGE_PATH + "/" + projectConfig.getProjectString());
}
return super.loadProjectConfig(projectConfig);
}
@Override
protected Login buildLogin(LoginConfig loginConfig) {
return createLogin();
}
@Override
protected AbstractSession buildSession(SessionConfig sessionConfig) {
AbstractSession s = super.buildSession(sessionConfig);
if (SessionLog.OFF == logLevel) {
s.dontLogMessages();
} else {
s.setLogLevel(logLevel);
}
return s;
}
};
Map<String, Session> sessions = factory.buildSessionConfigs(configs, loader);
for (Map.Entry<String, Session> entry : sessions.entrySet()) {
if (!sessionManager.getSessions().containsKey(entry.getKey())) {
sessionManager.addSession(entry.getKey(), entry.getValue());
}
}
return true;
}
}
return false;
}
};
loader.setClassLoader(dcl);
loader.setSessionName(COMICS_SESSION_NAME);
return (DatabaseSession) SessionManager.getManager().getSession(loader);
}
use of org.eclipse.persistence.internal.sessions.factories.model.project.ProjectConfig in project eclipselink by eclipse-ee4j.
the class GlassfishPackager method buildSessionsXML.
@Override
public SessionConfigs buildSessionsXML(OutputStream dbwsSessionsStream, DBWSBuilder builder) {
SessionConfigs ts = super.buildSessionsXML(dbwsSessionsStream, builder);
String dataSource = builder.getDataSource();
if (dataSource != null) {
DatabaseSessionConfig tmpConfig = (DatabaseSessionConfig) ts.getSessionConfigs().firstElement();
ProjectConfig orProject = tmpConfig.getPrimaryProject();
LogConfig logConfig = tmpConfig.getLogConfig();
String sessionName = tmpConfig.getName();
DatabaseSessionConfig orSessionConfig = new ServerSessionConfig();
orSessionConfig.setPrimaryProject(orProject);
orSessionConfig.setName(sessionName);
orSessionConfig.setLogConfig(logConfig);
CustomServerPlatformConfig customServerPlatformConfig = new CustomServerPlatformConfig();
customServerPlatformConfig.setEnableJTA(true);
customServerPlatformConfig.setEnableRuntimeServices(true);
customServerPlatformConfig.setServerClassName("org.eclipse.persistence.platform.server.sunas.SunAS9ServerPlatform");
customServerPlatformConfig.setExternalTransactionControllerClass("org.eclipse.persistence.transaction.sunas.SunAS9TransactionController");
orSessionConfig.setServerPlatformConfig(customServerPlatformConfig);
DatabaseLoginConfig dlc = new DatabaseLoginConfig();
dlc.setPlatformClass(builder.getPlatformClassname());
dlc.setExternalConnectionPooling(true);
dlc.setExternalTransactionController(true);
dlc.setDatasource(dataSource);
dlc.setBindAllParameters(true);
dlc.setStreamsForBinding(true);
orSessionConfig.setLoginConfig(dlc);
ts.getSessionConfigs().set(0, orSessionConfig);
}
return ts;
}
use of org.eclipse.persistence.internal.sessions.factories.model.project.ProjectConfig in project eclipselink by eclipse-ee4j.
the class JBossPackager method buildSessionsXML.
@Override
public SessionConfigs buildSessionsXML(OutputStream dbwsSessionsStream, DBWSBuilder builder) {
SessionConfigs ts = super.buildSessionsXML(dbwsSessionsStream, builder);
String dataSource = builder.getDataSource();
if (dataSource != null) {
DatabaseSessionConfig tmpConfig = (DatabaseSessionConfig) ts.getSessionConfigs().firstElement();
ProjectConfig orProject = tmpConfig.getPrimaryProject();
LogConfig logConfig = tmpConfig.getLogConfig();
String sessionName = tmpConfig.getName();
DatabaseSessionConfig orSessionConfig = new ServerSessionConfig();
orSessionConfig.setPrimaryProject(orProject);
orSessionConfig.setName(sessionName);
orSessionConfig.setLogConfig(logConfig);
CustomServerPlatformConfig customServerPlatformConfig = new CustomServerPlatformConfig();
customServerPlatformConfig.setEnableJTA(true);
customServerPlatformConfig.setEnableRuntimeServices(true);
customServerPlatformConfig.setServerClassName("org.eclipse.persistence.platform.server.jboss.JBossPlatform");
customServerPlatformConfig.setExternalTransactionControllerClass("org.eclipse.persistence.transaction.jboss.JBossTransactionController");
orSessionConfig.setServerPlatformConfig(customServerPlatformConfig);
DatabaseLoginConfig dlc = new DatabaseLoginConfig();
dlc.setPlatformClass(builder.getPlatformClassname());
dlc.setExternalConnectionPooling(true);
dlc.setExternalTransactionController(true);
dlc.setDatasource(dataSource);
dlc.setLookupType(JNDIConnector.STRING_LOOKUP);
dlc.setBindAllParameters(true);
dlc.setStreamsForBinding(true);
orSessionConfig.setLoginConfig(dlc);
ts.getSessionConfigs().set(0, orSessionConfig);
}
return ts;
}
use of org.eclipse.persistence.internal.sessions.factories.model.project.ProjectConfig in project eclipselink by eclipse-ee4j.
the class DBWSBuilder method buildOXProjectConfig.
protected ProjectConfig buildOXProjectConfig() {
ProjectConfig oxProjectConfig = null;
boolean useProjectXML = false;
if (builderHelper.hasTables() || hasBuildSqlOperations()) {
useProjectXML = true;
}
if (!useProjectXML) {
// check for any named queries - SimpleXMLFormatProject's sometimes need them
if (orProject.getQueries().size() > 0) {
useProjectXML = true;
} else // check for ObjectRelationalDataTypeDescriptor's - Advanced JDBC object/varray types
if (orProject.getDescriptors().size() > 0) {
Collection<ClassDescriptor> descriptors = orProject.getDescriptors().values();
for (ClassDescriptor desc : descriptors) {
if (desc.isObjectRelationalDataTypeDescriptor()) {
useProjectXML = true;
break;
}
}
}
}
if (useProjectXML) {
oxProjectConfig = new ProjectXMLConfig();
String pathPrefix = packager.getOxProjectPathPrefix();
oxProjectConfig.setProjectString(pathPrefix == null ? DBWS_OX_XML : pathPrefix + DBWS_OX_XML);
} else {
oxProjectConfig = new ProjectClassConfig();
oxProjectConfig.setProjectString(SimpleXMLFormatProject.class.getName());
}
return oxProjectConfig;
}
Aggregations