Search in sources :

Example 1 with GoldBuyer

use of org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.GoldBuyer 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 GoldBuyer

use of org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.GoldBuyer in project eclipselink by eclipse-ee4j.

the class AdvancedJPAJunitTest method testCreateNewBuyer.

/**
 * Tests:
 * - BasicMap mapping with a TypeConverter on the map value and an
 *   ObjectTypeConverter on the map key.
 * - Basic with a custom converter
 * - Serialized Basic of type EnumSet.
 */
public void testCreateNewBuyer() {
    EntityManager em = createEntityManager("fieldaccess");
    beginTransaction(em);
    try {
        GoldBuyer buyer = new GoldBuyer();
        buyer.setName("Guy Pelletier");
        buyer.setGender("Made of testosterone");
        buyer.setDescription("Loves to spend");
        buyer.addVisa(visa);
        buyer.addAmex(amex);
        buyer.addDinersClub(diners);
        buyer.addMastercard(mastercard);
        buyer.setSaturdayToSundayBuyingDays();
        em.persist(buyer);
        commitTransaction(em);
        buyerId = buyer.getId();
    } 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) GoldBuyer(org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.GoldBuyer)

Example 3 with GoldBuyer

use of org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.GoldBuyer in project eclipselink by eclipse-ee4j.

the class AdvancedJPAJunitTest method testBuyerOptimisticLocking.

/**
 * Tests an OptimisticLocking policy set on Buyer.
 */
public void testBuyerOptimisticLocking() {
    // Cannot create parallel entity managers in the server.
    if (isOnServer()) {
        return;
    }
    EntityManager em1 = createEntityManager("fieldaccess");
    EntityManager em2 = createEntityManager("fieldaccess");
    em1.getTransaction().begin();
    em2.getTransaction().begin();
    RuntimeException caughtException = null;
    try {
        GoldBuyer buyer1 = em1.find(GoldBuyer.class, buyerId);
        GoldBuyer buyer2 = em2.find(GoldBuyer.class, buyerId);
        buyer1.setName("Geezer");
        buyer2.setName("Guyzer");
        // Uses field locking, so need to update version.
        buyer1.setVersion(buyer1.getVersion() + 1);
        buyer2.setVersion(buyer2.getVersion() + 1);
        em1.getTransaction().commit();
        em2.getTransaction().commit();
        em1.close();
        em2.close();
    } catch (RuntimeException e) {
        caughtException = e;
        if (em1.getTransaction().isActive()) {
            em1.getTransaction().rollback();
        }
        if (em2.getTransaction().isActive()) {
            em2.getTransaction().rollback();
        }
        em1.close();
        em2.close();
    }
    if (caughtException == null) {
        fail("Optimistic lock exception was not thrown.");
    } else if (!(caughtException.getCause() instanceof jakarta.persistence.OptimisticLockException)) {
        // Re-throw exception to ensure stacktrace appears in test result.
        throw caughtException;
    }
}
Also used : EntityManager(jakarta.persistence.EntityManager) GoldBuyer(org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.GoldBuyer)

Example 4 with GoldBuyer

use of org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.GoldBuyer in project eclipselink by eclipse-ee4j.

the class AdvancedJPAJunitTest method testVerifyNewBuyer.

/**
 * Verifies:
 * - BasicMap mapping with a TypeConverter on the map value and an
 *   ObjectTypeConverter on the map key.
 * - Basic with a custom converter
 * - Serialized Basic of type EnumSet.
 */
public void testVerifyNewBuyer() {
    EntityManager em = createEntityManager("fieldaccess");
    beginTransaction(em);
    try {
        GoldBuyer buyer = em.find(GoldBuyer.class, buyerId);
        assertNotNull("The new buyer was not found", buyer);
        assertTrue("Gender was not persisted correctly.", buyer.isMale());
        assertTrue("Visa card did not persist correctly.", buyer.hasVisa(visa));
        assertTrue("Amex card did not persist correctly.", buyer.hasAmex(amex));
        assertTrue("Diners Club card did not persist correctly.", buyer.hasDinersClub(diners));
        assertTrue("Mastercard card did not persist correctly.", buyer.hasMastercard(mastercard));
        assertTrue("The serialized enum set was not persisted correctly.", buyer.buysSaturdayToSunday());
        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);
}
Also used : EntityManager(jakarta.persistence.EntityManager) GoldBuyer(org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.GoldBuyer)

Aggregations

GoldBuyer (org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.GoldBuyer)4 EntityManager (jakarta.persistence.EntityManager)3 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 EquipmentCode (org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.EquipmentCode)1 FormerEmployment (org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.FormerEmployment)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 SmallProject (org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.SmallProject)1 SuperLargeProject (org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.SuperLargeProject)1