Search in sources :

Example 26 with Employee

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

the class NestedUnitOfWorkNewObjectWithIndirectionTest method setup.

@Override
public void setup() {
    getAbstractSession().beginTransaction();
    Employee emp = (Employee) new EmployeePopulator().basicEmployeeExample1();
    original = (Employee) new EmployeePopulator().basicEmployeeExample2();
    original.getManagedEmployees().add(emp);
    emp.setManager(original);
}
Also used : Employee(org.eclipse.persistence.testing.models.employee.domain.Employee) EmployeePopulator(org.eclipse.persistence.testing.models.employee.domain.EmployeePopulator)

Example 27 with Employee

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

the class NestedUnitOfWorkReadOnlyClassTest method test.

@Override
public void test() {
    getSession().getIdentityMapAccessor().initializeAllIdentityMaps();
    // start root transaction
    UnitOfWork rootUOW = getSession().acquireUnitOfWork();
    Address addressRO = (Address) getSession().readObject(Address.class, new ExpressionBuilder().get("postalCode").equal(postalCode));
    if (addressRO == null) {
        throw new TestErrorException("Unable to find address.");
    }
    // start nested transaction
    UnitOfWork nestedUOW = rootUOW.acquireUnitOfWork();
    nestedUOW.addReadOnlyClass(Address.class);
    Employee emp = (Employee) nestedUOW.registerObject(new Employee());
    nestedUOW.assignSequenceNumber(emp);
    emp.setFirstName("John");
    emp.setAddress(addressRO);
    nestedUOW.commit();
    rootUOW.commit();
    originalEmployee = emp;
}
Also used : UnitOfWork(org.eclipse.persistence.sessions.UnitOfWork) Employee(org.eclipse.persistence.testing.models.employee.domain.Employee) Address(org.eclipse.persistence.testing.models.employee.domain.Address) TestErrorException(org.eclipse.persistence.testing.framework.TestErrorException) ExpressionBuilder(org.eclipse.persistence.expressions.ExpressionBuilder)

Example 28 with Employee

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

the class NestedUnitOfWorkTest method changeUnitOfWorkWorkingCopy.

protected void changeUnitOfWorkWorkingCopy() {
    Employee employee = (Employee) this.unitOfWorkWorkingCopy;
    // Transformation
    employee.setNormalHours(new java.sql.Time[2]);
    employee.setStartTime(Helper.timeFromHourMinuteSecond(1, 1, 1));
    employee.setEndTime(Helper.timeFromHourMinuteSecond(1, 1, 1));
    // Aggregate
    employee.setPeriod(new EmploymentPeriod(Helper.dateFromYearMonthDate(1901, 1, 1), Helper.dateFromYearMonthDate(1902, 2, 2)));
    // One to many private
    employee.setPhoneNumbers(new Vector());
    employee.addPhoneNumber(new PhoneNumber("home", "613", "2263374"));
    employee.addPhoneNumber(new PhoneNumber("office", "416", "8224599"));
    // Many to many
    employee.setProjects(new Vector());
    employee.addProject((Project) this.unitOfWork.readObject(SmallProject.class));
    employee.addProject((Project) this.unitOfWork.readObject(LargeProject.class));
    // Direct collection
    employee.setResponsibilitiesList(new Vector());
    employee.addResponsibility("make coffee");
    employee.addResponsibility("buy donuts");
    // One to one private/public
    employee.setAddress(new Address());
    // make sure that the employee is not his own manager
    employee.setManager((Employee) this.unitOfWork.readObject(Employee.class, (new ExpressionBuilder()).get("id").notEqual(employee.getId())));
}
Also used : EmploymentPeriod(org.eclipse.persistence.testing.models.employee.domain.EmploymentPeriod) Employee(org.eclipse.persistence.testing.models.employee.domain.Employee) Address(org.eclipse.persistence.testing.models.employee.domain.Address) PhoneNumber(org.eclipse.persistence.testing.models.employee.domain.PhoneNumber) ExpressionBuilder(org.eclipse.persistence.expressions.ExpressionBuilder) Vector(java.util.Vector)

Example 29 with Employee

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

the class MergeUnitOfWorkTest method verify.

/**
 * Verify if the objects match completely through allowing the session to use the descriptors.
 * This will compare the objects and all of their privately owned parts.
 */
@Override
protected void verify() {
    boolean found = false;
    Employee employeeToBeWritten = new org.eclipse.persistence.testing.models.employee.domain.Employee();
    Enumeration enumeration = ((Employee) this.objectToBeWritten).getManagedEmployees().elements();
    while ((!found) && (enumeration.hasMoreElements())) {
        Employee employee = (Employee) enumeration.nextElement();
        if (employee.getFirstName() == "New Man") {
            employeeToBeWritten = employee;
            found = true;
        }
    }
    this.compareForProperMerge((Employee) this.objectBeforeMerge, employeeToBeWritten);
}
Also used : Employee(org.eclipse.persistence.testing.models.employee.domain.Employee) Enumeration(java.util.Enumeration)

Example 30 with Employee

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

the class MergeUnitOfWorkTest method changeUnitOfWorkWorkingCopy.

protected void changeUnitOfWorkWorkingCopy() {
    Employee employee = (Employee) this.unitOfWorkWorkingCopy;
    Employee managedEmployee = (Employee) employee.getManagedEmployees().firstElement();
    Employee newEmployee;
    newEmployee = (Employee) unitOfWork.registerObject(new Employee());
    newEmployee.setNormalHours(employee.getNormalHours());
    newEmployee.setPeriod((EmploymentPeriod) employee.getPeriod().clone());
    newEmployee.setAddress(managedEmployee.getAddress());
    newEmployee.setFirstName("New Man");
    newEmployee.setLastName("Smith");
    employee.addManagedEmployee(newEmployee);
    this.setObjectBeforeMerge(newEmployee);
}
Also used : Employee(org.eclipse.persistence.testing.models.employee.domain.Employee)

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