Search in sources :

Example 41 with Employee

use of org.eclipse.persistence.testing.models.employee.domain.Employee in project eclipselink by eclipse-ee4j.

the class CommitAfterExecuteModifyQueryDuringTransTest method test.

@Override
public void test() {
    uow = getSession().acquireUnitOfWork();
    uow.getEventManager().addListener(new SessionEventAdapter() {

        @Override
        public void prepareUnitOfWork(SessionEvent event) {
            Vector myV = new Vector();
            myV.addElement(employeesNewFirstName);
            myV.addElement(initialVersionField);
            myV.addElement(originalEmployee.lastName);
            uow.executeQuery(dataModifyQuery, myV);
        }
    });
    Employee temp = (Employee) uow.registerObject(cachedEmployee);
    temp.firstName = "tempFirstName";
    // no exceptions are expected, though transaction should not be commited if test fails:
    uow.commit();
    cachedEmployee = (Employee) getSession().refreshObject(cachedEmployee);
}
Also used : SessionEvent(org.eclipse.persistence.sessions.SessionEvent) Employee(org.eclipse.persistence.testing.models.employee.domain.Employee) SessionEventAdapter(org.eclipse.persistence.sessions.SessionEventAdapter) Vector(java.util.Vector)

Example 42 with Employee

use of org.eclipse.persistence.testing.models.employee.domain.Employee in project eclipselink by eclipse-ee4j.

the class CommitUnitOfWorkAgainTest method test.

@Override
public void test() {
    // Test CR#2189
    UnitOfWork uow = getSession().acquireUnitOfWork();
    Employee anEmployee = (Employee) uow.readObject(Employee.class);
    anEmployee.setLastName("TOPLink");
    uow.commit();
    // If you try to commit again, it must throw a exception.[TOPLink-7068]
    try {
        anEmployee.setLastName("EclipseLink");
        uow.commit();
        throw new TestErrorException("UOW is not throwing an exception when it is committed for a second time.");
    } catch (ValidationException exception) {
        if (!(exception.getErrorCode() == ValidationException.CANNOT_COMMIT_UOW_AGAIN)) {
            throw new TestErrorException("UOW is throwing exception " + exception.getErrorCode() + " instead of CANNOT_COMMIT_UOW_AGAIN when it is committed for a second time.");
        }
    }
}
Also used : UnitOfWork(org.eclipse.persistence.sessions.UnitOfWork) Employee(org.eclipse.persistence.testing.models.employee.domain.Employee) ValidationException(org.eclipse.persistence.exceptions.ValidationException) TestErrorException(org.eclipse.persistence.testing.framework.TestErrorException)

Example 43 with Employee

use of org.eclipse.persistence.testing.models.employee.domain.Employee in project eclipselink by eclipse-ee4j.

the class ComplexMultipleUnitOfWorkTest method verify.

@Override
public void verify() {
    getSession().getIdentityMapAccessor().initializeIdentityMaps();
    Session sessionToVerifyDelete;
    if (getSession() instanceof RemoteSession) {
        sessionToVerifyDelete = RemoteModel.getServerSession();
    } else {
        sessionToVerifyDelete = getSession();
    }
    // Verify if object deleted in the uow was deleted
    if (!(((AbstractSession) sessionToVerifyDelete).verifyDelete(this.readInSession))) {
        throw new TestErrorException("The object '" + this.readInSession + "'deleted in the uow was not completely deleted from the database.");
    }
    // Verify if object deleted in the uow was deleted
    if (!(((AbstractSession) sessionToVerifyDelete).verifyDelete(this.readInUow))) {
        throw new TestErrorException("The object '" + this.readInUow + "'deleted in the nested uow was not completely deleted from the database.");
    }
    ReadObjectQuery query = new ReadObjectQuery();
    query.setSelectionObject(this.newEmployeeInUow);
    Employee objectFromDatabase = (Employee) getSession().executeQuery(query);
    if (!(((AbstractSession) getSession()).compareObjects(this.newEmployeeInUow, objectFromDatabase))) {
        throw new TestErrorException("The object read from the database, '" + this.newEmployeeInUow + "' does not match the originial, '" + objectFromDatabase + ".");
    }
}
Also used : Employee(org.eclipse.persistence.testing.models.employee.domain.Employee) ReadObjectQuery(org.eclipse.persistence.queries.ReadObjectQuery) RemoteSession(org.eclipse.persistence.sessions.remote.RemoteSession) TestErrorException(org.eclipse.persistence.testing.framework.TestErrorException) RemoteSession(org.eclipse.persistence.sessions.remote.RemoteSession) Session(org.eclipse.persistence.sessions.Session) AbstractSession(org.eclipse.persistence.internal.sessions.AbstractSession) AbstractSession(org.eclipse.persistence.internal.sessions.AbstractSession)

Example 44 with Employee

use of org.eclipse.persistence.testing.models.employee.domain.Employee in project eclipselink by eclipse-ee4j.

the class ComplexMultipleUnitOfWorkTest method createNewEmployeeObject.

public Employee createNewEmployeeObject() {
    Employee employee = new org.eclipse.persistence.testing.models.employee.domain.Employee();
    employee.setFirstName("Judy");
    employee.setLastName("Barney");
    employee.setMale();
    employee.setSalary(35000);
    employee.setPeriod(employmentPeriodExample());
    employee.setAddress(addressExample1());
    employee.addResponsibility("Make the coffee.");
    employee.addResponsibility("Clean the kitchen.");
    employee.addPhoneNumber(new org.eclipse.persistence.testing.models.employee.domain.PhoneNumber("Work", "613", "2258812"));
    employee.addProject(smallProjectExample());
    return employee;
}
Also used : Employee(org.eclipse.persistence.testing.models.employee.domain.Employee)

Example 45 with Employee

use of org.eclipse.persistence.testing.models.employee.domain.Employee in project eclipselink by eclipse-ee4j.

the class ComplexMultipleUnitOfWorkTest method processThirdUnitOfWork.

public void processThirdUnitOfWork() {
    this.thirdUnitOfWork = getSession().acquireUnitOfWork();
    Employee workingCopy = (Employee) thirdUnitOfWork.registerObject(this.newEmployeeInUow);
    changeObject(workingCopy, this.thirdUnitOfWork);
    if (!((AbstractSession) getSession()).compareObjectsDontMatch(this.newEmployeeInUow, workingCopy)) {
        throw new TestErrorException("The original object was changed through changing the clone.");
    }
    this.thirdUnitOfWork.commit();
}
Also used : Employee(org.eclipse.persistence.testing.models.employee.domain.Employee) TestErrorException(org.eclipse.persistence.testing.framework.TestErrorException)

Aggregations

Employee (org.eclipse.persistence.testing.models.employee.domain.Employee)220 UnitOfWork (org.eclipse.persistence.sessions.UnitOfWork)79 TestErrorException (org.eclipse.persistence.testing.framework.TestErrorException)52 ExpressionBuilder (org.eclipse.persistence.expressions.ExpressionBuilder)40 Vector (java.util.Vector)34 ReadObjectQuery (org.eclipse.persistence.queries.ReadObjectQuery)32 SmallProject (org.eclipse.persistence.testing.models.employee.domain.SmallProject)29 Address (org.eclipse.persistence.testing.models.employee.domain.Address)24 PhoneNumber (org.eclipse.persistence.testing.models.employee.domain.PhoneNumber)22 Expression (org.eclipse.persistence.expressions.Expression)21 LargeProject (org.eclipse.persistence.testing.models.employee.domain.LargeProject)18 UnitOfWorkImpl (org.eclipse.persistence.internal.sessions.UnitOfWorkImpl)16 TestSuite (org.eclipse.persistence.testing.framework.TestSuite)15 PopulationManager (org.eclipse.persistence.tools.schemaframework.PopulationManager)15 ReadAllQuery (org.eclipse.persistence.queries.ReadAllQuery)14 Project (org.eclipse.persistence.testing.models.employee.domain.Project)14 EmployeePopulator (org.eclipse.persistence.testing.models.employee.domain.EmployeePopulator)11 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)9 ValidationException (org.eclipse.persistence.exceptions.ValidationException)9 EmploymentPeriod (org.eclipse.persistence.testing.models.employee.domain.EmploymentPeriod)9