use of org.eclipse.persistence.testing.models.jpa.advanced.Equipment in project eclipselink by eclipse-ee4j.
the class AdvancedJPAJunitTest method testAddNewEquipmentToDepartment.
/**
* Tests adding objects to a 1-M mapping that uses a map.
*/
public void testAddNewEquipmentToDepartment() {
EntityManager em = createEntityManager();
beginTransaction(em);
try {
EJBQueryImpl query = (EJBQueryImpl) em.createNamedQuery("findAllSQLEquipment");
Collection<Equipment> equipment = query.getResultCollection();
if (equipment.isEmpty()) {
fail("No Equipment was found. testCreateNewEquipment should have created new equipment and should have run before this test.");
} else {
Department department = new Department();
department.setName("Department with equipment");
for (Equipment e : equipment) {
department.addEquipment(e);
}
em.persist(department);
deptId = department.getId();
commitTransaction(em);
}
} catch (RuntimeException e) {
if (isTransactionActive(em)) {
rollbackTransaction(em);
}
closeEntityManager(em);
// Re-throw exception to ensure stacktrace appears in test result.
throw e;
}
closeEntityManager(em);
}
use of org.eclipse.persistence.testing.models.jpa.advanced.Equipment in project eclipselink by eclipse-ee4j.
the class PessimisticLockingExtendedScopeTestSuite method testPESSMISTIC_ES3.
// Entity relationships for which the locked entity contains the foreign key
// will be locked with unidirectional many-to-one mapping(Scenario 1.3)
public void testPESSMISTIC_ES3() throws Exception {
if (getPlatform().isSQLServer()) {
warning("This test deadlocks on SQL Server");
return;
}
final Equipment eq = new Equipment();
final Actor<Equipment> actor = new Actor<>() {
@Override
public void setup(EntityManager em) {
EquipmentCode eqCode = new EquipmentCode();
eqCode.setCode("A");
em.persist(eqCode);
eq.setEquipmentCode(eqCode);
em.persist(eq);
}
@Override
public Equipment getEntityToLock(EntityManager em1) {
return em1.find(Equipment.class, eq.getId());
}
@Override
public void modify(EntityManager em2) {
Equipment eq2 = em2.find(Equipment.class, eq.getId());
eq2.setEquipmentCode(null);
}
@Override
public void check(EntityManager em1, Equipment lockedEntity) {
em1.refresh(lockedEntity);
assertNotNull("other transaction modified row concurrently", lockedEntity.getEquipmentCode());
}
};
testNonrepeatableRead(actor);
}
use of org.eclipse.persistence.testing.models.jpa.advanced.Equipment in project eclipselink by eclipse-ee4j.
the class Runner1 method run.
@Override
public void run() {
try {
EntityManager em = emf.createEntityManager();
Department dept = em.find(Department.class, deptPK);
Equipment equip = em.find(Equipment.class, equipPK);
dept.getEquipment().put(equip.getId(), equip);
UnitOfWorkImpl uow = ((EntityManagerImpl) em).getActivePersistenceContext(null);
try {
Thread.sleep(4000);
} catch (InterruptedException e) {
}
uow.issueSQLbeforeCompletion(true);
synchronized (this.waitOn) {
try {
this.waitOn.notify();
this.waitOn.wait();
} catch (InterruptedException e) {
}
}
CacheKey cacheKey = uow.getParent().getParent().getIdentityMapAccessorInstance().getCacheKeyForObject(dept);
synchronized (cacheKey) {
cacheKey.notify();
}
try {
Thread.sleep(4000);
} catch (InterruptedException e) {
}
uow.mergeClonesAfterCompletion();
} catch (Exception ex) {
}
}
use of org.eclipse.persistence.testing.models.jpa.advanced.Equipment in project eclipselink by eclipse-ee4j.
the class NamedQueryJUnitTest method removeEmployee.
/**
* Remove {@link Employee} entity including all related entities.
* Transaction must be opened for provided <code>EntityManager</code> instance.
* @param em An <code>EntityManager</code> instance used to remove entities.
* @param employee An <code>Employee</code> entity to be removed.
*/
private void removeEmployee(EntityManager em, Employee employee) {
Collection<Equipment> equipmentColl = employee.getDepartment().getEquipment().values();
em.remove(employee);
em.remove(employee.getDepartment());
em.remove(employee.getAddress());
for (Equipment equipment : equipmentColl) {
EquipmentCode ec = equipment.getEquipmentCode();
em.remove(equipment);
if (ec != null) {
em.remove(ec);
}
}
}
use of org.eclipse.persistence.testing.models.jpa.advanced.Equipment in project eclipselink by eclipse-ee4j.
the class AdvancedJPAJunitTest method testCreateNewEquipment.
/**
* Creates some new equipment objects.
*/
public void testCreateNewEquipment() {
EntityManager em = createEntityManager();
beginTransaction(em);
try {
// Persist some equipment.
Equipment equip1 = new Equipment();
equip1.setDescription("Toaster");
em.persist(equip1);
Equipment equip2 = new Equipment();
equip1.setDescription("Bucket");
em.persist(equip2);
Equipment equip3 = new Equipment();
equip1.setDescription("Broom");
em.persist(equip3);
commitTransaction(em);
} catch (RuntimeException e) {
if (isTransactionActive(em)) {
rollbackTransaction(em);
}
closeEntityManager(em);
// Re-throw exception to ensure stacktrace appears in test result.
throw e;
}
closeEntityManager(em);
}
Aggregations