Search in sources :

Example 1 with MetadataProcessor

use of org.eclipse.persistence.internal.jpa.metadata.MetadataProcessor in project eclipselink by eclipse-ee4j.

the class EntityManagerSetupImpl method predeploy.

/**
 * Perform any steps necessary prior to actual deployment.  This includes any steps in the session
 * creation that do not require the real loaded domain classes.
 *
 * The first call to this method caches persistenceUnitInfo which is reused in the following calls.
 *
 * Note that in JSE case factoryCount is NOT incremented on the very first call
 * (by JavaSECMPInitializer.callPredeploy, typically in preMain).
 * That provides 1 to 1 correspondence between factoryCount and the number of open factories.
 *
 * In case factoryCount > 0 the method just increments factoryCount.
 * factory == 0 triggers creation of a new session.
 *
 * This method and undeploy - the only methods altering factoryCount - should be synchronized.
 *
 * @return A transformer (which may be null) that should be plugged into the proper
 *         classloader to allow classes to be transformed as they get loaded.
 * @see #deploy(ClassLoader, Map)
 */
public synchronized ClassTransformer predeploy(PersistenceUnitInfo info, Map extendedProperties) {
    ClassLoader classLoaderToUse = null;
    // session == null
    if (state == STATE_DEPLOY_FAILED || state == STATE_UNDEPLOYED) {
        throw new PersistenceException(EntityManagerSetupException.cannotPredeploy(persistenceUnitInfo.getPersistenceUnitName(), state, persistenceException));
    }
    // session != null
    if (state == STATE_PREDEPLOYED || state == STATE_DEPLOYED || state == STATE_HALF_DEPLOYED) {
        session.log(SessionLog.FINEST, SessionLog.JPA, "predeploy_begin", new Object[] { getPersistenceUnitInfo().getPersistenceUnitName(), session.getName(), state, factoryCount });
        factoryCount++;
        session.log(SessionLog.FINEST, SessionLog.JPA, "predeploy_end", new Object[] { getPersistenceUnitInfo().getPersistenceUnitName(), session.getName(), state, factoryCount });
        return null;
    // session == null
    } else if (state == STATE_INITIAL) {
        persistenceUnitInfo = info;
        if (!isCompositeMember()) {
            if (mustBeCompositeMember(persistenceUnitInfo)) {
                if (this.staticWeaveInfo == null) {
                    return null;
                } else {
                    // predeploy is used for static weaving
                    throw new PersistenceException(EntityManagerSetupException.compositeMemberCannotBeUsedStandalone(persistenceUnitInfo.getPersistenceUnitName()));
                }
            }
        }
    }
    // state is INITIAL or PREDEPLOY_FAILED or STATE_HALF_PREDEPLOYED_COMPOSITE_MEMBER, session == null
    try {
        // properties not used in STATE_HALF_PREDEPLOYED_COMPOSITE_MEMBER
        Map predeployProperties = null;
        // composite can't be in STATE_HALF_PREDEPLOYED_COMPOSITE_MEMBER
        boolean isComposite = false;
        if (state != STATE_HALF_PREDEPLOYED_COMPOSITE_MEMBER) {
            // set the claasloader early on and change it if needed
            classLoaderToUse = persistenceUnitInfo.getClassLoader();
            predeployProperties = mergeMaps(extendedProperties, persistenceUnitInfo.getProperties());
            // Translate old properties.
            // This should be done before using properties (i.e. ServerPlatform).
            translateOldProperties(predeployProperties, null);
            String sessionsXMLStr = (String) predeployProperties.get(PersistenceUnitProperties.SESSIONS_XML);
            if (sessionsXMLStr != null) {
                isSessionLoadedFromSessionsXML = true;
            }
            // Create session (it needs to be done before initializing ServerPlatform and logging).
            // If a sessions-xml is used this will get replaced later, but is required for logging.
            isComposite = isComposite(persistenceUnitInfo);
            if (isComposite) {
                if (isSessionLoadedFromSessionsXML) {
                    throw EntityManagerSetupException.compositeIncompatibleWithSessionsXml(persistenceUnitInfo.getPersistenceUnitName());
                }
                session = new SessionBroker();
                ((SessionBroker) session).setShouldUseDescriptorAliases(true);
            } else {
                session = new ServerSession(new Project(new DatabaseLogin()));
                // set the listener to process RCM metadata refresh commands
                session.setRefreshMetadataListener(this);
            }
            session.setName(this.sessionName);
            updateTunerPreDeploy(predeployProperties, classLoaderToUse);
            updateTolerateInvalidJPQL(predeployProperties);
            if (this.compositeEmSetupImpl == null) {
                // session name and ServerPlatform must be set prior to setting the loggers.
                if (this.staticWeaveInfo == null) {
                    updateServerPlatform(predeployProperties, classLoaderToUse);
                    // Update loggers and settings for the singleton logger and the session logger.
                    updateLoggers(predeployProperties, true, classLoaderToUse);
                    // log the server platform being used by the session
                    if (session.getSessionLog().shouldLog(SessionLog.FINE)) {
                        session.getSessionLog().log(SessionLog.FINE, SessionLog.SERVER, "configured_server_platform", // NOI18N
                        session.getServerPlatform().getClass().getName());
                    }
                    // Get the temporary classLoader based on the platform
                    // Update performance profiler
                    updateProfiler(predeployProperties, classLoaderToUse);
                } else {
                    // predeploy is used for static weaving
                    Writer writer = this.staticWeaveInfo.getLogWriter();
                    if (writer != null) {
                        session.getSessionLog().setWriter(writer);
                    }
                    session.setLogLevel(this.staticWeaveInfo.getLogLevel());
                }
            } else {
                // composite member
                session.setSessionLog(this.compositeEmSetupImpl.session.getSessionLog());
                session.setProfiler(this.compositeEmSetupImpl.session.getProfiler());
            }
            // Cannot start logging until session and log and initialized, so log start of predeploy here.
            session.log(SessionLog.FINEST, SessionLog.JPA, "predeploy_begin", new Object[] { getPersistenceUnitInfo().getPersistenceUnitName(), session.getName(), state, factoryCount });
            // Project Cache accessor processing
            updateProjectCache(predeployProperties, classLoaderToUse);
            if (projectCacheAccessor != null) {
                // 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);
                    }
                } else {
                    throw EntityManagerSetupException.sessionLoadedFromSessionsXMLMustBeServerSession(persistenceUnitInfo.getPersistenceUnitName(), (String) predeployProperties.get(PersistenceUnitProperties.SESSIONS_XML), tempSession);
                }
                if (this.staticWeaveInfo == null) {
                    // Must now reset logging and server-platform on the loaded session.
                    // ServerPlatform must be set prior to setting the loggers.
                    updateServerPlatform(predeployProperties, classLoaderToUse);
                    // Update loggers and settings for the singleton logger and the session logger.
                    updateLoggers(predeployProperties, true, classLoaderToUse);
                }
            } else {
                classLoaderToUse = persistenceUnitInfo.getClassLoader();
            }
            warnOldProperties(predeployProperties, session);
            session.getPlatform().setConversionManager(new JPAConversionManager());
            if (this.staticWeaveInfo == null) {
                if (!isComposite) {
                    PersistenceUnitTransactionType transactionType = null;
                    // bug 5867753: find and override the transaction type
                    String transTypeString = getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.TRANSACTION_TYPE, predeployProperties, session);
                    if (transTypeString != null && transTypeString.length() > 0) {
                        transactionType = PersistenceUnitTransactionType.valueOf(transTypeString);
                    } else if (persistenceUnitInfo != null) {
                        transactionType = persistenceUnitInfo.getTransactionType();
                    }
                    if (!isValidationOnly(predeployProperties, false) && persistenceUnitInfo != null && transactionType == PersistenceUnitTransactionType.JTA) {
                        if (predeployProperties.get(PersistenceUnitProperties.JTA_DATASOURCE) == null && persistenceUnitInfo.getJtaDataSource() == null) {
                            if (predeployProperties.get(PersistenceUnitProperties.SCHEMA_DATABASE_PRODUCT_NAME) == null || predeployProperties.get(PersistenceUnitProperties.SCHEMA_DATABASE_MAJOR_VERSION) == null || predeployProperties.get(PersistenceUnitProperties.SCHEMA_DATABASE_MINOR_VERSION) == null) {
                                throw EntityManagerSetupException.jtaPersistenceUnitInfoMissingJtaDataSource(persistenceUnitInfo.getPersistenceUnitName());
                            }
                        }
                    }
                }
                // this flag is used to disable work done as a result of the LAZY hint on OneToOne and ManyToOne mappings
                if (state == STATE_INITIAL) {
                    if (compositeEmSetupImpl == null) {
                        if (null == enableWeaving) {
                            enableWeaving = Boolean.TRUE;
                        }
                        isWeavingStatic = false;
                        String weaving = getConfigPropertyAsString(PersistenceUnitProperties.WEAVING, predeployProperties);
                        if (weaving != null && weaving.equalsIgnoreCase("false")) {
                            enableWeaving = Boolean.FALSE;
                        } else if (weaving != null && weaving.equalsIgnoreCase("static")) {
                            isWeavingStatic = true;
                        }
                    } else {
                        // no weaving for composite forces no weaving for members
                        if (!compositeEmSetupImpl.enableWeaving) {
                            enableWeaving = Boolean.FALSE;
                        } else {
                            if (null == enableWeaving) {
                                enableWeaving = Boolean.TRUE;
                            }
                            String weaving = getConfigPropertyAsString(PersistenceUnitProperties.WEAVING, predeployProperties);
                            if (weaving != null && weaving.equalsIgnoreCase("false")) {
                                enableWeaving = Boolean.FALSE;
                            }
                        }
                        // static weaving is dictated by composite
                        isWeavingStatic = compositeEmSetupImpl.isWeavingStatic;
                    }
                }
                if (compositeEmSetupImpl == null) {
                    throwExceptionOnFail = "true".equalsIgnoreCase(EntityManagerFactoryProvider.getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.THROW_EXCEPTIONS, predeployProperties, "true", session));
                } else {
                    // composite member
                    throwExceptionOnFail = compositeEmSetupImpl.throwExceptionOnFail;
                }
            } else {
                // predeploy is used for static weaving
                enableWeaving = Boolean.TRUE;
            }
            weaveChangeTracking = false;
            weaveLazy = false;
            weaveEager = false;
            weaveFetchGroups = false;
            weaveInternal = false;
            weaveRest = false;
            weaveMappedSuperClass = false;
            if (enableWeaving) {
                weaveChangeTracking = "true".equalsIgnoreCase(EntityManagerFactoryProvider.getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.WEAVING_CHANGE_TRACKING, predeployProperties, "true", session));
                weaveLazy = "true".equalsIgnoreCase(EntityManagerFactoryProvider.getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.WEAVING_LAZY, predeployProperties, "true", session));
                weaveEager = "true".equalsIgnoreCase(EntityManagerFactoryProvider.getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.WEAVING_EAGER, predeployProperties, "false", session));
                weaveFetchGroups = "true".equalsIgnoreCase(EntityManagerFactoryProvider.getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.WEAVING_FETCHGROUPS, predeployProperties, "true", session));
                weaveInternal = "true".equalsIgnoreCase(EntityManagerFactoryProvider.getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.WEAVING_INTERNAL, predeployProperties, "true", session));
                weaveRest = "true".equalsIgnoreCase(EntityManagerFactoryProvider.getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.WEAVING_REST, predeployProperties, shouldWeaveRestByDefault(classLoaderToUse), session));
                weaveMappedSuperClass = "true".equalsIgnoreCase(EntityManagerFactoryProvider.getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.WEAVING_MAPPEDSUPERCLASS, predeployProperties, "true", session));
            }
        }
        if (shouldBuildProject && !isSessionLoadedFromSessionsXML) {
            if (isComposite) {
                predeployCompositeMembers(predeployProperties, classLoaderToUse);
            } else {
                MetadataProcessor compositeProcessor = null;
                if (compositeEmSetupImpl == null) {
                    mode = PersistenceUnitProcessor.Mode.ALL;
                } else {
                    // composite member
                    if (state != STATE_HALF_PREDEPLOYED_COMPOSITE_MEMBER) {
                        state = STATE_HALF_PREDEPLOYED_COMPOSITE_MEMBER;
                        mode = PersistenceUnitProcessor.Mode.COMPOSITE_MEMBER_INITIAL;
                    }
                    compositeProcessor = compositeEmSetupImpl.processor;
                }
                if (mode == PersistenceUnitProcessor.Mode.ALL || mode == PersistenceUnitProcessor.Mode.COMPOSITE_MEMBER_INITIAL) {
                    boolean usesMultitenantSharedEmf = "true".equalsIgnoreCase(EntityManagerFactoryProvider.getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.MULTITENANT_SHARED_EMF, predeployProperties, "true", session));
                    boolean usesMultitenantSharedCache = "true".equalsIgnoreCase(EntityManagerFactoryProvider.getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.MULTITENANT_SHARED_CACHE, predeployProperties, "false", session));
                    // Create an instance of MetadataProcessor for specified persistence unit info
                    processor = new MetadataProcessor(persistenceUnitInfo, session, classLoaderToUse, weaveLazy, weaveEager, weaveFetchGroups, usesMultitenantSharedEmf, usesMultitenantSharedCache, predeployProperties, compositeProcessor);
                    // need to use the real classloader to create the repository class
                    updateMetadataRepository(predeployProperties, classLoaderToUse);
                    // bug:299926 - Case insensitive table / column matching with native SQL queries
                    EntityManagerSetupImpl.updateCaseSensitivitySettings(predeployProperties, processor.getProject(), session);
                }
                // Set the shared cache mode to the jakarta.persistence.sharedCache.mode property value.
                updateSharedCacheMode(predeployProperties);
                // If Java Security is enabled, surround this call with a doPrivileged block.
                if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()) {
                    AccessController.doPrivileged(new PrivilegedAction<Void>() {

                        @Override
                        public Void run() {
                            PersistenceUnitProcessor.processORMetadata(processor, throwExceptionOnFail, mode);
                            return null;
                        }
                    });
                } else {
                    PersistenceUnitProcessor.processORMetadata(processor, throwExceptionOnFail, mode);
                }
                if (mode == PersistenceUnitProcessor.Mode.COMPOSITE_MEMBER_INITIAL) {
                    mode = PersistenceUnitProcessor.Mode.COMPOSITE_MEMBER_MIDDLE;
                    session.log(SessionLog.FINEST, SessionLog.JPA, "predeploy_end", new Object[] { getPersistenceUnitInfo().getPersistenceUnitName(), session.getName(), state + " " + mode, factoryCount });
                    return null;
                } else if (mode == PersistenceUnitProcessor.Mode.COMPOSITE_MEMBER_MIDDLE) {
                    mode = PersistenceUnitProcessor.Mode.COMPOSITE_MEMBER_FINAL;
                    session.log(SessionLog.FINEST, SessionLog.JPA, "predeploy_end", new Object[] { getPersistenceUnitInfo().getPersistenceUnitName(), session.getName(), state + " " + mode, factoryCount });
                    return null;
                }
                // mode == PersistenceUnitProcessor.Mode.ALL || mode == PersistenceUnitProcessor.Mode.COMPOSITE_MEMBER_FINAL
                // clear mode and proceed
                mode = null;
                if (session.getIntegrityChecker().hasErrors()) {
                    session.handleException(new IntegrityException(session.getIntegrityChecker()));
                }
                // be returned if we we are mean to process these mappings
                if (enableWeaving) {
                    // build a list of entities the persistence unit represented by this EntityManagerSetupImpl will use
                    Collection<MetadataClass> entities = PersistenceUnitProcessor.buildEntityList(processor, classLoaderToUse);
                    this.weaver = TransformerFactory.createTransformerAndModifyProject(session, entities, classLoaderToUse, weaveLazy, weaveChangeTracking, weaveFetchGroups, weaveInternal, weaveRest, weaveMappedSuperClass);
                    session.getProject().setClassNamesForWeaving(new ArrayList<>(processor.getProject().getWeavableClassNames()));
                }
                // moved from deployment:
                processor.addNamedQueries();
                processor.addStructConverterNames();
            }
        } else {
            // be returned if we we are meant to process these mappings.
            if (enableWeaving) {
                Collection<MetadataClass> persistenceClasses = new ArrayList<>();
                MetadataAsmFactory factory = new MetadataAsmFactory(new MetadataLogger(session), classLoaderToUse);
                if (shouldBuildProject) {
                    // build a list of entities the persistence unit represented by this EntityManagerSetupImpl will use
                    for (Iterator<Class<?>> iterator = session.getProject().getDescriptors().keySet().iterator(); iterator.hasNext(); ) {
                        persistenceClasses.add(factory.getMetadataClass(iterator.next().getName()));
                    }
                } else {
                    // build a list of entities the persistence unit represented by this EntityManagerSetupImpl will use
                    for (String className : session.getProject().getClassNamesForWeaving()) {
                        persistenceClasses.add(factory.getMetadataClass(className));
                    }
                }
                this.weaver = TransformerFactory.createTransformerAndModifyProject(session, persistenceClasses, classLoaderToUse, weaveLazy, weaveChangeTracking, weaveFetchGroups, weaveInternal, weaveRest, weaveMappedSuperClass);
            }
        }
        // composite member never has a factory - it is predeployed by the composite.
        if (!isCompositeMember()) {
            // but rather done by JavaSECMPInitializer.callPredeploy (typically in preMain).
            if (state != STATE_INITIAL || this.isInContainerMode()) {
                factoryCount++;
            }
            preInitializeMetamodel();
        }
        state = STATE_PREDEPLOYED;
        session.log(SessionLog.FINEST, SessionLog.JPA, "predeploy_end", new Object[] { getPersistenceUnitInfo().getPersistenceUnitName(), session.getName(), state, factoryCount });
        // gf3146: if static weaving is used, we should not return a transformer.  Transformer should still be created though as it modifies descriptors
        if (isWeavingStatic) {
            return null;
        } else {
            return this.weaver;
        }
    } catch (Throwable ex) {
        state = STATE_PREDEPLOY_FAILED;
        // cache this.persistenceException before slow logging
        PersistenceException persistenceEx = createPredeployFailedPersistenceException(ex);
        // If session exists, use it for logging
        if (session != null) {
            session.log(SessionLog.FINEST, SessionLog.JPA, "predeploy_end", new Object[] { getPersistenceUnitInfo().getPersistenceUnitName(), session.getName(), state, factoryCount });
        // If at least staticWeaveInfo exists, use it for logging
        } else if (staticWeaveInfo != null && staticWeaveInfo.getLogLevel() <= SessionLog.FINEST) {
            Writer logWriter = staticWeaveInfo.getLogWriter();
            if (logWriter != null) {
                String message = LoggingLocalization.buildMessage("predeploy_end", new Object[] { getPersistenceUnitInfo().getPersistenceUnitName(), "N/A", state, factoryCount });
                try {
                    logWriter.write(message);
                    logWriter.write(Helper.cr());
                } catch (IOException ioex) {
                // Ignore IOException
                }
            }
        }
        session = null;
        mode = null;
        throw persistenceEx;
    }
}
Also used : ArrayList(java.util.ArrayList) MetadataAsmFactory(org.eclipse.persistence.internal.jpa.metadata.accessors.objects.MetadataAsmFactory) EntityManagerFactoryProvider.getConfigPropertyAsString(org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.getConfigPropertyAsString) MetadataLogger(org.eclipse.persistence.internal.jpa.metadata.MetadataLogger) JPAClassLoaderHolder(org.eclipse.persistence.internal.helper.JPAClassLoaderHolder) MetadataClass(org.eclipse.persistence.internal.jpa.metadata.accessors.objects.MetadataClass) DynamicClassLoader(org.eclipse.persistence.dynamic.DynamicClassLoader) ServerSession(org.eclipse.persistence.sessions.server.ServerSession) JPAConversionManager(org.eclipse.persistence.internal.helper.JPAConversionManager) RMIServerSessionManager(org.eclipse.persistence.sessions.remote.rmi.RMIServerSessionManager) SessionManager(org.eclipse.persistence.sessions.factories.SessionManager) SessionBroker(org.eclipse.persistence.sessions.broker.SessionBroker) IntegrityException(org.eclipse.persistence.exceptions.IntegrityException) IOException(java.io.IOException) ValidationException(org.eclipse.persistence.exceptions.ValidationException) EclipseLinkException(org.eclipse.persistence.exceptions.EclipseLinkException) PrivilegedActionException(java.security.PrivilegedActionException) IOException(java.io.IOException) OptimisticLockException(jakarta.persistence.OptimisticLockException) DatabaseException(org.eclipse.persistence.exceptions.DatabaseException) DescriptorException(org.eclipse.persistence.exceptions.DescriptorException) RemoteException(java.rmi.RemoteException) IntegrityException(org.eclipse.persistence.exceptions.IntegrityException) EntityManagerSetupException(org.eclipse.persistence.exceptions.EntityManagerSetupException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ConversionException(org.eclipse.persistence.exceptions.ConversionException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) PersistenceException(jakarta.persistence.PersistenceException) MalformedURLException(java.net.MalformedURLException) PersistenceUnitLoadingException(org.eclipse.persistence.exceptions.PersistenceUnitLoadingException) MetadataProject(org.eclipse.persistence.internal.jpa.metadata.MetadataProject) Project(org.eclipse.persistence.sessions.Project) DatabaseLogin(org.eclipse.persistence.sessions.DatabaseLogin) DatabaseSessionImpl(org.eclipse.persistence.internal.sessions.DatabaseSessionImpl) PersistenceException(jakarta.persistence.PersistenceException) XMLSessionConfigLoader(org.eclipse.persistence.sessions.factories.XMLSessionConfigLoader) PrivilegedNewInstanceFromClass(org.eclipse.persistence.internal.security.PrivilegedNewInstanceFromClass) MetadataClass(org.eclipse.persistence.internal.jpa.metadata.accessors.objects.MetadataClass) PersistenceUnitTransactionType(jakarta.persistence.spi.PersistenceUnitTransactionType) Map(java.util.Map) ConcurrentMap(java.util.concurrent.ConcurrentMap) IdentityMap(org.eclipse.persistence.internal.identitymaps.IdentityMap) HashMap(java.util.HashMap) MetadataProcessor(org.eclipse.persistence.internal.jpa.metadata.MetadataProcessor) Writer(java.io.Writer) FileWriter(java.io.FileWriter) Session(org.eclipse.persistence.sessions.Session) RemoteSession(org.eclipse.persistence.sessions.remote.RemoteSession) ServerSession(org.eclipse.persistence.sessions.server.ServerSession) AbstractSession(org.eclipse.persistence.internal.sessions.AbstractSession)

Example 2 with MetadataProcessor

use of org.eclipse.persistence.internal.jpa.metadata.MetadataProcessor in project eclipselink by eclipse-ee4j.

the class EntityManagerSetupImpl method predeployCompositeMembers.

protected void predeployCompositeMembers(Map predeployProperties, ClassLoader tempClassLoader) {
    // get all puInfos found in jar-files specified in composite's persistence.xml
    // all these puInfos are not composite because composites are recursively "taken apart", too.
    Set<SEPersistenceUnitInfo> compositeMemberPuInfos = getCompositeMemberPuInfoSet(persistenceUnitInfo, predeployProperties);
    // makes sure each member has a non-null property, overrides where required properties with composite's predeploy properties.
    updateCompositeMembersProperties(compositeMemberPuInfos, predeployProperties);
    // Don't log these properties - may contain passwords. The properties will be logged by contained persistence units.
    Map compositeMemberMapOfProperties = (Map) getConfigProperty(PersistenceUnitProperties.COMPOSITE_UNIT_PROPERTIES, predeployProperties);
    this.compositeMemberEmSetupImpls = new HashSet<>(compositeMemberPuInfos.size());
    this.processor = new MetadataProcessor();
    if (enableWeaving) {
        this.weaver = new PersistenceWeaver(new HashMap<String, ClassDetails>());
    }
    // all composite members should complete a stage before any of them can move to the next one.
    for (SEPersistenceUnitInfo compositeMemberPuInfo : compositeMemberPuInfos) {
        // set composite's temporary classloader
        compositeMemberPuInfo.setNewTempClassLoader(tempClassLoader);
        String containedPuName = compositeMemberPuInfo.getPersistenceUnitName();
        EntityManagerSetupImpl containedEmSetupImpl = new EntityManagerSetupImpl(containedPuName, containedPuName);
        // set composite
        containedEmSetupImpl.setCompositeEmSetupImpl(this);
        // non-null only in case predeploy is used for static weaving
        containedEmSetupImpl.setStaticWeaveInfo(this.staticWeaveInfo);
        // the properties guaranteed to be non-null after updateCompositeMemberProperties call
        Map compositeMemberProperties = (Map) compositeMemberMapOfProperties.get(containedPuName);
        containedEmSetupImpl.predeploy(compositeMemberPuInfo, compositeMemberProperties);
        // reset temporary classloader back to the original
        compositeMemberPuInfo.setNewTempClassLoader(compositeMemberPuInfo.getClassLoader());
        this.compositeMemberEmSetupImpls.add(containedEmSetupImpl);
    }
    // mode = COMPOSITE_MEMBER_MIDDLE mode
    for (EntityManagerSetupImpl containedEmSetupImpl : this.compositeMemberEmSetupImpls) {
        // properties not used, puInfo already set
        containedEmSetupImpl.predeploy(null, null);
    }
    // mode = COMPOSITE_MEMBER_FINAL mode
    for (EntityManagerSetupImpl containedEmSetupImpl : this.compositeMemberEmSetupImpls) {
        // properties not used, puInfo already set
        PersistenceWeaver containedWeaver = (PersistenceWeaver) containedEmSetupImpl.predeploy(null, null);
        // if both composite and composite member weavings enabled copy class details from member's weaver to composite's one.
        if (enableWeaving && containedWeaver != null) {
            this.weaver.getClassDetailsMap().putAll(containedWeaver.getClassDetailsMap());
        }
    }
    if (enableWeaving && this.weaver.getClassDetailsMap().isEmpty()) {
        this.weaver = null;
    }
}
Also used : HashMap(java.util.HashMap) EntityManagerFactoryProvider.getConfigPropertyAsString(org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.getConfigPropertyAsString) SEPersistenceUnitInfo(org.eclipse.persistence.internal.jpa.deployment.SEPersistenceUnitInfo) Map(java.util.Map) ConcurrentMap(java.util.concurrent.ConcurrentMap) IdentityMap(org.eclipse.persistence.internal.identitymaps.IdentityMap) HashMap(java.util.HashMap) MetadataProcessor(org.eclipse.persistence.internal.jpa.metadata.MetadataProcessor) PersistenceWeaver(org.eclipse.persistence.internal.jpa.weaving.PersistenceWeaver)

Example 3 with MetadataProcessor

use of org.eclipse.persistence.internal.jpa.metadata.MetadataProcessor 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 4 with MetadataProcessor

use of org.eclipse.persistence.internal.jpa.metadata.MetadataProcessor 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 5 with MetadataProcessor

use of org.eclipse.persistence.internal.jpa.metadata.MetadataProcessor 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)

Aggregations

MetadataProcessor (org.eclipse.persistence.internal.jpa.metadata.MetadataProcessor)12 HashMap (java.util.HashMap)10 Map (java.util.Map)10 Project (org.eclipse.persistence.sessions.Project)10 JAXBException (jakarta.xml.bind.JAXBException)9 DatabaseSessionImpl (org.eclipse.persistence.internal.sessions.DatabaseSessionImpl)9 DatabaseLogin (org.eclipse.persistence.sessions.DatabaseLogin)9 JAXBContext (jakarta.xml.bind.JAXBContext)8 Unmarshaller (jakarta.xml.bind.Unmarshaller)8 StringReader (java.io.StringReader)8 StreamSource (javax.xml.transform.stream.StreamSource)8 Platform (org.eclipse.persistence.internal.databaseaccess.Platform)8 ConversionManager (org.eclipse.persistence.internal.helper.ConversionManager)8 XRDynamicClassLoader (org.eclipse.persistence.internal.xr.XRDynamicClassLoader)8 XmlBindingsModel (org.eclipse.persistence.internal.xr.XmlBindingsModel)8 XmlBindings (org.eclipse.persistence.jaxb.xmlmodel.XmlBindings)8 XMLContext (org.eclipse.persistence.oxm.XMLContext)8 XMLPlatform (org.eclipse.persistence.platform.xml.XMLPlatform)8 DatabaseSession (org.eclipse.persistence.sessions.DatabaseSession)8 DatasourceLogin (org.eclipse.persistence.sessions.DatasourceLogin)8