Search in sources :

Example 6 with DatabaseSessionImpl

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

the class SessionIsConnectedFlagTest method test.

@Override
public void test() {
    if (!getSession().isDatabaseSession()) {
        throwWarning("Test is designed to be run with DatabaseSession");
    }
    DatabaseSession session = (DatabaseSession) getSession();
    // session needs to be verified as connected
    assertTrue("Session isConnected should be true before logout", session.isConnected());
    // test session's accessors
    for (Accessor accessor : ((DatabaseSessionImpl) session).getAccessors()) {
        assertTrue(accessor.isConnected());
    }
    // logout session and test that the isConnected flag is false
    session.logout();
    assertFalse("Session isConnected should be false after logout", session.isConnected());
    // test session's accessors
    for (Accessor accessor : ((DatabaseSessionImpl) session).getAccessors()) {
        assertFalse(accessor.isConnected());
    }
    // login session and test that the isConnected flag is true
    session.login();
    assertTrue("Session isConnected should be true after login", session.isConnected());
    // test session's accessors
    for (Accessor accessor : ((DatabaseSessionImpl) session).getAccessors()) {
        assertTrue(accessor.isConnected());
    }
}
Also used : DatabaseSession(org.eclipse.persistence.sessions.DatabaseSession) DatabaseSessionImpl(org.eclipse.persistence.internal.sessions.DatabaseSessionImpl) Accessor(org.eclipse.persistence.internal.databaseaccess.Accessor)

Example 7 with DatabaseSessionImpl

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

the class ShouldCheckDatabaseTest method test.

@Override
public void test() {
    EmployeeProjectForDatabaseChecking project = new EmployeeProjectForDatabaseChecking();
    project.setDatasourceLogin(getSession().getDatasourceLogin());
    DatabaseSessionImpl session = (DatabaseSessionImpl) new Project(getSession().getDatasourceLogin()).createDatabaseSession();
    boolean caughtError = false;
    try {
        session.setSessionLog(getSession().getSessionLog());
        session.login();
        session.setIntegrityChecker(new IntegrityChecker());
        session.getIntegrityChecker().checkDatabase();
        session.addDescriptors(project);
    } catch (IntegrityException integrityException) {
        if (integrityException.getIntegrityChecker().getCaughtExceptions().size() != 5) {
            throw new TestErrorException("" + integrityException.getIntegrityChecker().getCaughtExceptions().size() + "  Not equal to the Number of Exceptions to the expected 5.");
        }
        caughtError = true;
    } finally {
        session.logout();
    }
    if (!caughtError) {
        throw new TestErrorException("Test is Failed, no database error ");
    }
}
Also used : DatabaseSessionImpl(org.eclipse.persistence.internal.sessions.DatabaseSessionImpl)

Example 8 with DatabaseSessionImpl

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

the class FailoverBase method prepare.

@Before
public void prepare() {
    DatabaseLogin login = new DatabaseLogin();
    login.useDirectDriverConnect();
    login.setDriverClass(EmulatedDriver.class);
    login.setConnectionString("jdbc:emulateddriver");
    login.getPlatform().setPingSQL("SELECT 1");
    Project p = new Project(login);
    ClassDescriptor cd = Address.descriptor();
    p.addDescriptor(cd);
    session = createSession(p);
    SessionLog log = new DefaultSessionLog(new OutputStreamWriter(System.out));
    int logLevel = AbstractSessionLog.translateStringToLoggingLevel(System.getProperty(PersistenceUnitProperties.LOGGING_LEVEL, "INFO"));
    session.setSessionLog(log);
    session.setLogLevel(logLevel);
    session.login();
    // this will actually store the results on the driver for subsequent connections.
    EmulatedConnection con = (EmulatedConnection) ((DatabaseSessionImpl) session).getAccessor().getConnection();
    Vector<DatabaseField> pingFields = new Vector<DatabaseField>() {

        {
            add(new DatabaseField("1"));
        }
    };
    con.putRows("SELECT 1", new Vector() {

        {
            add(new ArrayRecord(pingFields, pingFields.toArray(new DatabaseField[0]), new Object[] { "1" }));
        }
    });
    con.putRows(Address.getSQL(), Address.getData(cd));
}
Also used : ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) EmulatedConnection(org.eclipse.persistence.testing.tests.junit.failover.emulateddriver.EmulatedConnection) ArrayRecord(org.eclipse.persistence.internal.sessions.ArrayRecord) DatabaseLogin(org.eclipse.persistence.sessions.DatabaseLogin) Project(org.eclipse.persistence.sessions.Project) AbstractSessionLog(org.eclipse.persistence.logging.AbstractSessionLog) DefaultSessionLog(org.eclipse.persistence.logging.DefaultSessionLog) SessionLog(org.eclipse.persistence.logging.SessionLog) DatabaseSessionImpl(org.eclipse.persistence.internal.sessions.DatabaseSessionImpl) DatabaseField(org.eclipse.persistence.internal.helper.DatabaseField) DefaultSessionLog(org.eclipse.persistence.logging.DefaultSessionLog) OutputStreamWriter(java.io.OutputStreamWriter) Vector(java.util.Vector) Before(org.junit.Before)

Example 9 with DatabaseSessionImpl

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

the class SessionsFactory method processSessionConfig.

/**
 * INTERNAL:
 * Process the common elements from a SessionConfig.
 */
protected void processSessionConfig(SessionConfig sessionConfig, AbstractSession session) {
    // Name
    session.setName(sessionConfig.getName().trim());
    // Session Event Manager
    processSessionEventManagerConfig(sessionConfig.getSessionEventManagerConfig(), session);
    // server platform
    ((DatabaseSessionImpl) session).setServerPlatform(buildServerPlatformConfig(sessionConfig.getServerPlatformConfig(), (DatabaseSessionImpl) session));
    // Session Log - BUG# 3442865, don't set the log if it is null
    SessionLog log = buildSessionLog(sessionConfig.getLogConfig(), session);
    if (log != null) {
        session.setSessionLog(log);
    }
    // Remote command manager
    buildRemoteCommandManagerConfig(sessionConfig.getRemoteCommandManagerConfig(), session);
    // Profiler - XML Schema default is null
    if (sessionConfig.getProfiler() != null) {
        if (sessionConfig.getProfiler().equals("eclipselink")) {
            session.setProfiler(new PerformanceProfiler());
        }
    }
    // Exception handler
    String exceptionHandlerClassName = sessionConfig.getExceptionHandlerClass();
    if (exceptionHandlerClassName != null) {
        try {
            @SuppressWarnings({ "unchecked" }) Class<ExceptionHandler> exceptionHandlerClass = (Class<ExceptionHandler>) m_classLoader.loadClass(exceptionHandlerClassName);
            if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()) {
                session.setExceptionHandler(AccessController.doPrivileged(new PrivilegedNewInstanceFromClass<>(exceptionHandlerClass)));
            } else {
                session.setExceptionHandler(PrivilegedAccessHelper.newInstanceFromClass(exceptionHandlerClass));
            }
        } catch (Exception e) {
            throw SessionLoaderException.failedToLoadTag("exception-handler-class", exceptionHandlerClassName, e);
        }
    }
// Session customizer will be processed in the buildSessions method.
// Ensures it is run last.
}
Also used : ExceptionHandler(org.eclipse.persistence.exceptions.ExceptionHandler) DefaultSessionLog(org.eclipse.persistence.logging.DefaultSessionLog) SessionLog(org.eclipse.persistence.logging.SessionLog) PerformanceProfiler(org.eclipse.persistence.tools.profiler.PerformanceProfiler) DatabaseSessionImpl(org.eclipse.persistence.internal.sessions.DatabaseSessionImpl) PrivilegedNewInstanceFromClass(org.eclipse.persistence.internal.security.PrivilegedNewInstanceFromClass) PrivilegedNewInstanceFromClass(org.eclipse.persistence.internal.security.PrivilegedNewInstanceFromClass) ValidationException(org.eclipse.persistence.exceptions.ValidationException) PrivilegedActionException(java.security.PrivilegedActionException) SessionLoaderException(org.eclipse.persistence.exceptions.SessionLoaderException)

Example 10 with DatabaseSessionImpl

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

the class SessionsFactory method createSession.

/**
 * INTERNAL:
 * Return a DatabaseSession object from it's config object using either
 * the project classes or project XML files.
 */
protected DatabaseSessionImpl createSession(DatabaseSessionConfig sessionConfig, Login login) {
    Project primaryProject;
    if (sessionConfig.getPrimaryProject() != null) {
        primaryProject = loadProjectConfig(sessionConfig.getPrimaryProject());
    } else {
        // Build a session from an empty project
        primaryProject = new Project();
    }
    prepareProjectLogin(primaryProject, login);
    DatabaseSessionImpl sessionToReturn = getSession(sessionConfig, primaryProject);
    // to the mainProject
    if (sessionConfig.getAdditionalProjects() != null) {
        Enumeration<ProjectConfig> additionalProjects = sessionConfig.getAdditionalProjects().elements();
        while (additionalProjects.hasMoreElements()) {
            Project subProject = loadProjectConfig(additionalProjects.nextElement());
            primaryProject.addDescriptors(subProject, sessionToReturn);
        }
    }
    return sessionToReturn;
}
Also used : ProjectConfig(org.eclipse.persistence.internal.sessions.factories.model.project.ProjectConfig) Project(org.eclipse.persistence.sessions.Project) DatabaseSessionImpl(org.eclipse.persistence.internal.sessions.DatabaseSessionImpl)

Aggregations

DatabaseSessionImpl (org.eclipse.persistence.internal.sessions.DatabaseSessionImpl)64 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)18 EntityManager (jakarta.persistence.EntityManager)15 HashMap (java.util.HashMap)14 DatabaseSession (org.eclipse.persistence.sessions.DatabaseSession)14 Map (java.util.Map)13 DatabaseLogin (org.eclipse.persistence.sessions.DatabaseLogin)13 Project (org.eclipse.persistence.sessions.Project)12 StringReader (java.io.StringReader)9 StreamSource (javax.xml.transform.stream.StreamSource)9 Platform (org.eclipse.persistence.internal.databaseaccess.Platform)9 MetadataProcessor (org.eclipse.persistence.internal.jpa.metadata.MetadataProcessor)9 AbstractSession (org.eclipse.persistence.internal.sessions.AbstractSession)9 XMLContext (org.eclipse.persistence.oxm.XMLContext)9 DatasourceLogin (org.eclipse.persistence.sessions.DatasourceLogin)9 JAXBContext (jakarta.xml.bind.JAXBContext)8 JAXBException (jakarta.xml.bind.JAXBException)8 Unmarshaller (jakarta.xml.bind.Unmarshaller)8 ConversionManager (org.eclipse.persistence.internal.helper.ConversionManager)8 XRDynamicClassLoader (org.eclipse.persistence.internal.xr.XRDynamicClassLoader)8