Search in sources :

Example 1 with Platform

use of org.eclipse.persistence.internal.databaseaccess.Platform in project eclipselink by eclipse-ee4j.

the class SQLAsCollectionTestSuite method buildSessions.

@Override
public void buildSessions() {
    XRDynamicClassLoader xrdecl = new XRDynamicClassLoader(parentClassLoader);
    DatasourceLogin login = new DatabaseLogin();
    login.setUserName(username);
    login.setPassword(password);
    ((DatabaseLogin) login).setConnectionString(url);
    ((DatabaseLogin) login).setDriverClassName(DATABASE_PLATFORM);
    Platform platform = builder.getDatabasePlatform();
    ConversionManager conversionManager = platform.getConversionManager();
    if (conversionManager != null) {
        conversionManager.setLoader(xrdecl);
    }
    login.setDatasourcePlatform(platform);
    ((DatabaseLogin) login).bindAllParameters();
    ((DatabaseLogin) login).setUsesStreamsForBinding(true);
    Project orProject = null;
    if (DBWS_OR_STREAM.size() != 0) {
        MetadataProcessor processor = new MetadataProcessor(new XRPersistenceUnitInfo(xrdecl), new DatabaseSessionImpl(login), xrdecl, false, true, false, false, false, null, null);
        processor.setMetadataSource(new JPAMetadataSource(xrdecl, new StringReader(DBWS_OR_STREAM.toString())));
        PersistenceUnitProcessor.processORMetadata(processor, true, PersistenceUnitProcessor.Mode.ALL);
        processor.addNamedQueries();
        orProject = processor.getProject().getProject();
    } else {
        orProject = new Project();
    }
    orProject.setName(builder.getProjectName().concat(OR_PRJ_SUFFIX));
    orProject.setDatasourceLogin(login);
    DatabaseSession databaseSession = orProject.createDatabaseSession();
    if ("off".equalsIgnoreCase(builder.getLogLevel())) {
        databaseSession.dontLogMessages();
    } else {
        databaseSession.setLogLevel(AbstractSessionLog.translateStringToLoggingLevel(builder.getLogLevel()));
    }
    xrService.setORSession(databaseSession);
    orProject.convertClassNamesToClasses(xrdecl);
    Project oxProject = null;
    Map<String, OXMMetadataSource> metadataMap = new HashMap<String, OXMMetadataSource>();
    StreamSource xml = new StreamSource(new StringReader(DBWS_OX_STREAM.toString()));
    try {
        JAXBContext jc = JAXBContext.newInstance(XmlBindingsModel.class);
        Unmarshaller unmarshaller = jc.createUnmarshaller();
        JAXBElement<XmlBindingsModel> jaxbElt = unmarshaller.unmarshal(xml, XmlBindingsModel.class);
        XmlBindingsModel model = jaxbElt.getValue();
        for (XmlBindings xmlBindings : model.getBindingsList()) {
            metadataMap.put(xmlBindings.getPackageName(), new OXMMetadataSource(xmlBindings));
        }
    } catch (JAXBException jaxbex) {
        jaxbex.printStackTrace();
    }
    Map<String, Map<String, OXMMetadataSource>> properties = new HashMap<String, Map<String, OXMMetadataSource>>();
    properties.put(JAXBContextProperties.OXM_METADATA_SOURCE, metadataMap);
    try {
        org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext jCtx = org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContextFactory.createContextFromOXM(parentClassLoader, properties);
        oxProject = jCtx.getXMLContext().getSession(0).getProject();
    } catch (JAXBException e) {
        e.printStackTrace();
    }
    ((XMLLogin) oxProject.getDatasourceLogin()).setPlatformClassName(DOM_PLATFORM_CLASSNAME);
    ((XMLLogin) oxProject.getDatasourceLogin()).setEqualNamespaceResolvers(false);
    prepareDescriptors(oxProject, orProject, xrdecl);
    ProjectHelper.fixOROXAccessors(orProject, oxProject);
    xrService.setORSession(databaseSession);
    xrService.setXMLContext(new XMLContext(oxProject));
    xrService.setOXSession(xrService.getXMLContext().getSession(0));
}
Also used : XmlBindings(org.eclipse.persistence.jaxb.xmlmodel.XmlBindings) Platform(org.eclipse.persistence.internal.databaseaccess.Platform) XMLPlatform(org.eclipse.persistence.platform.xml.XMLPlatform) DatabaseSession(org.eclipse.persistence.sessions.DatabaseSession) HashMap(java.util.HashMap) XRDynamicClassLoader(org.eclipse.persistence.internal.xr.XRDynamicClassLoader) XMLLogin(org.eclipse.persistence.oxm.XMLLogin) JAXBContext(jakarta.xml.bind.JAXBContext) DBWSTestSuite.documentToString(dbws.testing.DBWSTestSuite.documentToString) StringReader(java.io.StringReader) ConversionManager(org.eclipse.persistence.internal.helper.ConversionManager) XmlBindingsModel(org.eclipse.persistence.internal.xr.XmlBindingsModel) Unmarshaller(jakarta.xml.bind.Unmarshaller) XMLUnmarshaller(org.eclipse.persistence.oxm.XMLUnmarshaller) DatasourceLogin(org.eclipse.persistence.sessions.DatasourceLogin) XMLContext(org.eclipse.persistence.oxm.XMLContext) StreamSource(javax.xml.transform.stream.StreamSource) JAXBException(jakarta.xml.bind.JAXBException) DatabaseLogin(org.eclipse.persistence.sessions.DatabaseLogin) Project(org.eclipse.persistence.sessions.Project) DBWSBuilderModelProject(org.eclipse.persistence.tools.dbws.DBWSBuilderModelProject) DatabaseSessionImpl(org.eclipse.persistence.internal.sessions.DatabaseSessionImpl) MetadataProcessor(org.eclipse.persistence.internal.jpa.metadata.MetadataProcessor) Map(java.util.Map) HashMap(java.util.HashMap)

Example 2 with Platform

use of org.eclipse.persistence.internal.databaseaccess.Platform in project eclipselink by eclipse-ee4j.

the class SecondarySQLTestSuite method buildSessions.

@Override
public void buildSessions() {
    XRDynamicClassLoader xrdecl = new XRDynamicClassLoader(parentClassLoader);
    DatasourceLogin login = new DatabaseLogin();
    login.setUserName(username);
    login.setPassword(password);
    ((DatabaseLogin) login).setConnectionString(url);
    ((DatabaseLogin) login).setDriverClassName(DATABASE_PLATFORM);
    Platform platform = builder.getDatabasePlatform();
    ConversionManager conversionManager = platform.getConversionManager();
    if (conversionManager != null) {
        conversionManager.setLoader(xrdecl);
    }
    login.setDatasourcePlatform(platform);
    ((DatabaseLogin) login).bindAllParameters();
    ((DatabaseLogin) login).setUsesStreamsForBinding(true);
    Project orProject = null;
    if (DBWS_OR_STREAM.size() != 0) {
        MetadataProcessor processor = new MetadataProcessor(new XRPersistenceUnitInfo(xrdecl), new DatabaseSessionImpl(login), xrdecl, false, true, false, false, false, null, null);
        processor.setMetadataSource(new JPAMetadataSource(xrdecl, new StringReader(DBWS_OR_STREAM.toString())));
        PersistenceUnitProcessor.processORMetadata(processor, true, PersistenceUnitProcessor.Mode.ALL);
        processor.addNamedQueries();
        orProject = processor.getProject().getProject();
    } else {
        orProject = new Project();
    }
    orProject.setName(builder.getProjectName().concat(OR_PRJ_SUFFIX));
    orProject.setDatasourceLogin(login);
    DatabaseSession databaseSession = orProject.createDatabaseSession();
    if ("off".equalsIgnoreCase(builder.getLogLevel())) {
        databaseSession.dontLogMessages();
    } else {
        databaseSession.setLogLevel(AbstractSessionLog.translateStringToLoggingLevel(builder.getLogLevel()));
    }
    xrService.setORSession(databaseSession);
    orProject.convertClassNamesToClasses(xrdecl);
    Project oxProject = null;
    Map<String, OXMMetadataSource> metadataMap = new HashMap<String, OXMMetadataSource>();
    StreamSource xml = new StreamSource(new StringReader(DBWS_OX_STREAM.toString()));
    try {
        JAXBContext jc = JAXBContext.newInstance(XmlBindingsModel.class);
        Unmarshaller unmarshaller = jc.createUnmarshaller();
        JAXBElement<XmlBindingsModel> jaxbElt = unmarshaller.unmarshal(xml, XmlBindingsModel.class);
        XmlBindingsModel model = jaxbElt.getValue();
        for (XmlBindings xmlBindings : model.getBindingsList()) {
            metadataMap.put(xmlBindings.getPackageName(), new OXMMetadataSource(xmlBindings));
        }
    } catch (JAXBException jaxbex) {
        jaxbex.printStackTrace();
    }
    Map<String, Map<String, OXMMetadataSource>> properties = new HashMap<String, Map<String, OXMMetadataSource>>();
    properties.put(JAXBContextProperties.OXM_METADATA_SOURCE, metadataMap);
    try {
        org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext jCtx = org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContextFactory.createContextFromOXM(parentClassLoader, properties);
        oxProject = jCtx.getXMLContext().getSession(0).getProject();
    } catch (JAXBException e) {
        e.printStackTrace();
    }
    ((XMLLogin) oxProject.getDatasourceLogin()).setPlatformClassName(DOM_PLATFORM_CLASSNAME);
    ((XMLLogin) oxProject.getDatasourceLogin()).setEqualNamespaceResolvers(false);
    prepareDescriptors(oxProject, orProject, xrdecl);
    ProjectHelper.fixOROXAccessors(orProject, oxProject);
    xrService.setORSession(databaseSession);
    xrService.setXMLContext(new XMLContext(oxProject));
    xrService.setOXSession(xrService.getXMLContext().getSession(0));
}
Also used : XmlBindings(org.eclipse.persistence.jaxb.xmlmodel.XmlBindings) Platform(org.eclipse.persistence.internal.databaseaccess.Platform) XMLPlatform(org.eclipse.persistence.platform.xml.XMLPlatform) DatabaseSession(org.eclipse.persistence.sessions.DatabaseSession) HashMap(java.util.HashMap) XRDynamicClassLoader(org.eclipse.persistence.internal.xr.XRDynamicClassLoader) XMLLogin(org.eclipse.persistence.oxm.XMLLogin) JAXBContext(jakarta.xml.bind.JAXBContext) StringReader(java.io.StringReader) ConversionManager(org.eclipse.persistence.internal.helper.ConversionManager) XmlBindingsModel(org.eclipse.persistence.internal.xr.XmlBindingsModel) Unmarshaller(jakarta.xml.bind.Unmarshaller) XMLUnmarshaller(org.eclipse.persistence.oxm.XMLUnmarshaller) DatasourceLogin(org.eclipse.persistence.sessions.DatasourceLogin) XMLContext(org.eclipse.persistence.oxm.XMLContext) StreamSource(javax.xml.transform.stream.StreamSource) JAXBException(jakarta.xml.bind.JAXBException) DatabaseLogin(org.eclipse.persistence.sessions.DatabaseLogin) Project(org.eclipse.persistence.sessions.Project) DBWSBuilderModelProject(org.eclipse.persistence.tools.dbws.DBWSBuilderModelProject) DatabaseSessionImpl(org.eclipse.persistence.internal.sessions.DatabaseSessionImpl) MetadataProcessor(org.eclipse.persistence.internal.jpa.metadata.MetadataProcessor) Map(java.util.Map) HashMap(java.util.HashMap)

Example 3 with Platform

use of org.eclipse.persistence.internal.databaseaccess.Platform in project eclipselink by eclipse-ee4j.

the class DBWSTestSuite method setUp.

/**
 * This method should be used when sessions xml is to be generated and written out
 * to DBWS_SESSION_STREAM.
 *
 * @param stageDir sessions xml will be generated and written out if non-null
 */
public static void setUp(String stageDir, boolean useLogger) throws WSDLException {
    comparer.setIgnoreOrder(true);
    if (builder == null) {
        builder = new DBWSBuilder();
    }
    DBWS_SERVICE_STREAM = new ByteArrayOutputStream();
    DBWS_SCHEMA_STREAM = new ByteArrayOutputStream();
    DBWS_SESSION_STREAM = new ByteArrayOutputStream();
    DBWS_OR_STREAM = new ByteArrayOutputStream();
    DBWS_OX_STREAM = new ByteArrayOutputStream();
    DBWS_WSDL_STREAM = new ByteArrayOutputStream();
    final String username = System.getProperty(DATABASE_USERNAME_KEY, DEFAULT_DATABASE_USERNAME);
    final String password = System.getProperty(DATABASE_PASSWORD_KEY, DEFAULT_DATABASE_PASSWORD);
    final String url = System.getProperty(DATABASE_URL_KEY, DEFAULT_DATABASE_URL);
    String builderString = DBWS_BUILDER_XML_USERNAME + username + DBWS_BUILDER_XML_PASSWORD + password + DBWS_BUILDER_XML_URL + url + DBWS_BUILDER_XML_DRIVER + DATABASE_DRIVER + DBWS_BUILDER_XML_PLATFORM + DATABASE_PLATFORM + DBWS_BUILDER_XML_MAIN;
    XMLContext context = new XMLContext(new DBWSBuilderModelProject());
    XMLUnmarshaller unmarshaller = context.createUnmarshaller();
    DBWSBuilderModel builderModel = (DBWSBuilderModel) unmarshaller.unmarshal(new StringReader(builderString));
    builder.quiet = true;
    builder.setPlatformClassname(DATABASE_PLATFORM);
    builder.properties = builderModel.properties;
    builder.operations = builderModel.operations;
    XRPackager xrPackager = new JSR109WebServicePackager(null, "WebServiceTestPackager", noArchive) {

        @Override
        public void start() {
        // do nothing - don't have to verify existence of 'stageDir' when
        // all the streams are in-memory
        }
    };
    xrPackager.setDBWSBuilder(builder);
    builder.setPackager(xrPackager);
    builder.setPackager(xrPackager);
    dbwsLogger = null;
    if (useLogger) {
        dbwsLogger = new DBWSLogger("DBWSTestLogger", null);
    }
    if (stageDir == null) {
        builder.getProperties().put(SESSIONS_FILENAME_KEY, NO_SESSIONS_FILENAME);
        builder.build(DBWS_SCHEMA_STREAM, __nullStream, DBWS_SERVICE_STREAM, DBWS_OR_STREAM, DBWS_OX_STREAM, __nullStream, __nullStream, __nullStream, __nullStream, __nullStream, __nullStream, __nullStream, dbwsLogger);
    } else {
        xrPackager.setStageDir(new File(stageDir));
        builder.build(DBWS_SCHEMA_STREAM, DBWS_SESSION_STREAM, DBWS_SERVICE_STREAM, DBWS_OR_STREAM, DBWS_OX_STREAM, __nullStream, __nullStream, DBWS_WSDL_STREAM, __nullStream, __nullStream, __nullStream, __nullStream, dbwsLogger);
    }
    XRServiceFactory factory = new XRServiceFactory() {

        @Override
        public XRServiceAdapter buildService(XRServiceModel xrServiceModel) {
            parentClassLoader = this.getClass().getClassLoader();
            xrSchemaStream = new ByteArrayInputStream(DBWS_SCHEMA_STREAM.toByteArray());
            return super.buildService(xrServiceModel);
        }

        @Override
        public void buildSessions() {
            XRDynamicClassLoader xrdecl = new XRDynamicClassLoader(parentClassLoader);
            DatasourceLogin login = new DatabaseLogin();
            login.setUserName(username);
            login.setPassword(password);
            ((DatabaseLogin) login).setConnectionString(url);
            ((DatabaseLogin) login).setDriverClassName(DATABASE_PLATFORM);
            Platform platform = builder.getDatabasePlatform();
            ConversionManager conversionManager = platform.getConversionManager();
            if (conversionManager != null) {
                conversionManager.setLoader(xrdecl);
            }
            login.setDatasourcePlatform(platform);
            ((DatabaseLogin) login).bindAllParameters();
            Project orProject = null;
            if (DBWS_OR_STREAM.size() != 0) {
                MetadataProcessor processor = new MetadataProcessor(new XRPersistenceUnitInfo(xrdecl), new DatabaseSessionImpl(login), xrdecl, false, true, false, false, false, null, null);
                processor.setMetadataSource(new JPAMetadataSource(xrdecl, new StringReader(DBWS_OR_STREAM.toString())));
                PersistenceUnitProcessor.processORMetadata(processor, true, PersistenceUnitProcessor.Mode.ALL);
                processor.addNamedQueries();
                orProject = processor.getProject().getProject();
            } else {
                orProject = new Project();
            }
            orProject.setName(builder.getProjectName().concat(OR_PRJ_SUFFIX));
            orProject.setDatasourceLogin(login);
            DatabaseSession databaseSession = orProject.createDatabaseSession();
            if ("off".equalsIgnoreCase(builder.getLogLevel())) {
                databaseSession.dontLogMessages();
            } else {
                databaseSession.setLogLevel(AbstractSessionLog.translateStringToLoggingLevel(builder.getLogLevel()));
            }
            xrService.setORSession(databaseSession);
            orProject.convertClassNamesToClasses(xrdecl);
            Project oxProject = null;
            if (DBWS_OX_STREAM.size() != 0) {
                Map<String, OXMMetadataSource> metadataMap = new HashMap<String, OXMMetadataSource>();
                StreamSource xml = new StreamSource(new StringReader(DBWS_OX_STREAM.toString()));
                try {
                    JAXBContext jc = JAXBContext.newInstance(XmlBindingsModel.class);
                    Unmarshaller unmarshaller = jc.createUnmarshaller();
                    JAXBElement<XmlBindingsModel> jaxbElt = unmarshaller.unmarshal(xml, XmlBindingsModel.class);
                    XmlBindingsModel model = jaxbElt.getValue();
                    for (XmlBindings xmlBindings : model.getBindingsList()) {
                        metadataMap.put(xmlBindings.getPackageName(), new OXMMetadataSource(xmlBindings));
                    }
                } catch (JAXBException jaxbex) {
                    jaxbex.printStackTrace();
                }
                Map<String, Map<String, OXMMetadataSource>> properties = new HashMap<String, Map<String, OXMMetadataSource>>();
                properties.put(JAXBContextProperties.OXM_METADATA_SOURCE, metadataMap);
                try {
                    org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext jCtx = org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContextFactory.createContextFromOXM(xrdecl, properties);
                    oxProject = jCtx.getXMLContext().getSession(0).getProject();
                } catch (JAXBException e) {
                    e.printStackTrace();
                }
            } else {
                oxProject = new Project();
            }
            oxProject.setName(builder.getProjectName().concat(OX_PRJ_SUFFIX));
            login = (DatasourceLogin) oxProject.getDatasourceLogin();
            if (login != null) {
                platform = login.getDatasourcePlatform();
                if (platform != null) {
                    conversionManager = platform.getConversionManager();
                    if (conversionManager != null) {
                        conversionManager.setLoader(xrdecl);
                    }
                }
            }
            prepareDescriptors(oxProject, orProject, xrdecl);
            ProjectHelper.fixOROXAccessors(orProject, oxProject);
            xrService.setORSession(orProject.createDatabaseSession());
            xrService.getORSession().dontLogMessages();
            xrService.setXMLContext(new XMLContext(oxProject));
            xrService.setOXSession(xrService.getXMLContext().getSession(0));
        }
    };
    context = new XMLContext(new DBWSModelProject());
    unmarshaller = context.createUnmarshaller();
    DBWSModel model = (DBWSModel) unmarshaller.unmarshal(new StringReader(DBWS_SERVICE_STREAM.toString()));
    xrService = factory.buildService(model);
}
Also used : XRPackager(org.eclipse.persistence.tools.dbws.XRPackager) XmlBindings(org.eclipse.persistence.jaxb.xmlmodel.XmlBindings) Platform(org.eclipse.persistence.internal.databaseaccess.Platform) XMLPlatform(org.eclipse.persistence.platform.xml.XMLPlatform) DatabaseSession(org.eclipse.persistence.sessions.DatabaseSession) HashMap(java.util.HashMap) XRDynamicClassLoader(org.eclipse.persistence.internal.xr.XRDynamicClassLoader) JAXBContext(jakarta.xml.bind.JAXBContext) DBWSBuilder(org.eclipse.persistence.tools.dbws.DBWSBuilder) DBWSModelProject(org.eclipse.persistence.dbws.DBWSModelProject) JSR109WebServicePackager(org.eclipse.persistence.tools.dbws.JSR109WebServicePackager) StringReader(java.io.StringReader) ConversionManager(org.eclipse.persistence.internal.helper.ConversionManager) XmlBindingsModel(org.eclipse.persistence.internal.xr.XmlBindingsModel) XMLUnmarshaller(org.eclipse.persistence.oxm.XMLUnmarshaller) Unmarshaller(jakarta.xml.bind.Unmarshaller) XMLUnmarshaller(org.eclipse.persistence.oxm.XMLUnmarshaller) DatasourceLogin(org.eclipse.persistence.sessions.DatasourceLogin) DBWSModel(org.eclipse.persistence.dbws.DBWSModel) XMLContext(org.eclipse.persistence.oxm.XMLContext) StreamSource(javax.xml.transform.stream.StreamSource) JAXBException(jakarta.xml.bind.JAXBException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DatabaseLogin(org.eclipse.persistence.sessions.DatabaseLogin) DBWSBuilderModelProject(org.eclipse.persistence.tools.dbws.DBWSBuilderModelProject) Project(org.eclipse.persistence.sessions.Project) DBWSModelProject(org.eclipse.persistence.dbws.DBWSModelProject) XRServiceFactory(org.eclipse.persistence.internal.xr.XRServiceFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) DatabaseSessionImpl(org.eclipse.persistence.internal.sessions.DatabaseSessionImpl) DBWSBuilderModel(org.eclipse.persistence.tools.dbws.DBWSBuilderModel) XRServiceModel(org.eclipse.persistence.internal.xr.XRServiceModel) DBWSBuilderModelProject(org.eclipse.persistence.tools.dbws.DBWSBuilderModelProject) File(java.io.File) MetadataProcessor(org.eclipse.persistence.internal.jpa.metadata.MetadataProcessor) Map(java.util.Map) HashMap(java.util.HashMap)

Example 4 with Platform

use of org.eclipse.persistence.internal.databaseaccess.Platform in project eclipselink by eclipse-ee4j.

the class ProjectHelper method fixOROXAccessors.

/**
 * INTERNAL: Fix the given EclipseLink OR and OX projects so that the
 * descriptors for all generated sub-classes of XRDynamicEntity have the correct
 * AttributeAccessors.
 */
public static void fixOROXAccessors(Project orProject, Project oxProject) {
    for (Iterator<ClassDescriptor> i = orProject.getDescriptors().values().iterator(); i.hasNext(); ) {
        ClassDescriptor desc = i.next();
        if (!XRDynamicEntity.class.isAssignableFrom(desc.getJavaClass())) {
            continue;
        }
        Class<?> clz = desc.getJavaClass();
        ClassDescriptor xdesc = null;
        if (oxProject != null) {
            xdesc = oxProject.getDescriptorForAlias(desc.getAlias());
        }
        XRDynamicPropertiesManager xrDPM = null;
        if (!clz.getName().endsWith(COLLECTION_WRAPPER_SUFFIX)) {
            try {
                XRDynamicEntity newInstance = (XRDynamicEntity) clz.getConstructor().newInstance();
                xrDPM = newInstance.fetchPropertiesManager();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        Set<String> propertiesNameSet = new HashSet<>();
        for (Iterator<DatabaseMapping> j = desc.getMappings().iterator(); j.hasNext(); ) {
            DatabaseMapping dm = j.next();
            String attributeName = dm.getAttributeName();
            DatabaseMapping xdm = null;
            if (xdesc != null) {
                xdm = xdesc.getMappingForAttributeName(attributeName);
            }
            dm.setAttributeAccessor(new XRDynamicEntityAccessor(dm));
            if (xdm != null) {
                if (dm.isForeignReferenceMapping()) {
                    ForeignReferenceMapping frm = (ForeignReferenceMapping) dm;
                    if (frm.usesIndirection() && frm.getIndirectionPolicy().getClass().isAssignableFrom(BasicIndirectionPolicy.class)) {
                        xdm.setAttributeAccessor(new XRDynamicEntityVHAccessor(dm));
                    } else {
                        // no indirection or indirection that is transparent enough (!) to work
                        xdm.setAttributeAccessor(new XRDynamicEntityAccessor(dm));
                    }
                } else {
                    xdm.setAttributeAccessor(new XRDynamicEntityAccessor(dm));
                }
            }
            propertiesNameSet.add(attributeName);
        }
        if (xrDPM != null) {
            xrDPM.setPropertyNames(propertiesNameSet);
        }
    }
    // turn-off dynamic class generation
    ClassLoader cl = null;
    Login login = orProject.getDatasourceLogin();
    if (login != null) {
        Platform platform = login.getDatasourcePlatform();
        if (platform != null) {
            ConversionManager conversionManager = platform.getConversionManager();
            if (conversionManager != null) {
                cl = conversionManager.getLoader();
            }
        }
    }
    if (cl instanceof XRDynamicClassLoader) {
        XRDynamicClassLoader xrdecl = (XRDynamicClassLoader) cl;
        xrdecl.dontGenerateSubclasses();
    }
    if (oxProject != null) {
        cl = null;
        login = oxProject.getDatasourceLogin();
        if (login != null) {
            Platform platform = login.getDatasourcePlatform();
            if (platform != null) {
                ConversionManager conversionManager = platform.getConversionManager();
                if (conversionManager != null) {
                    cl = conversionManager.getLoader();
                }
            }
        }
        if (cl instanceof XRDynamicClassLoader) {
            XRDynamicClassLoader xrdecl = (XRDynamicClassLoader) cl;
            xrdecl.dontGenerateSubclasses();
        }
    }
}
Also used : ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) Platform(org.eclipse.persistence.internal.databaseaccess.Platform) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping) BasicIndirectionPolicy(org.eclipse.persistence.internal.indirection.BasicIndirectionPolicy) Login(org.eclipse.persistence.sessions.Login) ForeignReferenceMapping(org.eclipse.persistence.mappings.ForeignReferenceMapping) ConversionManager(org.eclipse.persistence.internal.helper.ConversionManager) HashSet(java.util.HashSet)

Example 5 with Platform

use of org.eclipse.persistence.internal.databaseaccess.Platform in project eclipselink by eclipse-ee4j.

the class SessionsFactory method processStructConverterConfig.

/**
 * INTERNAL:
 */
@SuppressWarnings({ "unchecked" })
protected void processStructConverterConfig(StructConverterConfig converterClassConfig, DatabaseLogin login) {
    if (converterClassConfig != null) {
        Platform platform = login.getDatasourcePlatform();
        if (platform instanceof DatabasePlatform) {
            Iterator<String> i = converterClassConfig.getStructConverterClasses().iterator();
            while (i.hasNext()) {
                String converterClassName = i.next();
                try {
                    Class<StructConverter> converterClass = (Class<StructConverter>) m_classLoader.loadClass(converterClassName);
                    StructConverter converter = null;
                    if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()) {
                        try {
                            converter = AccessController.doPrivileged(new PrivilegedNewInstanceFromClass<>(converterClass));
                        } catch (PrivilegedActionException ex) {
                            throw (Exception) ex.getCause();
                        }
                    } else {
                        converter = PrivilegedAccessHelper.newInstanceFromClass(converterClass);
                    }
                    ((DatabasePlatform) platform).addStructConverter(converter);
                } catch (Exception exception) {
                    throw SessionLoaderException.failedToLoadTag("struct-converter", converterClassName, exception);
                }
            }
        }
    }
}
Also used : Platform(org.eclipse.persistence.internal.databaseaccess.Platform) DatasourcePlatform(org.eclipse.persistence.internal.databaseaccess.DatasourcePlatform) ServerPlatform(org.eclipse.persistence.platform.server.ServerPlatform) DatabasePlatform(org.eclipse.persistence.internal.databaseaccess.DatabasePlatform) NoServerPlatform(org.eclipse.persistence.platform.server.NoServerPlatform) StructConverter(org.eclipse.persistence.platform.database.converters.StructConverter) PrivilegedNewInstanceFromClass(org.eclipse.persistence.internal.security.PrivilegedNewInstanceFromClass) PrivilegedActionException(java.security.PrivilegedActionException) PrivilegedNewInstanceFromClass(org.eclipse.persistence.internal.security.PrivilegedNewInstanceFromClass) DatabasePlatform(org.eclipse.persistence.internal.databaseaccess.DatabasePlatform) ValidationException(org.eclipse.persistence.exceptions.ValidationException) PrivilegedActionException(java.security.PrivilegedActionException) SessionLoaderException(org.eclipse.persistence.exceptions.SessionLoaderException)

Aggregations

Platform (org.eclipse.persistence.internal.databaseaccess.Platform)58 EntityManager (jakarta.persistence.EntityManager)40 Test (org.junit.Test)31 DatabasePlatform (org.eclipse.persistence.platform.database.DatabasePlatform)21 CriteriaBuilder (jakarta.persistence.criteria.CriteriaBuilder)17 StringReader (java.io.StringReader)11 ConversionManager (org.eclipse.persistence.internal.helper.ConversionManager)11 EntityTbl01 (org.eclipse.persistence.jpa.test.query.model.EntityTbl01)11 DatabaseLogin (org.eclipse.persistence.sessions.DatabaseLogin)11 DatabaseSession (org.eclipse.persistence.sessions.DatabaseSession)11 Project (org.eclipse.persistence.sessions.Project)11 XRDynamicClassLoader (org.eclipse.persistence.internal.xr.XRDynamicClassLoader)10 XMLContext (org.eclipse.persistence.oxm.XMLContext)10 XMLPlatform (org.eclipse.persistence.platform.xml.XMLPlatform)10 HashMap (java.util.HashMap)9 Map (java.util.Map)9 DatabaseSessionImpl (org.eclipse.persistence.internal.sessions.DatabaseSessionImpl)9 DatasourceLogin (org.eclipse.persistence.sessions.DatasourceLogin)9 Query (jakarta.persistence.Query)8 JAXBContext (jakarta.xml.bind.JAXBContext)8