Search in sources :

Example 1 with ProjectConfig

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;
}
Also used : ProjectConfig(org.eclipse.persistence.internal.sessions.factories.model.project.ProjectConfig) Project(org.eclipse.persistence.sessions.Project) DatabaseSessionImpl(org.eclipse.persistence.internal.sessions.DatabaseSessionImpl)

Example 2 with ProjectConfig

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);
}
Also used : DynamicClassLoader(org.eclipse.persistence.dynamic.DynamicClassLoader) SessionConfigs(org.eclipse.persistence.internal.sessions.factories.model.SessionConfigs) XMLContext(org.eclipse.persistence.oxm.XMLContext) DatabaseSession(org.eclipse.persistence.sessions.DatabaseSession) SessionManager(org.eclipse.persistence.sessions.factories.SessionManager) SessionsFactory(org.eclipse.persistence.internal.sessions.factories.SessionsFactory) SessionConfig(org.eclipse.persistence.internal.sessions.factories.model.session.SessionConfig) Document(org.w3c.dom.Document) XMLSessionConfigProject_11_1_1(org.eclipse.persistence.internal.sessions.factories.XMLSessionConfigProject_11_1_1) ProjectConfig(org.eclipse.persistence.internal.sessions.factories.model.project.ProjectConfig) LoginConfig(org.eclipse.persistence.internal.sessions.factories.model.login.LoginConfig) DynamicClassLoader(org.eclipse.persistence.dynamic.DynamicClassLoader) XMLSessionConfigLoader(org.eclipse.persistence.sessions.factories.XMLSessionConfigLoader) XMLUnmarshaller(org.eclipse.persistence.oxm.XMLUnmarshaller) DynamicTypeBuilder(org.eclipse.persistence.dynamic.DynamicTypeBuilder) Map(java.util.Map) AbstractSession(org.eclipse.persistence.internal.sessions.AbstractSession) DatabaseSession(org.eclipse.persistence.sessions.DatabaseSession) AbstractSession(org.eclipse.persistence.internal.sessions.AbstractSession) Session(org.eclipse.persistence.sessions.Session)

Example 3 with ProjectConfig

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;
}
Also used : DatabaseSessionConfig(org.eclipse.persistence.internal.sessions.factories.model.session.DatabaseSessionConfig) ProjectConfig(org.eclipse.persistence.internal.sessions.factories.model.project.ProjectConfig) SessionConfigs(org.eclipse.persistence.internal.sessions.factories.model.SessionConfigs) CustomServerPlatformConfig(org.eclipse.persistence.internal.sessions.factories.model.platform.CustomServerPlatformConfig) DatabaseLoginConfig(org.eclipse.persistence.internal.sessions.factories.model.login.DatabaseLoginConfig) ServerSessionConfig(org.eclipse.persistence.internal.sessions.factories.model.session.ServerSessionConfig) LogConfig(org.eclipse.persistence.internal.sessions.factories.model.log.LogConfig)

Example 4 with ProjectConfig

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;
}
Also used : DatabaseSessionConfig(org.eclipse.persistence.internal.sessions.factories.model.session.DatabaseSessionConfig) ProjectConfig(org.eclipse.persistence.internal.sessions.factories.model.project.ProjectConfig) SessionConfigs(org.eclipse.persistence.internal.sessions.factories.model.SessionConfigs) CustomServerPlatformConfig(org.eclipse.persistence.internal.sessions.factories.model.platform.CustomServerPlatformConfig) DatabaseLoginConfig(org.eclipse.persistence.internal.sessions.factories.model.login.DatabaseLoginConfig) ServerSessionConfig(org.eclipse.persistence.internal.sessions.factories.model.session.ServerSessionConfig) LogConfig(org.eclipse.persistence.internal.sessions.factories.model.log.LogConfig)

Example 5 with ProjectConfig

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;
}
Also used : ProjectConfig(org.eclipse.persistence.internal.sessions.factories.model.project.ProjectConfig) SimpleXMLFormatProject(org.eclipse.persistence.internal.xr.sxf.SimpleXMLFormatProject) ProjectXMLConfig(org.eclipse.persistence.internal.sessions.factories.model.project.ProjectXMLConfig) ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) Collection(java.util.Collection) ProjectClassConfig(org.eclipse.persistence.internal.sessions.factories.model.project.ProjectClassConfig)

Aggregations

ProjectConfig (org.eclipse.persistence.internal.sessions.factories.model.project.ProjectConfig)8 SessionConfigs (org.eclipse.persistence.internal.sessions.factories.model.SessionConfigs)4 LogConfig (org.eclipse.persistence.internal.sessions.factories.model.log.LogConfig)4 DatabaseLoginConfig (org.eclipse.persistence.internal.sessions.factories.model.login.DatabaseLoginConfig)4 CustomServerPlatformConfig (org.eclipse.persistence.internal.sessions.factories.model.platform.CustomServerPlatformConfig)4 DatabaseSessionConfig (org.eclipse.persistence.internal.sessions.factories.model.session.DatabaseSessionConfig)4 ServerSessionConfig (org.eclipse.persistence.internal.sessions.factories.model.session.ServerSessionConfig)4 Collection (java.util.Collection)2 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)2 ProjectClassConfig (org.eclipse.persistence.internal.sessions.factories.model.project.ProjectClassConfig)2 ProjectXMLConfig (org.eclipse.persistence.internal.sessions.factories.model.project.ProjectXMLConfig)2 SimpleXMLFormatProject (org.eclipse.persistence.internal.xr.sxf.SimpleXMLFormatProject)2 Project (org.eclipse.persistence.sessions.Project)2 Map (java.util.Map)1 DynamicClassLoader (org.eclipse.persistence.dynamic.DynamicClassLoader)1 DynamicTypeBuilder (org.eclipse.persistence.dynamic.DynamicTypeBuilder)1 AbstractSession (org.eclipse.persistence.internal.sessions.AbstractSession)1 DatabaseSessionImpl (org.eclipse.persistence.internal.sessions.DatabaseSessionImpl)1 SessionsFactory (org.eclipse.persistence.internal.sessions.factories.SessionsFactory)1 XMLSessionConfigProject_11_1_1 (org.eclipse.persistence.internal.sessions.factories.XMLSessionConfigProject_11_1_1)1