Search in sources :

Example 6 with EmployeePopulator

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

the class UnregisteredNewObjectOptimisticLockTest method test.

@Override
protected void test() {
    try {
        UnitOfWork uow = getSession().acquireUnitOfWork();
        Employee orig = (Employee) uow.readObject(Employee.class);
        uow.setShouldNewObjectsBeCached(true);
        Employee newEmp = (Employee) new EmployeePopulator().basicEmployeeExample6();
        orig.getManagedEmployees().add(newEmp);
        newEmp.setManager(orig);
        uow.commit();
        uow = getSession().acquireUnitOfWork();
        newEmp = (Employee) uow.readObject(newEmp);
        newEmp.setFirstName("Changed Name");
        uow.commit();
    } catch (OptimisticLockException e) {
        throw new TestErrorException("bug 3431586 unregistered new object version number not merged into cache");
    }
}
Also used : UnitOfWork(org.eclipse.persistence.sessions.UnitOfWork) Employee(org.eclipse.persistence.testing.models.employee.domain.Employee) EmployeePopulator(org.eclipse.persistence.testing.models.employee.domain.EmployeePopulator) TestErrorException(org.eclipse.persistence.testing.framework.TestErrorException) OptimisticLockException(org.eclipse.persistence.exceptions.OptimisticLockException)

Example 7 with EmployeePopulator

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

the class QueryParameterForOneToOneValidationTest method test.

@Override
public void test() {
    // find a suitable id
    org.eclipse.persistence.testing.models.employee.domain.Employee empExample = (org.eclipse.persistence.testing.models.employee.domain.Employee) new EmployeePopulator().basicEmployeeExample10();
    ExpressionBuilder testBuilder = new ExpressionBuilder();
    Expression testExpression = testBuilder.get("firstName").equal(empExample.getFirstName());
    testExpression = testExpression.and(testBuilder.get("lastName").equal(empExample.getLastName()));
    Employee testEmp = (Employee) getSession().readObject(Employee.class, testExpression);
    if (testEmp == null) {
        throw new TestErrorException("Employee example was not retrieved from DB (null): " + empExample);
    }
    int id = testEmp.getId().intValue();
    getSession().getIdentityMapAccessor().initializeAllIdentityMaps();
    ReadAllQuery query = new ReadAllQuery(PhoneNumber.class);
    ExpressionBuilder builder = query.getExpressionBuilder();
    Expression expression = builder.get("owner").equal(builder.getParameter("the_parameter"));
    query.setSelectionCriteria(expression);
    query.addArgument("the_parameter", Integer.class);
    try {
        // doesn't matter what id is queried
        Vector params = new Vector();
        params.add(id);
        // special case for conforming
        if (this.shouldConform) {
            // enable conforming
            query.setCacheUsage(ObjectLevelReadQuery.CheckCacheOnly);
            // preload objects into identitymap
            getSession().readAllObjects(PhoneNumber.class);
            getSession().readAllObjects(Employee.class);
        }
        getSession().executeQuery(query, params);
    } catch (EclipseLinkException te) {
        caughtException = te;
    } catch (Exception e) {
        throw new TestException("Caught exception " + e.toString() + "running test " + getName());
    }
}
Also used : EmployeePopulator(org.eclipse.persistence.testing.models.employee.domain.EmployeePopulator) Employee(org.eclipse.persistence.testing.models.employee.domain.Employee) Employee(org.eclipse.persistence.testing.models.employee.domain.Employee)

Example 8 with EmployeePopulator

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

the class EmployeeChangeFlagBasicTestModel method getInsertObjectTestSuite.

public static TestSuite getInsertObjectTestSuite() {
    TestSuite suite = new TestSuite();
    suite.setName("EmployeeInsertObjectTestSuite");
    suite.setDescription("This suite tests the insertion of each object in the employee demo.");
    EmployeePopulator system = new EmployeePopulator();
    suite.addTest(new InsertObjectTest(system.basicEmployeeExample1()));
    suite.addTest(new InsertObjectTest(system.basicEmployeeExample2()));
    suite.addTest(new InsertObjectTest(system.basicEmployeeExample3()));
    suite.addTest(new InsertObjectTest(system.basicEmployeeExample4()));
    suite.addTest(new InsertObjectTest(system.basicEmployeeExample5()));
    suite.addTest(new InsertObjectTest(system.basicSmallProjectExample1()));
    suite.addTest(new InsertObjectTest(system.basicSmallProjectExample2()));
    suite.addTest(new InsertObjectTest(system.basicSmallProjectExample3()));
    suite.addTest(new InsertObjectTest(system.basicLargeProjectExample1()));
    suite.addTest(new InsertObjectTest(system.basicLargeProjectExample2()));
    suite.addTest(new InsertObjectTest(system.basicLargeProjectExample3()));
    return suite;
}
Also used : InsertObjectTest(org.eclipse.persistence.testing.framework.InsertObjectTest) TestSuite(org.eclipse.persistence.testing.framework.TestSuite) EmployeePopulator(org.eclipse.persistence.testing.models.employee.domain.EmployeePopulator)

Example 9 with EmployeePopulator

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

the class ConcurrentNewObjectTest method test.

@Override
protected void test() {
    UnitOfWorkImpl unitOfWork1 = (UnitOfWorkImpl) getSession().acquireUnitOfWork();
    Address address = new EmployeePopulator().addressExample1();
    Employee originalClone = (Employee) unitOfWork1.readObject(Employee.class);
    originalClone.setAddress(address);
    unitOfWork1.issueSQLbeforeCompletion();
    // Simulate use of the JTS
    unitOfWork1.setPendingMerge();
    address = (Address) getSession().readObject(address);
    try {
        unitOfWork1.mergeClonesAfterCompletion();
    } catch (Exception exception) {
        throw new TestErrorException("New Object was read into Cache before Merged by creator, creator threw error");
    }
}
Also used : Employee(org.eclipse.persistence.testing.models.employee.domain.Employee) Address(org.eclipse.persistence.testing.models.employee.domain.Address) EmployeePopulator(org.eclipse.persistence.testing.models.employee.domain.EmployeePopulator) TestErrorException(org.eclipse.persistence.testing.framework.TestErrorException) UnitOfWorkImpl(org.eclipse.persistence.internal.sessions.UnitOfWorkImpl) TestErrorException(org.eclipse.persistence.testing.framework.TestErrorException) TestWarningException(org.eclipse.persistence.testing.framework.TestWarningException)

Example 10 with EmployeePopulator

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

the class UpdateChangeObjectTest method changeObject.

@Override
protected void changeObject() {
    Employee employee = (Employee) this.workingCopy;
    // 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(2001, 1, 1), Helper.dateFromYearMonthDate(2002, 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) getUnitOfWork().readObject(SmallProject.class));
    employee.addProject((Project) getUnitOfWork().readObject(LargeProject.class));
    // Direct collection
    employee.setResponsibilitiesList(new Vector());
    employee.addResponsibility("make cafee");
    employee.addResponsibility("buy donuts");
    // One to one private/public
    employee.setAddress(new EmployeePopulator().addressExample12());
    // make sure that the employee is not his own manager
    Vector employees = getUnitOfWork().readAllObjects(Employee.class);
    Employee manager = null;
    for (int i = 0; i < employees.size(); i++) {
        manager = (Employee) employees.elementAt(i);
        if (!manager.getId().equals(employee.getId())) {
            break;
        }
    }
    employee.setManager(manager);
}
Also used : EmploymentPeriod(org.eclipse.persistence.testing.models.employee.domain.EmploymentPeriod) Employee(org.eclipse.persistence.testing.models.employee.domain.Employee) EmployeePopulator(org.eclipse.persistence.testing.models.employee.domain.EmployeePopulator) PhoneNumber(org.eclipse.persistence.testing.models.employee.domain.PhoneNumber) Vector(java.util.Vector)

Aggregations

EmployeePopulator (org.eclipse.persistence.testing.models.employee.domain.EmployeePopulator)15 Employee (org.eclipse.persistence.testing.models.employee.domain.Employee)11 TestErrorException (org.eclipse.persistence.testing.framework.TestErrorException)7 UnitOfWork (org.eclipse.persistence.sessions.UnitOfWork)6 UnitOfWorkImpl (org.eclipse.persistence.internal.sessions.UnitOfWorkImpl)4 BigDecimal (java.math.BigDecimal)3 Vector (java.util.Vector)3 InsertObjectTest (org.eclipse.persistence.testing.framework.InsertObjectTest)3 TestSuite (org.eclipse.persistence.testing.framework.TestSuite)3 ReadObjectQuery (org.eclipse.persistence.queries.ReadObjectQuery)2 EmploymentPeriod (org.eclipse.persistence.testing.models.employee.domain.EmploymentPeriod)2 PhoneNumber (org.eclipse.persistence.testing.models.employee.domain.PhoneNumber)2 OptimisticLockException (org.eclipse.persistence.exceptions.OptimisticLockException)1 ReadAllQuery (org.eclipse.persistence.queries.ReadAllQuery)1 TestWarningException (org.eclipse.persistence.testing.framework.TestWarningException)1 Address (org.eclipse.persistence.testing.models.employee.domain.Address)1 SmallProject (org.eclipse.persistence.testing.models.employee.domain.SmallProject)1