use of org.eclipse.persistence.internal.sessions.UnitOfWorkImpl 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");
}
}
use of org.eclipse.persistence.internal.sessions.UnitOfWorkImpl in project eclipselink by eclipse-ee4j.
the class NewObjectIdentityTest method test.
@Override
public void test() {
UnitOfWork uow = getSession().acquireUnitOfWork();
origPerson = new Employee();
Employee person = (Employee) uow.registerObject(origPerson);
person.setFirstName("Anthony");
person.setLastName("Anthony");
((UnitOfWorkImpl) uow).issueSQLbeforeCompletion();
Runnable runnable = new Runnable() {
@Override
public void run() {
ReadAllQuery query = new ReadAllQuery(Employee.class);
query.setSelectionCriteria(query.getExpressionBuilder().get("firstName").equal("Anthony").and(query.getExpressionBuilder().get("lastName").equal("Anthony")));
readPerson = (Employee) ((Vector) getSession().executeQuery(query)).firstElement();
}
};
Thread thread = new Thread(runnable);
thread.start();
try {
Thread.sleep(3000);
} catch (InterruptedException ex) {
}
((UnitOfWorkImpl) uow).mergeClonesAfterCompletion();
try {
thread.join();
} catch (InterruptedException ex) {
}
}
use of org.eclipse.persistence.internal.sessions.UnitOfWorkImpl in project eclipselink by eclipse-ee4j.
the class ExpressionBuilderTestSuite method testUnitOfWorkInExpressionBuilder.
// Bug# 429232 - Instance of UnitOfWork is stored in ExpressionBuilder inside ConcurrentFixedCache
// Make sure that [ExpressionBuilder].setSession() will not store UnitOfWork inside builder even
// when UnitOfWork is passed as an argument.
public void testUnitOfWorkInExpressionBuilder() {
ExpressionBuilder builder = new ExpressionBuilder();
UnitOfWorkImpl uow = (UnitOfWorkImpl) getSession().acquireUnitOfWork();
builder.setSession(uow);
AbstractSession session = builder.getSession();
if (session instanceof UnitOfWork) {
throw new TestErrorException("Session stored in ExpressionBuilder shall not be UnitOfWork.");
}
}
use of org.eclipse.persistence.internal.sessions.UnitOfWorkImpl in project eclipselink by eclipse-ee4j.
the class WriteChanges_Release_TestCase method test.
@Override
public void test() {
UnitOfWork uow = getSession().acquireUnitOfWork();
uow.writeChanges();
uow.release();
if (((UnitOfWorkImpl) uow).isInTransaction()) {
throw new TestErrorException("Even though release was called, since we already wrote changes and started the transaction, it must be rolled back.");
}
}
use of org.eclipse.persistence.internal.sessions.UnitOfWorkImpl in project eclipselink by eclipse-ee4j.
the class WriteChangesFailed_TestCase method test.
@Override
public void test() {
UnitOfWork uow = getSession().acquireUnitOfWork();
try {
Employee employee = new Employee();
employee = (Employee) uow.registerNewObject(employee);
employee.setId(id);
employee.setFirstName("Andrew");
try {
uow.writeChanges();
} catch (Exception e) {
exception = e;
}
if (exception == null) {
return;
}
// added this kind of testing for the CommitTransactionPending state.
if (((UnitOfWorkImpl) uow).getLifecycle() != UnitOfWorkImpl.WriteChangesFailed) {
throw new TestErrorException("Lifecycle state not set to WriteChangesFailed. Instead it was: " + ((UnitOfWorkImpl) uow).getLifecycle());
}
// black box test one scenario just for sanity.
try {
uow.revertAndResume();
throw new TestErrorException("Exception not thrown calling revertAndResume after writeChanges failed.");
} catch (Exception expected) {
if (!((expected instanceof ValidationException) && (((ValidationException) expected).getErrorCode() == ValidationException.UNIT_OF_WORK_AFTER_WRITE_CHANGES_FAILED))) {
throw new TestErrorException("Exception not thrown calling revertAndResume after writeChanges. Instead triggered other exception.", expected);
}
}
// test that transaction rolled back.
if (getAbstractSession().isInTransaction()) {
throw new TestErrorException("Should not be in transaction after a failed writeChanges.");
}
} finally {
uow.release();
}
}
Aggregations