Search in sources :

Example 1 with EquipmentCode

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);
}
Also used : Equipment(org.eclipse.persistence.testing.models.jpa.advanced.Equipment) EquipmentCode(org.eclipse.persistence.testing.models.jpa.advanced.EquipmentCode)

Example 2 with EquipmentCode

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);
    }
}
Also used : EmploymentPeriod(org.eclipse.persistence.testing.models.jpa.advanced.EmploymentPeriod) SmallProject(org.eclipse.persistence.testing.models.jpa.advanced.SmallProject) VegetablePK(org.eclipse.persistence.testing.models.jpa.advanced.VegetablePK) WorldRank(org.eclipse.persistence.testing.models.jpa.advanced.WorldRank) Address(org.eclipse.persistence.testing.models.jpa.advanced.Address) EquipmentCode(org.eclipse.persistence.testing.models.jpa.advanced.EquipmentCode) FormerEmployment(org.eclipse.persistence.testing.models.jpa.advanced.FormerEmployment) GoldBuyer(org.eclipse.persistence.testing.models.jpa.advanced.GoldBuyer) PlatinumBuyer(org.eclipse.persistence.testing.models.jpa.advanced.PlatinumBuyer) Buyer(org.eclipse.persistence.testing.models.jpa.advanced.Buyer) GoldBuyer(org.eclipse.persistence.testing.models.jpa.advanced.GoldBuyer) PlatinumBuyer(org.eclipse.persistence.testing.models.jpa.advanced.PlatinumBuyer) Department(org.eclipse.persistence.testing.models.jpa.advanced.Department) Employee(org.eclipse.persistence.testing.models.jpa.advanced.Employee) Equipment(org.eclipse.persistence.testing.models.jpa.advanced.Equipment) GolferPK(org.eclipse.persistence.testing.models.jpa.advanced.GolferPK) PhoneNumber(org.eclipse.persistence.testing.models.jpa.advanced.PhoneNumber) Golfer(org.eclipse.persistence.testing.models.jpa.advanced.Golfer) Man(org.eclipse.persistence.testing.models.jpa.advanced.Man) Woman(org.eclipse.persistence.testing.models.jpa.advanced.Woman) PartnerLink(org.eclipse.persistence.testing.models.jpa.advanced.PartnerLink) Vegetable(org.eclipse.persistence.testing.models.jpa.advanced.Vegetable) SuperLargeProject(org.eclipse.persistence.testing.models.jpa.advanced.SuperLargeProject) LargeProject(org.eclipse.persistence.testing.models.jpa.advanced.LargeProject)

Example 3 with EquipmentCode

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);
}
Also used : EntityManager(jakarta.persistence.EntityManager) Equipment(org.eclipse.persistence.testing.models.jpa.advanced.Equipment) EquipmentCode(org.eclipse.persistence.testing.models.jpa.advanced.EquipmentCode)

Example 4 with EquipmentCode

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);
        }
    }
}
Also used : Equipment(org.eclipse.persistence.testing.models.jpa.advanced.Equipment) EquipmentCode(org.eclipse.persistence.testing.models.jpa.advanced.EquipmentCode)

Example 5 with EquipmentCode

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);
}
Also used : EntityManager(jakarta.persistence.EntityManager) JpaEntityManager(org.eclipse.persistence.jpa.JpaEntityManager) Query(jakarta.persistence.Query) ReadAllQuery(org.eclipse.persistence.queries.ReadAllQuery) DoesExistQuery(org.eclipse.persistence.queries.DoesExistQuery) TypedQuery(jakarta.persistence.TypedQuery) DatabaseQuery(org.eclipse.persistence.queries.DatabaseQuery) EquipmentCode(org.eclipse.persistence.testing.models.jpa.advanced.EquipmentCode) QueryException(org.eclipse.persistence.exceptions.QueryException)

Aggregations

EquipmentCode (org.eclipse.persistence.testing.models.jpa.advanced.EquipmentCode)5 Equipment (org.eclipse.persistence.testing.models.jpa.advanced.Equipment)4 EntityManager (jakarta.persistence.EntityManager)2 Query (jakarta.persistence.Query)1 TypedQuery (jakarta.persistence.TypedQuery)1 QueryException (org.eclipse.persistence.exceptions.QueryException)1 JpaEntityManager (org.eclipse.persistence.jpa.JpaEntityManager)1 DatabaseQuery (org.eclipse.persistence.queries.DatabaseQuery)1 DoesExistQuery (org.eclipse.persistence.queries.DoesExistQuery)1 ReadAllQuery (org.eclipse.persistence.queries.ReadAllQuery)1 Address (org.eclipse.persistence.testing.models.jpa.advanced.Address)1 Buyer (org.eclipse.persistence.testing.models.jpa.advanced.Buyer)1 Department (org.eclipse.persistence.testing.models.jpa.advanced.Department)1 Employee (org.eclipse.persistence.testing.models.jpa.advanced.Employee)1 EmploymentPeriod (org.eclipse.persistence.testing.models.jpa.advanced.EmploymentPeriod)1 FormerEmployment (org.eclipse.persistence.testing.models.jpa.advanced.FormerEmployment)1 GoldBuyer (org.eclipse.persistence.testing.models.jpa.advanced.GoldBuyer)1 Golfer (org.eclipse.persistence.testing.models.jpa.advanced.Golfer)1 GolferPK (org.eclipse.persistence.testing.models.jpa.advanced.GolferPK)1 LargeProject (org.eclipse.persistence.testing.models.jpa.advanced.LargeProject)1