Search in sources :

Example 1 with DatasourceLogin

use of org.eclipse.persistence.sessions.DatasourceLogin in project eclipselink by eclipse-ee4j.

the class MetadataProject method processSequencingAccessors.

/**
 * INTERNAL:
 * Process the sequencing information. At this point, through validation, it
 * is not possible to have:
 *   1 - a table generator with the generator name equal to
 *       DEFAULT_SEQUENCE_GENERATOR or DEFAULT_IDENTITY_GENERATOR
 *   2 - a sequence generator with the name eqaul to DEFAULT_TABLE_GENERATOR
 *       or DEFAULT_IDENTITY_GENERATOR
 *   3 - you can't have both a sequence generator and a table generator with
 *       the same DEFAULT_AUTO_GENERATOR name.
 *
 * @see addTableGenerator and addSequenceGenerator.
 */
protected void processSequencingAccessors() {
    if (!m_generatedValues.isEmpty()) {
        // 1 - Build our map of sequences keyed on generator names.
        Hashtable<String, Sequence> sequences = new Hashtable<String, Sequence>();
        for (SequenceGeneratorMetadata sequenceGenerator : m_sequenceGenerators.values()) {
            sequences.put(sequenceGenerator.getName(), sequenceGenerator.process(m_logger));
        }
        for (UuidGeneratorMetadata uuidGenerator : m_uuidGenerators.values()) {
            sequences.put(uuidGenerator.getName(), uuidGenerator.process(m_logger));
        }
        for (TableGeneratorMetadata tableGenerator : m_tableGenerators.values()) {
            sequences.put(tableGenerator.getGeneratorName(), tableGenerator.process(m_logger));
        }
        // create them using the Table and Sequence generator metadata.
        if (!sequences.containsKey(DEFAULT_TABLE_GENERATOR)) {
            TableGeneratorMetadata tableGenerator = new TableGeneratorMetadata(DEFAULT_TABLE_GENERATOR);
            // This code was attempting to use the platform default sequence name,
            // however the platform has not been set yet, so it would never work,
            // it was also causing the platform default sequence to be set, causing the DatabasePlatform default to be used,
            // so I am removing this code, as it breaks the platform default sequence and does not work.
            // Sequence seq = m_session.getDatasourcePlatform().getDefaultSequence();
            // Using "" as the default should make the platform default it.
            String defaultTableGeneratorName = "";
            // Process the default values.
            processTable(tableGenerator, defaultTableGeneratorName, getPersistenceUnitDefaultCatalog(), getPersistenceUnitDefaultSchema(), tableGenerator);
            sequences.put(DEFAULT_TABLE_GENERATOR, tableGenerator.process(m_logger));
        }
        if (!sequences.containsKey(DEFAULT_SEQUENCE_GENERATOR)) {
            sequences.put(DEFAULT_SEQUENCE_GENERATOR, new SequenceGeneratorMetadata(DEFAULT_SEQUENCE_GENERATOR, getPersistenceUnitDefaultCatalog(), getPersistenceUnitDefaultSchema()).process(m_logger));
        }
        if (!sequences.containsKey(DEFAULT_IDENTITY_GENERATOR)) {
            sequences.put(DEFAULT_IDENTITY_GENERATOR, new SequenceGeneratorMetadata(DEFAULT_IDENTITY_GENERATOR, 1, getPersistenceUnitDefaultCatalog(), getPersistenceUnitDefaultSchema(), true).process(m_logger));
        }
        if (!sequences.containsKey(DEFAULT_UUID_GENERATOR)) {
            sequences.put(DEFAULT_UUID_GENERATOR, new UuidGeneratorMetadata().process(m_logger));
        }
        // Use a temporary sequence generator to build a qualifier to set on
        // the default generator. Don't use this generator as the default
        // auto generator though.
        SequenceGeneratorMetadata tempGenerator = new SequenceGeneratorMetadata(DEFAULT_AUTO_GENERATOR, getPersistenceUnitDefaultCatalog(), getPersistenceUnitDefaultSchema());
        DatasourceLogin login = m_session.getProject().getLogin();
        login.setTableQualifier(tempGenerator.processQualifier());
        // 3 - Loop through generated values and set sequences for each.
        for (MetadataClass entityClass : m_generatedValues.keySet()) {
            // Skip setting sequences if our accessor is null, must be a mapped superclass
            ClassAccessor accessor = m_allAccessors.get(entityClass.getName());
            if (accessor != null) {
                m_generatedValues.get(entityClass).process(accessor.getDescriptor(), sequences, login);
            }
        }
    }
}
Also used : DatasourceLogin(org.eclipse.persistence.sessions.DatasourceLogin) SequenceGeneratorMetadata(org.eclipse.persistence.internal.jpa.metadata.sequencing.SequenceGeneratorMetadata) UuidGeneratorMetadata(org.eclipse.persistence.internal.jpa.metadata.sequencing.UuidGeneratorMetadata) MetadataClass(org.eclipse.persistence.internal.jpa.metadata.accessors.objects.MetadataClass) ClassAccessor(org.eclipse.persistence.internal.jpa.metadata.accessors.classes.ClassAccessor) Hashtable(java.util.Hashtable) TableGeneratorMetadata(org.eclipse.persistence.internal.jpa.metadata.sequencing.TableGeneratorMetadata) Sequence(org.eclipse.persistence.sequencing.Sequence)

Example 2 with DatasourceLogin

use of org.eclipse.persistence.sessions.DatasourceLogin in project eclipselink by eclipse-ee4j.

the class EntityManagerSetupImpl method updateSession.

/**
 * Make any changes to our ServerSession that can be made after it is created.
 */
protected void updateSession(Map m, ClassLoader loader) {
    if (session == null || (session.isDatabaseSession() && ((DatabaseSessionImpl) session).isLoggedIn())) {
        return;
    }
    // In deploy ServerPlatform could've changed which will affect the loggers.
    boolean serverPlatformChanged = updateServerPlatform(m, loader);
    updateJPQLParser(m);
    if (!session.hasBroker()) {
        updateLoggers(m, serverPlatformChanged, loader);
        updateProfiler(m, loader);
    }
    // log the server platform being used by the session if it has been changed
    if (serverPlatformChanged && session.getSessionLog().shouldLog(SessionLog.FINE)) {
        session.getSessionLog().log(SessionLog.FINE, SessionLog.SERVER, "configured_server_platform", // NOI18N
        session.getServerPlatform().getClass().getName());
    }
    if (session.isBroker()) {
        PersistenceUnitTransactionType transactionType = persistenceUnitInfo.getTransactionType();
        // bug 5867753: find and override the transaction type using properties
        String transTypeString = getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.TRANSACTION_TYPE, m, session);
        if (transTypeString != null) {
            transactionType = PersistenceUnitTransactionType.valueOf(transTypeString);
        }
        ((DatasourceLogin) session.getDatasourceLogin()).setUsesExternalTransactionController(transactionType == PersistenceUnitTransactionType.JTA);
    } else {
        String shouldBindString = getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.JDBC_BIND_PARAMETERS, m, session);
        if (shouldBindString != null) {
            session.getPlatform().setShouldBindAllParameters(Boolean.parseBoolean(shouldBindString));
        }
        String shouldForceBindString = getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.JDBC_FORCE_BIND_PARAMETERS, m, session);
        if (shouldForceBindString != null) {
            session.getPlatform().setShouldForceBindAllParameters(Boolean.parseBoolean(shouldForceBindString));
        }
        updateLogins(m);
    }
    if (!session.getDatasourceLogin().shouldUseExternalTransactionController()) {
        session.getServerPlatform().disableJTA();
    }
    if (session.isServerSession()) {
        updatePools((ServerSession) session, m);
        updateConnectionSettings((ServerSession) session, m);
        if (!isSessionLoadedFromSessionsXML) {
            updateDescriptorCacheSettings(m, loader);
        }
        updateConnectionPolicy((ServerSession) session, m);
    }
    if (session.isBroker()) {
        if (this.compositeMemberEmSetupImpls != null) {
            // composite
            Map compositeMemberMapOfProperties = (Map) getConfigProperty(PersistenceUnitProperties.COMPOSITE_UNIT_PROPERTIES, m);
            for (EntityManagerSetupImpl compositeMemberEmSetupImpl : this.compositeMemberEmSetupImpls) {
                // the properties guaranteed to be non-null after updateCompositeMemberProperties call
                String compositeMemberPuName = compositeMemberEmSetupImpl.getPersistenceUnitInfo().getPersistenceUnitName();
                Map compositeMemberProperties = (Map) compositeMemberMapOfProperties.get(compositeMemberPuName);
                // debug output added to make it easier to navigate the log because the method is called outside of composite member deploy
                compositeMemberEmSetupImpl.session.log(SessionLog.FINEST, SessionLog.PROPERTIES, "composite_member_begin_call", new Object[] { "updateSession", compositeMemberPuName, state });
                compositeMemberEmSetupImpl.updateSession(compositeMemberProperties, loader);
                compositeMemberEmSetupImpl.session.log(SessionLog.FINEST, SessionLog.PROPERTIES, "composite_member_end_call", new Object[] { "updateSession", compositeMemberPuName, state });
            }
        }
        setSessionEventListener(m, loader);
        setExceptionHandler(m, loader);
        updateAllowZeroIdSetting(m);
        updateCacheCoordination(m, loader);
        processSessionCustomizer(m, loader);
    } else {
        setSessionEventListener(m, loader);
        setExceptionHandler(m, loader);
        updateBatchWritingSetting(m, loader);
        updateNativeSQLSetting(m);
        updateSequencing(m);
        updateSequencingStart(m);
        updateAllowNativeSQLQueriesSetting(m);
        updateSQLCastSetting(m);
        updateUppercaseSetting(m);
        updateCacheStatementSettings(m);
        updateAllowExtendedCacheLogging(m);
        updateAllowExtendedThreadLogging(m);
        updateAllowExtendedThreadLoggingThreadDump(m);
        updateTemporalMutableSetting(m);
        updateTableCreationSettings(m);
        updateIndexForeignKeys(m);
        if (!session.hasBroker()) {
            updateAllowZeroIdSetting(m);
        }
        updateIdValidation(m);
        updatePessimisticLockTimeout(m);
        updatePessimisticLockTimeoutUnit(m);
        updateQueryTimeout(m);
        updateQueryTimeoutUnit(m);
        updateLockingTimestampDefault(m);
        updateSQLCallDeferralDefault(m);
        updateNamingIntoIndexed(m);
        if (!session.hasBroker()) {
            updateCacheCoordination(m, loader);
        }
        updatePartitioning(m, loader);
        updateDatabaseEventListener(m, loader);
        updateSerializer(m, loader);
        updateShouldOptimizeResultSetAccess(m);
        updateTolerateInvalidJPQL(m);
        updateTenancy(m, loader);
        // ConcurrencyManager properties
        updateConcurrencyManagerWaitTime(m);
        updateConcurrencyManagerBuildObjectCompleteWaitTime(m);
        updateConcurrencyManagerMaxAllowedSleepTime(m);
        updateConcurrencyManagerMaxAllowedFrequencyToProduceTinyDumpLogMessage(m);
        updateConcurrencyManagerMaxAllowedFrequencyToProduceMassiveDumpLogMessage(m);
        updateConcurrencyManagerAllowInterruptedExceptionFired(m);
        updateConcurrencyManagerAllowConcurrencyExceptionToBeFiredUp(m);
        updateConcurrencyManagerAllowTakingStackTraceDuringReadLockAcquisition(m);
        updateConcurrencyManagerUseObjectBuildingSemaphore(m);
        updateConcurrencyManagerUseWriteLockManagerSemaphore(m);
        updateConcurrencyManagerNoOfThreadsAllowedToObjectBuildInParallel(m);
        updateConcurrencyManagerNoOfThreadsAllowedToDoWriteLockManagerAcquireRequiredLocksInParallel(m);
        updateConcurrencySemaphoreMaxTimePermit(m);
        updateConcurrencySemaphoreLogTimeout(m);
        // Customizers should be processed last
        processDescriptorCustomizers(m, loader);
        processSessionCustomizer(m, loader);
        setDescriptorNamedQueries(m);
    }
}
Also used : DatasourceLogin(org.eclipse.persistence.sessions.DatasourceLogin) PersistenceUnitTransactionType(jakarta.persistence.spi.PersistenceUnitTransactionType) EntityManagerFactoryProvider.getConfigPropertyAsString(org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.getConfigPropertyAsString) Map(java.util.Map) ConcurrentMap(java.util.concurrent.ConcurrentMap) IdentityMap(org.eclipse.persistence.internal.identitymaps.IdentityMap) HashMap(java.util.HashMap)

Example 3 with DatasourceLogin

use of org.eclipse.persistence.sessions.DatasourceLogin in project eclipselink by eclipse-ee4j.

the class EntityManagerSetupImpl method updatePools.

/**
 * Configure the internal connection pooling parameters.
 * By default if nothing is configured a default shared (exclusive) read/write pool is used with 32 min/max connections and 1 initial.
 */
@SuppressWarnings("deprecation")
protected void updatePools(ServerSession serverSession, Map m) {
    String value = null;
    String property = null;
    try {
        // Sizes are irrelevant for external connection pool
        if (!serverSession.getDefaultConnectionPool().getLogin().shouldUseExternalConnectionPooling()) {
            // CONNECTION and WRITE_CONNECTION properties both configure the default pool (mean the same thing, but WRITE normally used with READ).
            property = PersistenceUnitProperties.JDBC_CONNECTIONS_MIN;
            value = getConfigPropertyAsStringLogDebug(property, m, serverSession);
            if (value != null) {
                serverSession.getDefaultConnectionPool().setMinNumberOfConnections(Integer.parseInt(value));
            }
            property = PersistenceUnitProperties.JDBC_CONNECTIONS_MAX;
            value = getConfigPropertyAsStringLogDebug(property, m, serverSession);
            if (value != null) {
                serverSession.getDefaultConnectionPool().setMaxNumberOfConnections(Integer.parseInt(value));
            }
            property = PersistenceUnitProperties.JDBC_CONNECTIONS_INITIAL;
            value = getConfigPropertyAsStringLogDebug(property, m, serverSession);
            if (value != null) {
                serverSession.getDefaultConnectionPool().setInitialNumberOfConnections(Integer.parseInt(value));
            }
            property = PersistenceUnitProperties.JDBC_WRITE_CONNECTIONS_MIN;
            value = getConfigPropertyAsStringLogDebug(property, m, serverSession);
            if (value != null) {
                serverSession.getDefaultConnectionPool().setMinNumberOfConnections(Integer.parseInt(value));
            }
            property = PersistenceUnitProperties.JDBC_WRITE_CONNECTIONS_MAX;
            value = getConfigPropertyAsStringLogDebug(property, m, serverSession);
            if (value != null) {
                serverSession.getDefaultConnectionPool().setMaxNumberOfConnections(Integer.parseInt(value));
            }
            property = PersistenceUnitProperties.JDBC_WRITE_CONNECTIONS_INITIAL;
            value = getConfigPropertyAsStringLogDebug(property, m, serverSession);
            if (value != null) {
                serverSession.getDefaultConnectionPool().setInitialNumberOfConnections(Integer.parseInt(value));
            }
        }
        // Sizes and shared option are irrelevant for external connection pool
        if (!serverSession.getReadConnectionPool().getLogin().shouldUseExternalConnectionPooling()) {
            String shared = getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.JDBC_READ_CONNECTIONS_SHARED, m, serverSession);
            boolean isShared = false;
            if (shared != null) {
                isShared = Boolean.parseBoolean(shared);
            }
            ConnectionPool pool = null;
            if (isShared) {
                pool = new ReadConnectionPool("read", serverSession.getReadConnectionPool().getLogin(), serverSession);
            } else {
                pool = new ConnectionPool("read", serverSession.getReadConnectionPool().getLogin(), serverSession);
            }
            String min = getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.JDBC_READ_CONNECTIONS_MIN, m, serverSession);
            if (min != null) {
                value = min;
                property = PersistenceUnitProperties.JDBC_READ_CONNECTIONS_MIN;
                pool.setMinNumberOfConnections(Integer.parseInt(min));
            }
            String max = getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.JDBC_READ_CONNECTIONS_MAX, m, serverSession);
            if (max != null) {
                value = max;
                property = PersistenceUnitProperties.JDBC_READ_CONNECTIONS_MAX;
                pool.setMaxNumberOfConnections(Integer.parseInt(max));
            }
            String initial = getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.JDBC_READ_CONNECTIONS_INITIAL, m, serverSession);
            if (initial != null) {
                value = initial;
                property = PersistenceUnitProperties.JDBC_READ_CONNECTIONS_INITIAL;
                pool.setInitialNumberOfConnections(Integer.parseInt(initial));
            }
            // Only set the read pool if they configured it, otherwise use default shared read/write.
            if (isShared || (min != null) || (max != null) || (initial != null)) {
                serverSession.setReadConnectionPool(pool);
            }
            String wait = getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.JDBC_CONNECTIONS_WAIT, m, serverSession);
            if (wait != null) {
                value = wait;
                property = PersistenceUnitProperties.JDBC_CONNECTIONS_WAIT;
                serverSession.getDefaultConnectionPool().setWaitTimeout(Integer.parseInt(wait));
                pool.setWaitTimeout(Integer.parseInt(wait));
            }
        }
        // Configure sequence connection pool if set.
        String sequence = getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.JDBC_SEQUENCE_CONNECTION_POOL, m, serverSession);
        if (sequence != null) {
            serverSession.getSequencingControl().setShouldUseSeparateConnection(Boolean.parseBoolean(sequence));
        }
        String sequenceDataSource = getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.JDBC_SEQUENCE_CONNECTION_POOL_DATASOURCE, m, serverSession);
        if (sequenceDataSource != null) {
            DatasourceLogin login = this.session.getLogin().clone();
            login.dontUseExternalTransactionController();
            JNDIConnector jndiConnector = new JNDIConnector(sequenceDataSource);
            login.setConnector(jndiConnector);
            serverSession.getSequencingControl().setLogin(login);
        }
        // Sizes and shared option are irrelevant for external connection pool
        if (!serverSession.getReadConnectionPool().getLogin().shouldUseExternalConnectionPooling()) {
            value = getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.JDBC_SEQUENCE_CONNECTION_POOL_MIN, m, serverSession);
            if (value != null) {
                property = PersistenceUnitProperties.JDBC_SEQUENCE_CONNECTION_POOL_MIN;
                serverSession.getSequencingControl().setMinPoolSize(Integer.parseInt(value));
            }
            value = getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.JDBC_SEQUENCE_CONNECTION_POOL_MAX, m, serverSession);
            if (value != null) {
                property = PersistenceUnitProperties.JDBC_SEQUENCE_CONNECTION_POOL_MAX;
                serverSession.getSequencingControl().setMaxPoolSize(Integer.parseInt(value));
            }
            value = getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.JDBC_SEQUENCE_CONNECTION_POOL_INITIAL, m, serverSession);
            if (value != null) {
                property = PersistenceUnitProperties.JDBC_SEQUENCE_CONNECTION_POOL_INITIAL;
                serverSession.getSequencingControl().setInitialPoolSize(Integer.parseInt(value));
            }
        }
    } catch (NumberFormatException exception) {
        serverSession.handleException(ValidationException.invalidValueForProperty(value, property, exception));
    }
}
Also used : ExternalConnectionPool(org.eclipse.persistence.sessions.server.ExternalConnectionPool) ReadConnectionPool(org.eclipse.persistence.sessions.server.ReadConnectionPool) ConnectionPool(org.eclipse.persistence.sessions.server.ConnectionPool) DatasourceLogin(org.eclipse.persistence.sessions.DatasourceLogin) ReadConnectionPool(org.eclipse.persistence.sessions.server.ReadConnectionPool) JNDIConnector(org.eclipse.persistence.sessions.JNDIConnector) EntityManagerFactoryProvider.getConfigPropertyAsString(org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.getConfigPropertyAsString)

Example 4 with DatasourceLogin

use of org.eclipse.persistence.sessions.DatasourceLogin 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 5 with DatasourceLogin

use of org.eclipse.persistence.sessions.DatasourceLogin 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)

Aggregations

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