Search in sources :

Example 1 with TelephoneNumber

use of org.eclipse.persistence.testing.models.jpa.inherited.TelephoneNumber in project eclipselink by eclipse-ee4j.

the class EmbeddableSuperclassJunitTest method testUpdateTelephoneNumberThroughBeerConsumer.

public void testUpdateTelephoneNumberThroughBeerConsumer() {
    TelephoneNumber oldPhone = null, newPhone = null;
    EntityManager em = createEntityManager();
    beginTransaction(em);
    try {
        BeerConsumer beerConsumer = em.find(BeerConsumer.class, m_beerConsumerId1);
        oldPhone = (TelephoneNumber) beerConsumer.getTelephoneNumbers().values().iterator().next();
        beerConsumer.removePhoneNumber(oldPhone);
        em.remove(oldPhone);
        newPhone = new TelephoneNumber();
        newPhone.setAreaCode("XXX");
        newPhone.setNumber(oldPhone.getNumber());
        newPhone.setType(oldPhone.getType());
        beerConsumer.addTelephoneNumber(newPhone);
        commitTransaction(em);
    } catch (RuntimeException e) {
        if (isTransactionActive(em)) {
            rollbackTransaction(em);
        }
        closeEntityManager(em);
        throw e;
    }
    clearCache();
    BeerConsumer bc = em.find(BeerConsumer.class, m_beerConsumerId1);
    assertTrue("The new/updated phone was not persisted.", bc.hasTelephoneNumber(newPhone));
    assertFalse("The old phone was not removed.", bc.hasTelephoneNumber(oldPhone));
}
Also used : EntityManager(jakarta.persistence.EntityManager) BeerConsumer(org.eclipse.persistence.testing.models.jpa.inherited.BeerConsumer) TelephoneNumber(org.eclipse.persistence.testing.models.jpa.inherited.TelephoneNumber)

Example 2 with TelephoneNumber

use of org.eclipse.persistence.testing.models.jpa.inherited.TelephoneNumber in project eclipselink by eclipse-ee4j.

the class EmbeddableSuperclassJunitTest method testShuffleTelephoneNumbersOnBeerConsumers.

public void testShuffleTelephoneNumbersOnBeerConsumers() {
    int beerConsumer1TelephoneCountStart = 0, beerConsumer2TelephoneCountStart = 0;
    EntityManager em = createEntityManager();
    beginTransaction(em);
    try {
        BeerConsumer beerConsumer1 = em.find(BeerConsumer.class, m_beerConsumerId1);
        beerConsumer1TelephoneCountStart = beerConsumer1.getTelephoneNumbers().size();
        BeerConsumer beerConsumer2 = em.find(BeerConsumer.class, m_beerConsumerId2);
        beerConsumer2TelephoneCountStart = beerConsumer2.getTelephoneNumbers().size();
        TelephoneNumber phone = (TelephoneNumber) beerConsumer1.getTelephoneNumbers().values().iterator().next();
        phone.setBeerConsumer(beerConsumer2);
        commitTransaction(em);
    } catch (RuntimeException e) {
        if (isTransactionActive(em)) {
            rollbackTransaction(em);
        }
        closeEntityManager(em);
        throw e;
    }
    clearCache();
    em.clear();
    BeerConsumer newBeerConsumer1 = em.find(BeerConsumer.class, m_beerConsumerId1);
    int beerConsumer1TelephoneCountEnd = newBeerConsumer1.getTelephoneNumbers().size();
    BeerConsumer newBeerConsumer2 = em.find(BeerConsumer.class, m_beerConsumerId2);
    int beerConsumer2TelephoneCountEnd = newBeerConsumer2.getTelephoneNumbers().size();
    assertTrue("Error updating a TelephoneNumber's beer consumer", beerConsumer1TelephoneCountEnd + 1 == beerConsumer1TelephoneCountStart);
    assertTrue("Error updating a TelephoneNumber's beer consumer", beerConsumer2TelephoneCountEnd - 1 == beerConsumer2TelephoneCountStart);
}
Also used : EntityManager(jakarta.persistence.EntityManager) BeerConsumer(org.eclipse.persistence.testing.models.jpa.inherited.BeerConsumer) TelephoneNumber(org.eclipse.persistence.testing.models.jpa.inherited.TelephoneNumber)

Example 3 with TelephoneNumber

use of org.eclipse.persistence.testing.models.jpa.inherited.TelephoneNumber in project eclipselink by eclipse-ee4j.

the class JUnitJPQLComplexTestSuite method mappedContainerPolicyCompoundMapKeyTest.

public void mappedContainerPolicyCompoundMapKeyTest() {
    // skip test on OC4j some this test fails on some OC4j versions because of an issue with Timestamp
    if (getServerSession().getServerPlatform() != null && getServerSession().getServerPlatform() instanceof Oc4jPlatform) {
        return;
    }
    EntityManager em = createEntityManager();
    beginTransaction(em);
    try {
        BeerConsumer consumer = new BeerConsumer();
        consumer.setName("Marvin Monroe");
        em.persist(consumer);
        TelephoneNumber number = new TelephoneNumber();
        number.setType("Home");
        number.setAreaCode("975");
        number.setNumber("1234567");
        em.persist(number);
        consumer.addTelephoneNumber(number);
        BeerConsumer consumer2 = new BeerConsumer();
        consumer2.setName("Marvin Monroe2");
        em.persist(consumer2);
        TelephoneNumber number2 = new TelephoneNumber();
        number2.setType("Home");
        number2.setAreaCode("974");
        number2.setNumber("1234567");
        em.persist(number2);
        consumer2.addTelephoneNumber(number2);
        em.flush();
        Vector expectedResult = new Vector();
        expectedResult.add(number);
        clearCache();
        String ejbqlString = "SELECT KEY(number) from BeerConsumer bc join bc.telephoneNumbers number where bc.name = 'Marvin Monroe'";
        List result = em.createQuery(ejbqlString).getResultList();
        Assert.assertTrue("mappedContainerPolicyCompoundMapKeyTest failed", comparer.compareObjects(result, expectedResult));
    } finally {
        rollbackTransaction(em);
        closeEntityManager(em);
    }
}
Also used : EntityManager(jakarta.persistence.EntityManager) JpaEntityManager(org.eclipse.persistence.jpa.JpaEntityManager) Oc4jPlatform(org.eclipse.persistence.platform.server.oc4j.Oc4jPlatform) List(java.util.List) ArrayList(java.util.ArrayList) ExpertBeerConsumer(org.eclipse.persistence.testing.models.jpa.inherited.ExpertBeerConsumer) BeerConsumer(org.eclipse.persistence.testing.models.jpa.inherited.BeerConsumer) TelephoneNumber(org.eclipse.persistence.testing.models.jpa.inherited.TelephoneNumber) Vector(java.util.Vector)

Example 4 with TelephoneNumber

use of org.eclipse.persistence.testing.models.jpa.inherited.TelephoneNumber in project eclipselink by eclipse-ee4j.

the class EmbeddableSuperclassJunitTest method testCreateTelephoneNumbers.

public void testCreateTelephoneNumbers() {
    EntityManager em = createEntityManager();
    beginTransaction(em);
    try {
        BeerConsumer beerConsumer1 = em.find(BeerConsumer.class, m_beerConsumerId1);
        TelephoneNumber telephoneNumber1 = new TelephoneNumber();
        telephoneNumber1.setType("Home");
        telephoneNumber1.setAreaCode("975");
        telephoneNumber1.setNumber("1234567");
        beerConsumer1.addTelephoneNumber(telephoneNumber1);
        TelephoneNumber telephoneNumber2 = new TelephoneNumber();
        telephoneNumber2.setType("Cell");
        telephoneNumber2.setAreaCode("975");
        telephoneNumber2.setNumber("7654321");
        beerConsumer1.addTelephoneNumber(telephoneNumber2);
        BeerConsumer beerConsumer2 = em.find(BeerConsumer.class, m_beerConsumerId2);
        TelephoneNumber telephoneNumber3 = new TelephoneNumber();
        telephoneNumber3.setType("Home");
        telephoneNumber3.setAreaCode("555");
        telephoneNumber3.setNumber("5555555");
        beerConsumer2.addTelephoneNumber(telephoneNumber3);
        TelephoneNumber telephoneNumber4 = new TelephoneNumber();
        telephoneNumber4.setType("Cell");
        telephoneNumber4.setAreaCode("555");
        telephoneNumber4.setNumber("3331010");
        beerConsumer2.addTelephoneNumber(telephoneNumber4);
        TelephoneNumber telephoneNumber5 = new TelephoneNumber();
        telephoneNumber5.setType("Work");
        telephoneNumber5.setAreaCode("999");
        telephoneNumber5.setNumber("8648363");
        beerConsumer2.addTelephoneNumber(telephoneNumber5);
        commitTransaction(em);
    } catch (RuntimeException e) {
        if (isTransactionActive(em)) {
            rollbackTransaction(em);
        }
        closeEntityManager(em);
        fail("An exception was caught during create operation: [" + e.getMessage() + "]");
    }
    closeEntityManager(em);
}
Also used : EntityManager(jakarta.persistence.EntityManager) BeerConsumer(org.eclipse.persistence.testing.models.jpa.inherited.BeerConsumer) TelephoneNumber(org.eclipse.persistence.testing.models.jpa.inherited.TelephoneNumber)

Aggregations

EntityManager (jakarta.persistence.EntityManager)4 BeerConsumer (org.eclipse.persistence.testing.models.jpa.inherited.BeerConsumer)4 TelephoneNumber (org.eclipse.persistence.testing.models.jpa.inherited.TelephoneNumber)4 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Vector (java.util.Vector)1 JpaEntityManager (org.eclipse.persistence.jpa.JpaEntityManager)1 Oc4jPlatform (org.eclipse.persistence.platform.server.oc4j.Oc4jPlatform)1 ExpertBeerConsumer (org.eclipse.persistence.testing.models.jpa.inherited.ExpertBeerConsumer)1