Search in sources :

Example 96 with TestErrorException

use of org.eclipse.persistence.testing.framework.TestErrorException in project eclipselink by eclipse-ee4j.

the class EMCascadingModifyAndMergeTest method test.

@Override
public void test() {
    employee.setFirstName("Ivy");
    PhoneNumber phone = employee.getPhoneNumbers().iterator().next();
    phone.setAreaCode("519");
    phone.setNumber("9876543");
    try {
        CMP3TestModel.createEntityManager();
        beginTransaction();
        Employee emp = getEntityManager().find(Employee.class, empIDs[0]);
        emp.setFirstName("Tobin");
        PhoneNumber phon = emp.getPhoneNumbers().iterator().next();
        phon.setAreaCode("416");
        phon.setNumber("7654321");
        // emp.addPhoneNumber(ModelExamples.phoneExample7());
        getEntityManager().merge(employee);
        commitTransaction();
    } catch (Exception ex) {
        rollbackTransaction();
        ex.printStackTrace();
        throw new TestErrorException("Exception thrown durring persist and flush" + ex);
    }
}
Also used : TestErrorException(org.eclipse.persistence.testing.framework.TestErrorException) TestErrorException(org.eclipse.persistence.testing.framework.TestErrorException)

Example 97 with TestErrorException

use of org.eclipse.persistence.testing.framework.TestErrorException in project eclipselink by eclipse-ee4j.

the class EMCascadingPersistAndCommitTest method test.

@Override
public void test() {
    Employee employee = new Employee();
    employee.setFirstName("First");
    employee.setLastName("Bean");
    Project project = new Project();
    project.setName("Project # 1");
    project.setDescription("A simple Project");
    PhoneNumber phone = new PhoneNumber("Work", "613", "9876543");
    employee.addProject(project);
    employee.addPhoneNumber(phone);
    try {
        beginTransaction();
        getEntityManager().persist(employee);
        empIDs[0] = employee.getId();
        commitTransaction();
    } catch (Exception ex) {
        rollbackTransaction();
        throw new TestErrorException("Exception thrown durring persist and flush" + ex);
    }
}
Also used : TestErrorException(org.eclipse.persistence.testing.framework.TestErrorException) TestErrorException(org.eclipse.persistence.testing.framework.TestErrorException)

Example 98 with TestErrorException

use of org.eclipse.persistence.testing.framework.TestErrorException in project eclipselink by eclipse-ee4j.

the class EMCascadingRemoveAndFlushTest method test.

@Override
public void test() {
    try {
        beginTransaction();
        Employee employee = getEntityManager().find(Employee.class, empIDs[0]);
        for (Iterator<PhoneNumber> phones = employee.getPhoneNumbers().iterator(); phones.hasNext(); ) {
            this.phoneIDs.add(phones.next().buildPK());
        }
        getEntityManager().remove(employee);
        getEntityManager().flush();
        // lets initialize the identity map to make sure they were persisted
        ((JpaEntityManager) getEntityManager()).getServerSession().getIdentityMapAccessor().initializeAllIdentityMaps();
        getEntityManager().clear();
        persistedItems.put("after flush Employee", getEntityManager().find(Employee.class, empIDs[0]));
        for (Iterator<PhoneNumberPK> ids = this.phoneIDs.iterator(); ids.hasNext(); ) {
            PhoneNumber phone = getEntityManager().find(PhoneNumber.class, ids.next());
            if (phone != null) {
                persistedItems.put("after flush PhoneNumber", phone);
            }
        }
        commitTransaction();
    } catch (Exception ex) {
        rollbackTransaction();
        ex.printStackTrace();
        throw new TestErrorException("Exception thrown durring persist and flush" + ex);
    }
}
Also used : JpaEntityManager(org.eclipse.persistence.jpa.JpaEntityManager) TestErrorException(org.eclipse.persistence.testing.framework.TestErrorException) TestErrorException(org.eclipse.persistence.testing.framework.TestErrorException)

Example 99 with TestErrorException

use of org.eclipse.persistence.testing.framework.TestErrorException in project eclipselink by eclipse-ee4j.

the class EMRemoveAndFlushTest method setup.

@Override
public void setup() {
    super.setup();
    persistedItems.clear();
    Employee employee = ModelExamples.employeeExample1();
    Project project = ModelExamples.projectExample1();
    try {
        beginTransaction();
        getEntityManager().persist(employee);
        getEntityManager().persist(project);
        commitTransaction();
    } catch (Exception ex) {
        rollbackTransaction();
        ex.printStackTrace();
        throw new TestErrorException("Exception thrown durring persist and flush" + ex);
    }
    empIDs[0] = employee.getId();
    projIDs[0] = project.getId();
}
Also used : TestErrorException(org.eclipse.persistence.testing.framework.TestErrorException) TestErrorException(org.eclipse.persistence.testing.framework.TestErrorException)

Example 100 with TestErrorException

use of org.eclipse.persistence.testing.framework.TestErrorException in project eclipselink by eclipse-ee4j.

the class UCPUnitOfWorkTests method buildServerSession.

@Override
public Server buildServerSession() {
    try {
        PoolDataSource dataSource = PoolDataSourceFactory.getPoolDataSource();
        // dataSource.setONSConfiguration("nodes=adcdbc01-r.us.oracle.com:6200");
        dataSource.setConnectionFactoryClassName("oracle.jdbc.pool.OracleDataSource");
        dataSource.setURL(getSession().getLogin().getConnectionString());
        dataSource.setUser(getSession().getLogin().getUserName());
        dataSource.setPassword(getSession().getLogin().getPassword());
        dataSource.setInitialPoolSize(1);
        dataSource.setMinPoolSize(1);
        dataSource.setMaxPoolSize(10);
        dataSource.setFastConnectionFailoverEnabled(true);
        Project project = getSession().getProject().clone();
        project.setLogin(project.getLogin().clone());
        project.getLogin().setConnector(new JNDIConnector(dataSource));
        project.getLogin().setUsesExternalConnectionPooling(true);
        Server server = project.createServerSession();
        server.setSessionLog(getSession().getSessionLog());
        server.login();
        return server;
    } catch (SQLException error) {
        throw new TestErrorException("UCP failed to initialize.", error);
    }
}
Also used : Project(org.eclipse.persistence.sessions.Project) Server(org.eclipse.persistence.sessions.server.Server) SQLException(java.sql.SQLException) TestErrorException(org.eclipse.persistence.testing.framework.TestErrorException) JNDIConnector(org.eclipse.persistence.sessions.JNDIConnector) PoolDataSource(oracle.ucp.jdbc.PoolDataSource)

Aggregations

TestErrorException (org.eclipse.persistence.testing.framework.TestErrorException)227 UnitOfWork (org.eclipse.persistence.sessions.UnitOfWork)79 Employee (org.eclipse.persistence.testing.models.employee.domain.Employee)50 ReadObjectQuery (org.eclipse.persistence.queries.ReadObjectQuery)27 ExpressionBuilder (org.eclipse.persistence.expressions.ExpressionBuilder)22 Vector (java.util.Vector)20 EntityMapValue (org.eclipse.persistence.testing.models.collections.map.EntityMapValue)20 Expression (org.eclipse.persistence.expressions.Expression)19 UnitOfWorkImpl (org.eclipse.persistence.internal.sessions.UnitOfWorkImpl)18 Iterator (java.util.Iterator)17 AggregateMapKey (org.eclipse.persistence.testing.models.collections.map.AggregateMapKey)16 EntityMapKey (org.eclipse.persistence.testing.models.collections.map.EntityMapKey)15 Project (org.eclipse.persistence.sessions.Project)13 Session (org.eclipse.persistence.sessions.Session)11 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)7 QueryException (org.eclipse.persistence.exceptions.QueryException)7 TestWarningException (org.eclipse.persistence.testing.framework.TestWarningException)7 Address (org.eclipse.persistence.testing.models.employee.domain.Address)7 Test (org.junit.Test)7 BigDecimal (java.math.BigDecimal)6