Search in sources :

Example 11 with XMLLogin

use of org.eclipse.persistence.oxm.XMLLogin in project eclipselink by eclipse-ee4j.

the class XMLLoginDeploymentXMLTestCases method testDocumentPreservationPolicy.

// Bug - test 'DocumentPreservationPolicy' in project.xml
public void testDocumentPreservationPolicy() {
    Project roundTrippedProject;
    XMLLogin roundTrippedLogin;
    // DocumentPreservationPolicy = DescriptorLevelDocumentPreservationPolicy
    // NodeOrderingPolicy = AppendNewElementsOrderingPolicy
    // ======================================================================
    m_login.setDocumentPreservationPolicy(new DescriptorLevelDocumentPreservationPolicy());
    m_login.getDocumentPreservationPolicy().setNodeOrderingPolicy(new AppendNewElementsOrderingPolicy());
    roundTrippedProject = writeAndReadProject();
    roundTrippedLogin = (XMLLogin) roundTrippedProject.getDatasourceLogin();
    assertEquals(m_login.getDocumentPreservationPolicy().getClass(), roundTrippedLogin.getDocumentPreservationPolicy().getClass());
    assertEquals(m_login.getDocumentPreservationPolicy().getNodeOrderingPolicy().getClass(), roundTrippedLogin.getDocumentPreservationPolicy().getNodeOrderingPolicy().getClass());
    // NodeOrderingPolicy = IgnoreNewElementsOrderingPolicy
    // DocumentPreservationPolicy = NoDocumentPreservationPolicy
    // =========================================================
    m_login.setDocumentPreservationPolicy(new NoDocumentPreservationPolicy());
    m_login.getDocumentPreservationPolicy().setNodeOrderingPolicy(new IgnoreNewElementsOrderingPolicy());
    roundTrippedProject = writeAndReadProject();
    roundTrippedLogin = (XMLLogin) roundTrippedProject.getDatasourceLogin();
    assertEquals(m_login.getDocumentPreservationPolicy().getClass(), roundTrippedLogin.getDocumentPreservationPolicy().getClass());
    assertEquals(m_login.getDocumentPreservationPolicy().getNodeOrderingPolicy().getClass(), roundTrippedLogin.getDocumentPreservationPolicy().getNodeOrderingPolicy().getClass());
    // DocumentPreservationPolicy = XMLBinderPolicy
    // NodeOrderingPolicy = RelativePositionOrderingPolicy
    // ===================================================
    m_login.setDocumentPreservationPolicy(new XMLBinderPolicy());
    m_login.getDocumentPreservationPolicy().setNodeOrderingPolicy(new RelativePositionOrderingPolicy());
    roundTrippedProject = writeAndReadProject();
    roundTrippedLogin = (XMLLogin) roundTrippedProject.getDatasourceLogin();
    assertEquals(m_login.getDocumentPreservationPolicy().getClass(), roundTrippedLogin.getDocumentPreservationPolicy().getClass());
    assertEquals(m_login.getDocumentPreservationPolicy().getNodeOrderingPolicy().getClass(), roundTrippedLogin.getDocumentPreservationPolicy().getNodeOrderingPolicy().getClass());
}
Also used : Project(org.eclipse.persistence.sessions.Project) AppendNewElementsOrderingPolicy(org.eclipse.persistence.oxm.documentpreservation.AppendNewElementsOrderingPolicy) IgnoreNewElementsOrderingPolicy(org.eclipse.persistence.oxm.documentpreservation.IgnoreNewElementsOrderingPolicy) XMLLogin(org.eclipse.persistence.oxm.XMLLogin) XMLBinderPolicy(org.eclipse.persistence.internal.oxm.documentpreservation.XMLBinderPolicy) RelativePositionOrderingPolicy(org.eclipse.persistence.oxm.documentpreservation.RelativePositionOrderingPolicy) NoDocumentPreservationPolicy(org.eclipse.persistence.internal.oxm.documentpreservation.NoDocumentPreservationPolicy) DescriptorLevelDocumentPreservationPolicy(org.eclipse.persistence.internal.oxm.documentpreservation.DescriptorLevelDocumentPreservationPolicy)

Example 12 with XMLLogin

use of org.eclipse.persistence.oxm.XMLLogin in project eclipselink by eclipse-ee4j.

the class XMLLoginDeploymentXMLTestCases method testDataSourcePlatform.

// Bug 242452 - test 'DatasourcePlatform' in project.xml
public void testDataSourcePlatform() {
    Project roundTrippedProject;
    XMLLogin roundTrippedLogin;
    // DatasourcePlatform = SAXPlatform
    // ================================
    m_login.setDatasourcePlatform(new SAXPlatform());
    roundTrippedProject = writeAndReadProject();
    roundTrippedLogin = (XMLLogin) roundTrippedProject.getDatasourceLogin();
    assertEquals(m_login.getDatasourcePlatform().getClass(), roundTrippedLogin.getDatasourcePlatform().getClass());
    // DatasourcePlatform = DOMPlatform
    // ================================
    m_login.setDatasourcePlatform(new DOMPlatform());
    roundTrippedProject = writeAndReadProject();
    roundTrippedLogin = (XMLLogin) roundTrippedProject.getDatasourceLogin();
    assertEquals(m_login.getDatasourcePlatform().getClass(), roundTrippedLogin.getDatasourcePlatform().getClass());
}
Also used : Project(org.eclipse.persistence.sessions.Project) DOMPlatform(org.eclipse.persistence.oxm.platform.DOMPlatform) SAXPlatform(org.eclipse.persistence.oxm.platform.SAXPlatform) XMLLogin(org.eclipse.persistence.oxm.XMLLogin)

Example 13 with XMLLogin

use of org.eclipse.persistence.oxm.XMLLogin in project eclipselink by eclipse-ee4j.

the class GenerateSchemaTestCases method loginProject.

/**
 * Login the session to ensure that the descriptors are initialized.
 */
protected void loginProject(Project prj) {
    XMLPlatform<XMLUnmarshaller> platform = new SAXPlatform();
    prj.setLogin(new XMLLogin(platform));
    DatabaseSession session = prj.createDatabaseSession();
    session.setLogLevel(SessionLog.OFF);
    for (Iterator<ClassDescriptor> descriptorIt = prj.getOrderedDescriptors().iterator(); descriptorIt.hasNext(); ) {
        ClassDescriptor descriptor = descriptorIt.next();
        if (descriptor.getJavaClass() == null) {
            descriptor.setJavaClass(session.getDatasourcePlatform().getConversionManager().convertClassNameToClass(descriptor.getJavaClassName()));
        }
    }
    session.login();
}
Also used : SAXPlatform(org.eclipse.persistence.oxm.platform.SAXPlatform) ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) DatabaseSession(org.eclipse.persistence.sessions.DatabaseSession) XMLLogin(org.eclipse.persistence.oxm.XMLLogin) XMLUnmarshaller(org.eclipse.persistence.internal.oxm.XMLUnmarshaller)

Example 14 with XMLLogin

use of org.eclipse.persistence.oxm.XMLLogin in project eclipselink by eclipse-ee4j.

the class XRServiceFactory method buildSessions.

/**
 * <p>INTERNAL:
 */
@SuppressWarnings("rawtypes")
public void buildSessions() {
    XRDynamicClassLoader projectLoader = new XRDynamicClassLoader(parentClassLoader);
    SessionManager sessionManager = SessionManager.getManager();
    boolean found = false;
    String sessionsFile = xrService.sessionsFile == null ? DBWS_SESSIONS_XML : xrService.sessionsFile;
    for (String prefix : META_INF_PATHS) {
        String searchPath = prefix + sessionsFile;
        XRSessionConfigLoader loader = new XRSessionConfigLoader(searchPath);
        loader.setShouldLogin(false);
        try {
            found = loader.load(sessionManager, projectLoader);
        } catch (RuntimeException e) {
        /* ignore */
        }
        if (found) {
            break;
        }
    }
    if (!found) {
        throw DBWSException.couldNotLocateFile(DBWS_SESSIONS_XML);
    }
    // make sure the OR/OX sessions were loaded successfully
    Map sessions = sessionManager.getSessions();
    String orSessionKey = xrService.name + DASH_STR + DBWS_OR_SESSION_NAME_SUFFIX;
    if (!sessions.containsKey(orSessionKey)) {
        throw DBWSException.couldNotLocateORSessionForService(xrService.name);
    }
    String oxSessionKey = xrService.name + DASH_STR + DBWS_OX_SESSION_NAME_SUFFIX;
    if (!sessions.containsKey(oxSessionKey)) {
        throw DBWSException.couldNotLocateOXSessionForService(xrService.name);
    }
    xrService.orSession = (Session) sessions.get(orSessionKey);
    xrService.oxSession = (Session) sessions.get(oxSessionKey);
    // load OX project via xml-bindings
    Project oxProject;
    if ((oxProject = loadOXMetadata(projectLoader, xrService.oxSession)) == null) {
        // at this point we may have a legacy deployment XML project, or none set
        oxProject = xrService.oxSession.getProject();
        // check to see if it's a default Project
        if (oxProject.getName().length() == 0) {
            // default to SimpleXMLFormat
            oxProject = new SimpleXMLFormatProject();
        }
    }
    ((XMLLogin) oxProject.getDatasourceLogin()).setPlatformClassName(DOM_PLATFORM_CLASSNAME);
    ((XMLLogin) oxProject.getDatasourceLogin()).setEqualNamespaceResolvers(false);
    // load OR project via entity-mappings
    Project orProject;
    if ((orProject = loadORMetadata(projectLoader, (ServerSession) xrService.orSession)) == null) {
        // at this point we may have a legacy deployment XML project, or none set
        orProject = xrService.orSession.getProject();
        updateFindQueryNames(orProject);
    }
    prepareDescriptors(oxProject, orProject, projectLoader);
    ProjectHelper.fixOROXAccessors(orProject, oxProject);
    xrService.xmlContext = new XMLContext(oxProject);
    xrService.oxSession = xrService.xmlContext.getSession(0);
}
Also used : SimpleXMLFormatProject(org.eclipse.persistence.internal.xr.sxf.SimpleXMLFormatProject) Project(org.eclipse.persistence.sessions.Project) SchemaModelProject(org.eclipse.persistence.internal.oxm.schema.SchemaModelProject) SimpleXMLFormatProject(org.eclipse.persistence.internal.xr.sxf.SimpleXMLFormatProject) ServerSession(org.eclipse.persistence.sessions.server.ServerSession) XMLContext(org.eclipse.persistence.oxm.XMLContext) SessionManager(org.eclipse.persistence.sessions.factories.SessionManager) XMLLogin(org.eclipse.persistence.oxm.XMLLogin) Map(java.util.Map) HashMap(java.util.HashMap)

Example 15 with XMLLogin

use of org.eclipse.persistence.oxm.XMLLogin in project eclipselink by eclipse-ee4j.

the class XRSessionsFactory method loadProjectConfig.

@Override
protected Project loadProjectConfig(ProjectConfig projectConfig) {
    Project project = null;
    String projectString = projectConfig.getProjectString();
    if (projectConfig.isProjectClassConfig()) {
        try {
            if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()) {
                project = (Project) AccessController.doPrivileged(new PrivilegedNewInstanceFromClass<>(m_classLoader.loadClass(projectString)));
            } else {
                project = (Project) PrivilegedAccessHelper.newInstanceFromClass(m_classLoader.loadClass(projectString));
            }
        } catch (Throwable exception) {
            throw SessionLoaderException.failedToLoadProjectClass(projectString, exception);
        }
    } else {
        try {
            URL url = null;
            Matcher matcher = matchDBWSOrProject.matcher(projectString);
            if (matcher.find()) {
                // need to try a variety of URLs to find DBWS OR/OX Project
                String orXml = matcher.group();
                for (String prefix : META_INF_PATHS) {
                    String searchPath = prefix + orXml;
                    url = m_classLoader.getResource(searchPath);
                    if (url != null) {
                        break;
                    }
                }
            } else {
                matcher = matchDBWSOxProject.matcher(projectString);
                if (matcher.find()) {
                    String oxXml = matcher.group();
                    for (String prefix : META_INF_PATHS) {
                        String searchPath = prefix + oxXml;
                        url = m_classLoader.getResource(searchPath);
                        if (url != null) {
                            break;
                        }
                    }
                }
            }
            if (url != null) {
                Project p = new EclipseLinkObjectPersistenceRuntimeXMLProject();
                XMLLogin xmlLogin = new XMLLogin();
                xmlLogin.setDatasourcePlatform(new DOMPlatform());
                p.setDatasourceLogin(xmlLogin);
                if (m_classLoader != null) {
                    p.getDatasourceLogin().getDatasourcePlatform().getConversionManager().setLoader(m_classLoader);
                }
                XMLPlatform xmlPlatform = XMLPlatformFactory.getInstance().getXMLPlatform();
                XMLParser parser = xmlPlatform.newXMLParser();
                parser.setNamespaceAware(true);
                parser.setWhitespacePreserving(false);
                XMLContext context = new XMLContext(p);
                context.getSession(Project.class).getEventManager().addListener(new MissingDescriptorListener());
                XMLUnmarshaller unmarshaller = context.createUnmarshaller();
                project = (Project) unmarshaller.unmarshal(url);
            }
        } catch (ValidationException validationException) {
            if (validationException.getErrorCode() == ValidationException.PROJECT_XML_NOT_FOUND) {
                throw SessionLoaderException.failedToLoadProjectXml(projectString, validationException);
            } else {
                throw SessionLoaderException.failedToParseXML(projectString, validationException);
            }
        }
    }
    return project;
}
Also used : DOMPlatform(org.eclipse.persistence.oxm.platform.DOMPlatform) ValidationException(org.eclipse.persistence.exceptions.ValidationException) Matcher(java.util.regex.Matcher) XMLContext(org.eclipse.persistence.oxm.XMLContext) XMLLogin(org.eclipse.persistence.oxm.XMLLogin) MissingDescriptorListener(org.eclipse.persistence.internal.sessions.factories.MissingDescriptorListener) URL(java.net.URL) Project(org.eclipse.persistence.sessions.Project) EclipseLinkObjectPersistenceRuntimeXMLProject(org.eclipse.persistence.internal.sessions.factories.EclipseLinkObjectPersistenceRuntimeXMLProject) XMLPlatform(org.eclipse.persistence.platform.xml.XMLPlatform) EclipseLinkObjectPersistenceRuntimeXMLProject(org.eclipse.persistence.internal.sessions.factories.EclipseLinkObjectPersistenceRuntimeXMLProject) XMLUnmarshaller(org.eclipse.persistence.oxm.XMLUnmarshaller) XMLParser(org.eclipse.persistence.platform.xml.XMLParser)

Aggregations

XMLLogin (org.eclipse.persistence.oxm.XMLLogin)29 Project (org.eclipse.persistence.sessions.Project)25 XMLContext (org.eclipse.persistence.oxm.XMLContext)17 DatabaseSession (org.eclipse.persistence.sessions.DatabaseSession)13 StringReader (java.io.StringReader)11 DatabaseLogin (org.eclipse.persistence.sessions.DatabaseLogin)10 HashMap (java.util.HashMap)9 Map (java.util.Map)9 XMLUnmarshaller (org.eclipse.persistence.oxm.XMLUnmarshaller)9 DOMPlatform (org.eclipse.persistence.oxm.platform.DOMPlatform)9 XRDynamicClassLoader (org.eclipse.persistence.internal.xr.XRDynamicClassLoader)8 XMLPlatform (org.eclipse.persistence.platform.xml.XMLPlatform)8 JAXBContext (jakarta.xml.bind.JAXBContext)7 JAXBException (jakarta.xml.bind.JAXBException)7 Unmarshaller (jakarta.xml.bind.Unmarshaller)7 StreamSource (javax.xml.transform.stream.StreamSource)7 Platform (org.eclipse.persistence.internal.databaseaccess.Platform)7 ConversionManager (org.eclipse.persistence.internal.helper.ConversionManager)7 MetadataProcessor (org.eclipse.persistence.internal.jpa.metadata.MetadataProcessor)7 DatabaseSessionImpl (org.eclipse.persistence.internal.sessions.DatabaseSessionImpl)7