Search in sources :

Example 6 with Project

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();
            }
        }
    }
}
Also used : Project(org.eclipse.persistence.sessions.Project) EclipseLinkException(org.eclipse.persistence.exceptions.EclipseLinkException) EclipseLinkException(org.eclipse.persistence.exceptions.EclipseLinkException) DescriptorException(org.eclipse.persistence.exceptions.DescriptorException) IntegrityException(org.eclipse.persistence.exceptions.IntegrityException)

Example 7 with Project

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));
}
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 8 with Project

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;
}
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)

Example 9 with Project

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;
}
Also used : Project(org.eclipse.persistence.sessions.Project) ValidationException(org.eclipse.persistence.exceptions.ValidationException) 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 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));
}
Also used : ObjectPersistenceWorkbenchXMLProject(org.eclipse.persistence.internal.sessions.factories.ObjectPersistenceWorkbenchXMLProject) Project(org.eclipse.persistence.sessions.Project) Field(java.lang.reflect.Field) ObjectPersistenceWorkbenchXMLProject(org.eclipse.persistence.internal.sessions.factories.ObjectPersistenceWorkbenchXMLProject) TransformerBasedFieldTransformation(org.eclipse.persistence.internal.descriptors.TransformerBasedFieldTransformation) XMLContext(org.eclipse.persistence.oxm.XMLContext) XMLMarshaller(org.eclipse.persistence.oxm.XMLMarshaller) StringReader(java.io.StringReader) XMLTransformationMapping(org.eclipse.persistence.oxm.mappings.XMLTransformationMapping) Document(org.w3c.dom.Document) ConstantTransformer(org.eclipse.persistence.mappings.transformers.ConstantTransformer) Test(org.junit.Test)

Aggregations

Project (org.eclipse.persistence.sessions.Project)216 StringReader (java.io.StringReader)92 ObjectPersistenceWorkbenchXMLProject (org.eclipse.persistence.internal.sessions.factories.ObjectPersistenceWorkbenchXMLProject)83 Test (org.junit.Test)83 XMLContext (org.eclipse.persistence.oxm.XMLContext)80 NonJDBCTestHelper.buildTestProject (org.eclipse.persistence.testing.tests.nonJDBC.NonJDBCTestHelper.buildTestProject)60 NonJDBCTestHelper.buildWorkbenchXMLProject (org.eclipse.persistence.testing.tests.nonJDBC.NonJDBCTestHelper.buildWorkbenchXMLProject)60 Document (org.w3c.dom.Document)53 XMLMarshaller (org.eclipse.persistence.oxm.XMLMarshaller)49 PLSQLStoredProcedureCall (org.eclipse.persistence.platform.database.oracle.plsql.PLSQLStoredProcedureCall)37 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)30 DatabaseLogin (org.eclipse.persistence.sessions.DatabaseLogin)28 XMLDescriptor (org.eclipse.persistence.oxm.XMLDescriptor)27 XMLLogin (org.eclipse.persistence.oxm.XMLLogin)25 SchemaModelProject (org.eclipse.persistence.internal.oxm.schema.SchemaModelProject)24 DatabaseSession (org.eclipse.persistence.sessions.DatabaseSession)23 DataModifyQuery (org.eclipse.persistence.queries.DataModifyQuery)22 Schema (org.eclipse.persistence.internal.oxm.schema.model.Schema)17 Descriptor (org.eclipse.persistence.internal.oxm.mappings.Descriptor)16 XMLUnmarshaller (org.eclipse.persistence.oxm.XMLUnmarshaller)16