use of org.eclipse.persistence.internal.sessions.UnitOfWorkImpl in project eclipselink by eclipse-ee4j.
the class LifecycleJUnitTest method testClearAfterEntityManagerCommitFinished.
// This clear should pass because the state is always 0 Begin except for inside the commit()
public void testClearAfterEntityManagerCommitFinished() {
EntityManagerFactory emf = getEntityManagerFactory();
EntityManager em = emf.createEntityManager();
Department dept = null;
try {
em.getTransaction().begin();
dept = new Department();
em.persist(dept);
// simulate an attempt to call close() while we are in the middle of a commit
UnitOfWorkImpl uow = getUnitOfWorkFromEntityManager(em);
// get lifecycle state
int lifecycleBefore = uow.getLifecycle();
assertEquals("Birth state 0 is not set ", 0, lifecycleBefore);
em.clear();
int lifecycleAfter = uow.getLifecycle();
assertEquals("Birth state 0 is not set after a clear on state Birth ", 0, lifecycleAfter);
em.getTransaction().commit();
em.clear();
int lifecycleAfterCommit = uow.getLifecycle();
assertEquals("Birth state 0 is not set after commit ", 0, lifecycleAfterCommit);
} catch (RuntimeException ex) {
if (isTransactionActive(em)) {
rollbackTransaction(em);
}
closeEntityManager(em);
throw ex;
} finally {
closeEntityManager(em);
}
}
use of org.eclipse.persistence.internal.sessions.UnitOfWorkImpl in project eclipselink by eclipse-ee4j.
the class Runner2 method run.
@Override
public void run() {
try {
EntityManager em = emf.createEntityManager();
Equipment equip = em.find(Equipment.class, equipPK);
equip.setDescription("To changed");
Department dept = em.find(Department.class, deptPK);
dept.setName("Name Change As Well");
UnitOfWorkImpl uow = ((EntityManagerImpl) em).getActivePersistenceContext(null);
synchronized (this.waitOn) {
try {
this.waitOn.wait();
} catch (InterruptedException e) {
}
}
uow.issueSQLbeforeCompletion(true);
uow.mergeClonesAfterCompletion();
} catch (Exception ex) {
ex.printStackTrace();
}
}
use of org.eclipse.persistence.internal.sessions.UnitOfWorkImpl in project eclipselink by eclipse-ee4j.
the class TransitionRunner1 method run.
@Override
public void run() {
EntityManager em = emf.createEntityManager();
ConcurrencyB b = em.find(ConcurrencyB.class, concB.getId());
ConcurrencyC c = em.find(ConcurrencyC.class, concC.getId());
c.setName(System.currentTimeMillis() + "_C");
b.setName(System.currentTimeMillis() + "_B");
UnitOfWorkImpl uow = ((EntityManagerImpl) em).getActivePersistenceContext(null);
try {
synchronized (toWaitOn) {
toWaitOn.wait(120000);
}
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
uow.issueSQLbeforeCompletion(true);
try {
synchronized (toWaitOn) {
toWaitOn.notifyAll();
toWaitOn.wait(6000);
}
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
uow.release();
}
use of org.eclipse.persistence.internal.sessions.UnitOfWorkImpl in project eclipselink by eclipse-ee4j.
the class TransitionRunner2 method run.
@Override
public void run() {
try {
EntityManager em = emf.createEntityManager();
Equipment equip = em.find(Equipment.class, equipPK);
equip.setDescription("To changed");
Department dept = em.find(Department.class, deptPK);
dept.setName("Name Change As Well");
UnitOfWorkImpl uow = ((EntityManagerImpl) em).getActivePersistenceContext(null);
synchronized (this.waitOn) {
try {
this.waitOn.wait();
} catch (InterruptedException e) {
}
}
uow.issueSQLbeforeCompletion(true);
uow.mergeClonesAfterCompletion();
} catch (Exception ex) {
ex.printStackTrace();
}
}
use of org.eclipse.persistence.internal.sessions.UnitOfWorkImpl in project eclipselink by eclipse-ee4j.
the class EntityManagerJUnitTestSuite method testDetachRemovedObject.
// detach(object) on a removed object does not throw exception. This test only
// checks whether an removed object is completely deleted from the
// getDeletedObject()Map after 'detach(removedobject)' is invoked
public void testDetachRemovedObject() {
// create an Employee
Employee emp = new Employee();
emp.setFirstName("testDetachRemovedObjectEmployee");
// persist the Employee
EntityManager em = createEntityManager();
try {
beginTransaction(em);
em.persist(emp);
commitTransaction(em);
} catch (RuntimeException re) {
if (isTransactionActive(em)) {
rollbackTransaction(em);
}
throw re;
}
beginTransaction(em);
// attempt to remove the Employee
em.remove(em.find(Employee.class, emp.getId()));
commitTransaction(em);
beginTransaction(em);
EntityManagerImpl em1 = (EntityManagerImpl) em.getDelegate();
try {
// attempt to detach the Employee
em.detach(emp);
UnitOfWork uow = em1.getUnitOfWork();
UnitOfWorkImpl uowImpl = (UnitOfWorkImpl) uow;
boolean afterClear = uowImpl.getDeletedObjects().containsKey(emp);
assertFalse("exception thrown when detaching a removed entity is attempted.", afterClear);
} catch (IllegalArgumentException iae) {
return;
} finally {
if (isTransactionActive(em)) {
rollbackTransaction(em);
}
closeEntityManager(em);
}
}
Aggregations