Search in sources :

Example 21 with Employee

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

the class GetFromNewObjectWithConformTest method test.

@Override
public void test() {
    UnitOfWork uow = getSession().acquireUnitOfWork();
    emp = new Employee();
    emp.setFirstName("SomeName");
    emp.setLastName("Some Last Name");
    uow.registerObject(emp);
    ReadObjectQuery query = new ReadObjectQuery(Employee.class);
    query.conformResultsInUnitOfWork();
    uow.getIdentityMapAccessor().initializeAllIdentityMaps();
    emp = (Employee) uow.executeQuery(query);
    uow.release();
}
Also used : UnitOfWork(org.eclipse.persistence.sessions.UnitOfWork) Employee(org.eclipse.persistence.testing.models.employee.domain.Employee) ReadObjectQuery(org.eclipse.persistence.queries.ReadObjectQuery)

Example 22 with Employee

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

the class NestedUnitOfWorkDeleteConformedNestedNewObjectTest method test.

@Override
public void test() {
    UnitOfWork uow = getSession().acquireUnitOfWork();
    UnitOfWork nestedUow1 = uow.acquireUnitOfWork();
    Employee employee = (Employee) new EmployeePopulator().basicEmployeeExample1();
    employee.setId(new BigDecimal(15));
    nestedUow1.registerObject(employee);
    nestedUow1.commit();
    nestedUow1 = uow.acquireUnitOfWork();
    ReadAllQuery query = new ReadAllQuery();
    query.setReferenceClass(Employee.class);
    query.setSelectionCriteria(new org.eclipse.persistence.expressions.ExpressionBuilder().get("id").equal(new BigDecimal(15)));
    query.conformResultsInUnitOfWork();
    Vector results = (Vector) nestedUow1.executeQuery(query);
    if (results.size() > 1) {
        throw new TestErrorException("The read all query on primary key returned more than one object see bug # 3183379");
    }
    Employee nestedEmployee = (Employee) results.firstElement();
    nestedUow1.deleteObject(nestedEmployee);
    nestedUow1.commit();
    if (!((UnitOfWorkImpl) uow).getNewObjectsCloneToOriginal().isEmpty()) {
        throw new TestErrorException("Failed to unregister the Object in the nested unit of work");
    }
}
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) ReadAllQuery(org.eclipse.persistence.queries.ReadAllQuery) TestErrorException(org.eclipse.persistence.testing.framework.TestErrorException) UnitOfWorkImpl(org.eclipse.persistence.internal.sessions.UnitOfWorkImpl) Vector(java.util.Vector) BigDecimal(java.math.BigDecimal)

Example 23 with Employee

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

the class NestedUnitOfWorkDeleteFromNestedObjectTest method test.

@Override
public void test() {
    UnitOfWork uow = getSession().acquireUnitOfWork();
    UnitOfWork nestedUow1 = uow.acquireUnitOfWork();
    ReadAllQuery query = new ReadAllQuery();
    query.setReferenceClass(Employee.class);
    ExpressionBuilder expressionBuilder = new ExpressionBuilder();
    query.setSelectionCriteria(expressionBuilder.get("firstName").equal("Bob").and(expressionBuilder.get("lastName").equal("Smith")));
    query.conformResultsInUnitOfWork();
    Vector<Employee> results = (Vector<Employee>) uow.executeQuery(query);
    Employee employee = results.firstElement();
    Employee employeeNested = (Employee) nestedUow1.registerObject(employee);
    assertTrue(employeeNested.getPhoneNumbers().size() > 0);
    for (PhoneNumber item : new Vector<PhoneNumber>(employeeNested.getPhoneNumbers())) {
        if (item != null) {
            nestedUow1.deleteObject(item);
            employeeNested.removePhoneNumber(item);
        }
    }
    nestedUow1.deleteObject(employeeNested);
    nestedUow1.commitAndResume();
    if (employee.getPhoneNumbers().size() != 0) {
        throw new TestErrorException("Objects removal from the nested unit of work is not merged into outer/main unit of work. Number of remaining objects is: " + employee.getPhoneNumbers().size());
    }
}
Also used : UnitOfWork(org.eclipse.persistence.sessions.UnitOfWork) Employee(org.eclipse.persistence.testing.models.employee.domain.Employee) ReadAllQuery(org.eclipse.persistence.queries.ReadAllQuery) TestErrorException(org.eclipse.persistence.testing.framework.TestErrorException) PhoneNumber(org.eclipse.persistence.testing.models.employee.domain.PhoneNumber) ExpressionBuilder(org.eclipse.persistence.expressions.ExpressionBuilder) Vector(java.util.Vector)

Example 24 with Employee

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

the class NestedUnitOfWorkDeleteNestedNewObjectTest method test.

@Override
public void test() {
    UnitOfWork uow = getSession().acquireUnitOfWork();
    UnitOfWork nestedUow1 = uow.acquireUnitOfWork();
    Employee employee = (Employee) new EmployeePopulator().basicEmployeeExample1();
    Employee nestedEmployee = (Employee) nestedUow1.registerObject(employee);
    nestedUow1.deleteObject(nestedEmployee);
    nestedUow1.commit();
    uow.commit();
    if (((UnitOfWorkImpl) uow).getNewObjectsCloneToOriginal().containsKey(employee)) {
        throw new TestErrorException("Failed to unregister the Object in the nested unit of work");
    }
}
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)

Example 25 with Employee

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

the class NestedUnitOfWorkNewObjectWithIndirectionTest method test.

@Override
public void test() {
    UnitOfWork uow = getSession().acquireUnitOfWork();
    UnitOfWork nestedUow1 = uow.acquireUnitOfWork();
    Employee employeeClone = (Employee) uow.registerObject(original);
    Employee employeeNestedClone = (Employee) nestedUow1.registerObject(employeeClone);
    if (((Employee) employeeNestedClone.getManagedEmployees().firstElement()).getManager() != employeeNestedClone) {
        throw new TestErrorException("Object Identity Lost when triggering indirection in nested UOW see BUG # 3228185");
    }
}
Also used : UnitOfWork(org.eclipse.persistence.sessions.UnitOfWork) 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