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");
}
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");
}
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();
}
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);
}
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.");
}
Aggregations