use of org.eclipse.persistence.testing.models.jpa.advanced.EquipmentCode in project eclipselink by eclipse-ee4j.
the class NamedQueryJUnitTest method persistEmployee.
/**
* Persist {@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 persist entities.
* @param employee An <code>Employee</code> entity to be persisted.
*/
private void persistEmployee(EntityManager em, Employee employee) {
Collection<Equipment> equipmentColl = employee.getDepartment().getEquipment().values();
for (Equipment equipment : equipmentColl) {
EquipmentCode ec = equipment.getEquipmentCode();
if (ec != null) {
em.persist(ec);
}
em.persist(equipment);
}
em.persist(employee.getAddress());
em.persist(employee.getDepartment());
em.persist(employee);
}
use of org.eclipse.persistence.testing.models.jpa.advanced.EquipmentCode in project eclipselink by eclipse-ee4j.
the class EntityManagerJUnitTestSuite method testWeaving.
/**
* Test that all of the classes in the advanced model were weaved as expected.
*/
public void testWeaving() {
// Only test if weaving was on, test runs without weaving must set this system property.
if (isWeavingEnabled()) {
internalTestWeaving(new Employee(), isWeavingForChangeTrackingEnabled(), isWeavingForFetchGroupsEnabled(), true);
internalTestWeaving(new FormerEmployment(), isWeavingForChangeTrackingEnabled(), isWeavingForFetchGroupsEnabled(), false);
internalTestWeaving(new Address(), isWeavingForChangeTrackingEnabled(), isWeavingForFetchGroupsEnabled(), false);
internalTestWeaving(new PhoneNumber(), isWeavingForChangeTrackingEnabled(), isWeavingForFetchGroupsEnabled(), false);
internalTestWeaving(new EmploymentPeriod(), isWeavingForChangeTrackingEnabled(), isWeavingForFetchGroupsEnabled(), false);
// field-locking
internalTestWeaving(new Buyer(), false, isWeavingForFetchGroupsEnabled(), false);
// field-locking
internalTestWeaving(new GoldBuyer(), false, isWeavingForFetchGroupsEnabled(), false);
// field-locking
internalTestWeaving(new PlatinumBuyer(), false, isWeavingForFetchGroupsEnabled(), false);
// eager 1-m
internalTestWeaving(new Department(), isWeavingForChangeTrackingEnabled(), isWeavingForFetchGroupsEnabled(), false);
internalTestWeaving(new Golfer(), isWeavingForChangeTrackingEnabled(), isWeavingForFetchGroupsEnabled(), false);
internalTestWeaving(new GolferPK(), isWeavingForChangeTrackingEnabled(), isWeavingForFetchGroupsEnabled(), false);
internalTestWeaving(new SmallProject(), isWeavingForChangeTrackingEnabled(), isWeavingForFetchGroupsEnabled(), false);
internalTestWeaving(new LargeProject(), isWeavingForChangeTrackingEnabled(), isWeavingForFetchGroupsEnabled(), false);
internalTestWeaving(new Man(), isWeavingForChangeTrackingEnabled(), isWeavingForFetchGroupsEnabled(), false);
internalTestWeaving(new Woman(), isWeavingForChangeTrackingEnabled(), isWeavingForFetchGroupsEnabled(), false);
// serialized
internalTestWeaving(new Vegetable(), false, isWeavingForFetchGroupsEnabled(), false);
internalTestWeaving(new VegetablePK(), false, isWeavingForFetchGroupsEnabled(), false);
internalTestWeaving(new WorldRank(), isWeavingForChangeTrackingEnabled(), isWeavingForFetchGroupsEnabled(), false);
internalTestWeaving(new Equipment(), isWeavingForChangeTrackingEnabled(), isWeavingForFetchGroupsEnabled(), false);
internalTestWeaving(new EquipmentCode(), isWeavingForChangeTrackingEnabled(), isWeavingForFetchGroupsEnabled(), false);
internalTestWeaving(new PartnerLink(), isWeavingForChangeTrackingEnabled(), isWeavingForFetchGroupsEnabled(), false);
}
}
use of org.eclipse.persistence.testing.models.jpa.advanced.EquipmentCode 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.EquipmentCode 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.EquipmentCode in project eclipselink by eclipse-ee4j.
the class AdvancedJPAJunitTest method testUpdateReadOnlyEquipmentCode.
/**
* Tests trying to update a read only class.
*/
public void testUpdateReadOnlyEquipmentCode() {
EntityManager em = createEntityManager();
beginTransaction(em);
try {
Query query = em.createNamedQuery("findSQLEquipmentCodeA");
EquipmentCode equipmentCode = (EquipmentCode) query.getSingleResult();
equipmentCode.setCode("Z");
commitTransaction(em);
// not found, therefore, updated on the db.
try {
query = em.createNamedQuery("findSQLEquipmentCodeA");
query.getSingleResult();
} catch (Exception e) {
fail("The read only EquipmentA was modified");
}
} 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