Search in sources :

Example 51 with Employee

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

the class TransactionIsolationMergeIndirectionOriginalsExistTest method test.

@Override
public void test() {
    // read all the addresses first, so they exist in the shared cache.
    Vector addresses = getSession().readAllObjects(Address.class);
    unitOfWork.beginEarlyTransaction();
    Employee employeeClone = (Employee) unitOfWork.readObject(Employee.class);
    // Just need the pk to reset() later.
    original = employeeClone;
    originalFirstName = original.getFirstName();
    employeeClone.setFirstName("elle");
    Address addressClone = employeeClone.getAddress();
    Address originalAddress = (Address) getSession().readObject(addressClone);
    unitOfWork.commit();
    unitOfWork = null;
    // Because the address was triggered, it should get merged into the old
    // original.
    Employee newOriginal = (Employee) getSession().getIdentityMapAccessor().getFromIdentityMap(employeeClone);
    strongAssert(newOriginal != employeeClone, "Somehow the employee clone was merged into the shared cache.");
    Address newAddress = (Address) getSession().getIdentityMapAccessor().getFromIdentityMap(addressClone);
    strongAssert(newAddress == originalAddress, "Identity was lost on address accross the 1-1");
}
Also used : Employee(org.eclipse.persistence.testing.models.employee.domain.Employee) Address(org.eclipse.persistence.testing.models.employee.domain.Address) Vector(java.util.Vector)

Example 52 with Employee

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

the class TransactionIsolationMergeOriginalsExistTest method test.

@Override
public void test() {
    unitOfWork.beginEarlyTransaction();
    // load original into shared cache first, to make sure that if already in
    // cache just return it.
    original = (Employee) getSession().readObject(Employee.class);
    originalFirstName = original.getFirstName();
    // want to avoid cache hit here, so make it go to database...
    ExpressionBuilder builder = new ExpressionBuilder();
    Expression expression = builder.get("firstName").equal(original.getFirstName()).and(builder.get("lastName").equal(original.getLastName()));
    Employee employeeClone = (Employee) unitOfWork.readAllObjects(Employee.class, expression).elementAt(0);
    employeeClone.setFirstName("elle");
    unitOfWork.commit();
    unitOfWork = null;
    ReadObjectQuery cacheQuery = new ReadObjectQuery(Employee.class);
    cacheQuery.checkCacheOnly();
    Employee newOriginal = (Employee) getSession().executeQuery(cacheQuery);
    strongAssert(newOriginal != null, "There should now be an original in the shared cache.");
    strongAssert(newOriginal == original, "The original should in the shared cache should still have its identity.");
    strongAssert(newOriginal.getFirstName().equals("elle"), "Changes were not merged into the shared cache");
}
Also used : Employee(org.eclipse.persistence.testing.models.employee.domain.Employee) ReadObjectQuery(org.eclipse.persistence.queries.ReadObjectQuery) Expression(org.eclipse.persistence.expressions.Expression) ExpressionBuilder(org.eclipse.persistence.expressions.ExpressionBuilder)

Example 53 with Employee

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

the class TransactionIsolationMergeTest method reset.

@Override
public void reset() throws Exception {
    if (unitOfWork != null) {
        unitOfWork.release();
        unitOfWork = null;
    }
    unitOfWork = getSession().acquireUnitOfWork();
    Employee clone = (Employee) unitOfWork.readObject(original);
    clone.setFirstName(originalFirstName);
    unitOfWork.commit();
    unitOfWork = null;
    originalFirstName = null;
    original = null;
    getSession().getIdentityMapAccessor().initializeAllIdentityMaps();
}
Also used : Employee(org.eclipse.persistence.testing.models.employee.domain.Employee)

Example 54 with Employee

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

the class TransactionIsolationNoNewObjectsTest method test.

@Override
public void test() {
    Employee employee = new Employee();
    // no need to set attributes.
    Employee newClone = (Employee) unitOfWork.registerObject(employee);
    unitOfWork.writeChanges();
    // employee should now have primary key set, so can try reading it in
    // unit of work.
    // However can not do reads after write changes, so get a unitofwork against
    // the same write connection, and read from there.
    UnitOfWork parallelUow = unitOfWork.getParent().acquireUnitOfWork();
    parallelUow.beginEarlyTransaction();
    try {
        Employee newCloneInParallelUow = (Employee) parallelUow.readObject(newClone);
        strongAssert(newCloneInParallelUow != null, "As the parallel Uow shares the same write connection, should " + "be able to see parallel objects.");
    } finally {
        parallelUow.release();
    }
    ReadObjectQuery cacheQuery = new ReadObjectQuery(Employee.class);
    cacheQuery.checkCacheOnly();
    Employee original = (Employee) getSession().executeQuery(cacheQuery);
    strongAssert(original == null, "Reading back a new object from the write connection should " + "not have cached objects in the shared cache. " + original);
}
Also used : UnitOfWork(org.eclipse.persistence.sessions.UnitOfWork) Employee(org.eclipse.persistence.testing.models.employee.domain.Employee) ReadObjectQuery(org.eclipse.persistence.queries.ReadObjectQuery)

Example 55 with Employee

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

the class TransactionIsolationNoOriginalsTest method test.

@Override
public void test() {
    unitOfWork.beginEarlyTransaction();
    Employee employeeClone = (Employee) unitOfWork.readObject(Employee.class);
    strongAssert(employeeClone != null, "Executing reads in early transaction doesn't work.");
    ReadObjectQuery cacheQuery = new ReadObjectQuery(Employee.class);
    cacheQuery.checkCacheOnly();
    Employee employee = (Employee) getSession().executeQuery(cacheQuery);
    strongAssert(employee == null, "There should be nothing in the shared cache.");
}
Also used : Employee(org.eclipse.persistence.testing.models.employee.domain.Employee) ReadObjectQuery(org.eclipse.persistence.queries.ReadObjectQuery)

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