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());
}
}
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 ");
}
}
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));
}
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.
}
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;
}
Aggregations