use of org.eclipse.persistence.sessions.Project in project eclipselink by eclipse-ee4j.
the class ConstructorTest method test.
@Override
public void test() {
org.eclipse.persistence.sessions.DatabaseSession testSession = null;
try {
Project project = new ConstructorProject();
project.setLogin(getSession().getLogin());
testSession = project.createDatabaseSession();
testSession.dontLogMessages();
testSession.login();
} catch (org.eclipse.persistence.exceptions.EclipseLinkException exception) {
caughtException = exception;
} catch (Exception e) {
throw new org.eclipse.persistence.testing.framework.TestWarningException("A non-TopLink exception is caught.");
} finally {
if (testSession != null) {
if (testSession.isConnected()) {
testSession.logout();
}
}
}
}
use of org.eclipse.persistence.sessions.Project 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.sessions.Project 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;
}
use of org.eclipse.persistence.sessions.Project in project eclipselink by eclipse-ee4j.
the class SessionsFactory method loadProjectConfig.
/**
* INTERNAL:
* Load a projectConfig from the session.xml file. This method will determine
* the proper loading scheme, that is, for a class or xml project.
*/
@SuppressWarnings({ "unchecked" })
protected Project loadProjectConfig(ProjectConfig projectConfig) {
Project project = null;
String projectString = projectConfig.getProjectString().trim();
if (projectConfig.isProjectClassConfig()) {
try {
if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()) {
project = AccessController.doPrivileged(new PrivilegedNewInstanceFromClass<>((Class<Project>) m_classLoader.loadClass(projectString)));
} else {
project = PrivilegedAccessHelper.newInstanceFromClass((Class<Project>) m_classLoader.loadClass(projectString));
}
} catch (Exception exception) {
throw SessionLoaderException.failedToLoadProjectClass(projectString, exception);
}
} else {
try {
project = XMLProjectReader.read(projectString, m_classLoader);
} catch (ValidationException validationException) {
if (validationException.getErrorCode() == ValidationException.PROJECT_XML_NOT_FOUND) {
try {
project = XMLProjectReader.read(projectString);
} catch (Exception e) {
throw SessionLoaderException.failedToLoadProjectXml(projectString, validationException);
}
} else {
throw SessionLoaderException.failedToLoadProjectXml(projectString, validationException);
}
}
}
return project;
}
use of org.eclipse.persistence.sessions.Project in project eclipselink by eclipse-ee4j.
the class PLSQLcollectionTestSuite method toProjectXML.
@Test
public void toProjectXML() throws IllegalArgumentException, IllegalAccessException, SecurityException, NoSuchFieldException {
ObjectPersistenceWorkbenchXMLProject runtimeProject = new ObjectPersistenceWorkbenchXMLProject();
XMLTransformationMapping versionMapping = (XMLTransformationMapping) runtimeProject.getDescriptor(Project.class).getMappings().get(0);
TransformerBasedFieldTransformation versionTransformer = (TransformerBasedFieldTransformation) versionMapping.getFieldTransformations().get(0);
Field transformerField = TransformerBasedFieldTransformation.class.getDeclaredField("transformer");
transformerField.setAccessible(true);
ConstantTransformer constantTransformer = (ConstantTransformer) transformerField.get(versionTransformer);
constantTransformer.setValue(CONSTANT_PROJECT_BUILD_VERSION);
XMLContext context = new XMLContext(runtimeProject);
XMLMarshaller marshaller = context.createMarshaller();
Document testDoc = marshaller.objectToXML(project);
Document controlDoc = xmlParser.parse(new StringReader(TEST_PROJECT_CONTROL_DOC));
assertTrue("control document not same as instance document", comparer.isNodeEqual(controlDoc, testDoc));
}
Aggregations