Search in sources :

Example 1 with EquipmentCode

use of org.eclipse.persistence.testing.models.jpa.fieldaccess.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 (JUnitTestCase.isWeavingEnabled("fieldaccess")) {
        internalTestWeaving(new Employee(), true, true);
        internalTestWeaving(new FormerEmployment(), true, false);
        internalTestWeaving(new Address(), true, false);
        internalTestWeaving(new PhoneNumber(), true, false);
        internalTestWeaving(new EmploymentPeriod(), true, false);
        // field-locking
        internalTestWeaving(new Buyer(), false, false);
        // field-locking
        internalTestWeaving(new GoldBuyer(), false, false);
        // field-locking
        internalTestWeaving(new PlatinumBuyer(), false, false);
        internalTestWeaving(new Department(), true, false);
        internalTestWeaving(new Golfer(), true, false);
        internalTestWeaving(new GolferPK(), true, false);
        internalTestWeaving(new SmallProject(), true, false);
        internalTestWeaving(new LargeProject(), true, false);
        internalTestWeaving(new Man(), true, false);
        internalTestWeaving(new Woman(), true, false);
        // serialized
        internalTestWeaving(new Vegetable(), false, false);
        internalTestWeaving(new VegetablePK(), false, false);
        internalTestWeaving(new WorldRank(), true, false);
        internalTestWeaving(new Equipment(), true, false);
        internalTestWeaving(new EquipmentCode(), true, false);
        internalTestWeaving(new PartnerLink(), true, false);
    }
    if (((OneToOneMapping) getDatabaseSession().getDescriptor(DatabaseField.class).getMappingForAttributeName("table")).usesIndirection()) {
        fail("LAZY mapping should have been reverted as class was not weaved.");
    }
}
Also used : EmploymentPeriod(org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.EmploymentPeriod) SmallProject(org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.SmallProject) VegetablePK(org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.VegetablePK) WorldRank(org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.WorldRank) Address(org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.Address) EquipmentCode(org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.EquipmentCode) FormerEmployment(org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.FormerEmployment) GoldBuyer(org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.GoldBuyer) GoldBuyer(org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.GoldBuyer) Buyer(org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.Buyer) PlatinumBuyer(org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.PlatinumBuyer) PlatinumBuyer(org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.PlatinumBuyer) Department(org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.Department) Employee(org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.Employee) Equipment(org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.Equipment) GolferPK(org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.GolferPK) PhoneNumber(org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.PhoneNumber) Golfer(org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.Golfer) Man(org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.Man) Woman(org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.Woman) PartnerLink(org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.PartnerLink) OneToOneMapping(org.eclipse.persistence.mappings.OneToOneMapping) Vegetable(org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.Vegetable) LargeProject(org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.LargeProject) SuperLargeProject(org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.SuperLargeProject)

Example 2 with EquipmentCode

use of org.eclipse.persistence.testing.models.jpa.fieldaccess.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("fieldaccess");
    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) Query(jakarta.persistence.Query) EquipmentCode(org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.EquipmentCode) PersistenceException(jakarta.persistence.PersistenceException)

Aggregations

EquipmentCode (org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.EquipmentCode)2 EntityManager (jakarta.persistence.EntityManager)1 PersistenceException (jakarta.persistence.PersistenceException)1 Query (jakarta.persistence.Query)1 OneToOneMapping (org.eclipse.persistence.mappings.OneToOneMapping)1 Address (org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.Address)1 Buyer (org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.Buyer)1 Department (org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.Department)1 Employee (org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.Employee)1 EmploymentPeriod (org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.EmploymentPeriod)1 Equipment (org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.Equipment)1 FormerEmployment (org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.FormerEmployment)1 GoldBuyer (org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.GoldBuyer)1 Golfer (org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.Golfer)1 GolferPK (org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.GolferPK)1 LargeProject (org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.LargeProject)1 Man (org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.Man)1 PartnerLink (org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.PartnerLink)1 PhoneNumber (org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.PhoneNumber)1 PlatinumBuyer (org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.PlatinumBuyer)1