Search in sources :

Example 1 with CoronaTag

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

the class InheritedModelJunitTest method testCoronaBeerConsumer.

public void testCoronaBeerConsumer() {
    EntityManager em = createEntityManager();
    beginTransaction(em);
    BeerConsumer initialBC = new BeerConsumer();
    int beerConsumerId = 0;
    try {
        Corona corona1 = new Corona();
        corona1.setAlcoholContent(5.3);
        CoronaTag coronaTag1 = new CoronaTag();
        coronaTag1.setCode("0A");
        coronaTag1.setNumber(789);
        Corona corona2 = new Corona();
        corona2.setAlcoholContent(5.3);
        CoronaTag coronaTag2 = new CoronaTag();
        coronaTag2.setCode("BX");
        coronaTag2.setNumber(521);
        Corona corona3 = new Corona();
        corona3.setAlcoholContent(5.3);
        CoronaTag coronaTag3 = new CoronaTag();
        coronaTag3.setCode("UY");
        coronaTag3.setNumber(429);
        initialBC.setName("Corona Consumer");
        initialBC.addCoronaBeerToConsume(corona1, coronaTag1);
        initialBC.addCoronaBeerToConsume(corona2, coronaTag2);
        initialBC.addCoronaBeerToConsume(corona3, coronaTag3);
        em.persist(initialBC);
        beerConsumerId = initialBC.getId();
        commitTransaction(em);
    } catch (RuntimeException e) {
        if (isTransactionActive(em)) {
            rollbackTransaction(em);
        }
        closeEntityManager(em);
        fail("An exception was caught during create operation: [" + e.getMessage() + "]");
    }
    closeEntityManager(em);
    clearCache();
    em = createEntityManager();
    BeerConsumer refreshedBC = em.find(BeerConsumer.class, beerConsumerId);
    assertTrue("The beer consumer read back did not match the original", getServerSession().compareObjects(initialBC, refreshedBC));
}
Also used : EntityManager(jakarta.persistence.EntityManager) CoronaTag(org.eclipse.persistence.testing.models.jpa.inherited.CoronaTag) Corona(org.eclipse.persistence.testing.models.jpa.inherited.Corona) ExpertBeerConsumer(org.eclipse.persistence.testing.models.jpa.inherited.ExpertBeerConsumer) BeerConsumer(org.eclipse.persistence.testing.models.jpa.inherited.BeerConsumer) NoviceBeerConsumer(org.eclipse.persistence.testing.models.jpa.inherited.NoviceBeerConsumer)

Example 2 with CoronaTag

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

the class JUnitJPQLComplexTestSuite method mappedKeyMapContainerPolicyNavigateMapKeyInEmbeddableTest.

public void mappedKeyMapContainerPolicyNavigateMapKeyInEmbeddableTest() {
    // 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);
        Corona corona = new Corona();
        corona.setAlcoholContent(5.0);
        CoronaTag tag = new CoronaTag();
        tag.setCode("123");
        tag.setNumber(123);
        consumer.addCoronaBeerToConsume(corona, tag);
        em.persist(corona);
        BeerConsumer consumer2 = new BeerConsumer();
        consumer2.setName("Marvin Monroe2");
        em.persist(consumer2);
        Corona corona2 = new Corona();
        corona2.setAlcoholContent(5.0);
        CoronaTag tag2 = new CoronaTag();
        tag2.setCode("1234");
        tag2.setNumber(1234);
        consumer2.addCoronaBeerToConsume(corona2, tag2);
        em.persist(corona2);
        em.flush();
        Vector expectedResult = new Vector();
        expectedResult.add("123");
        clearCache();
        String ejbqlString = "SELECT KEY(c).code from BeerConsumer bc join bc.coronaBeersToConsume c where bc.name = 'Marvin Monroe'";
        List result = em.createQuery(ejbqlString).getResultList();
        Assert.assertTrue("mappedKeyMapContainerPolicyNavigateMapKeyInEmbeddableTest 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) CoronaTag(org.eclipse.persistence.testing.models.jpa.inherited.CoronaTag) Corona(org.eclipse.persistence.testing.models.jpa.inherited.Corona) 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) Vector(java.util.Vector)

Example 3 with CoronaTag

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

the class JUnitJPQLComplexTestSuite method mappedKeyMapContainerPolicyEmbeddableMapKeyInSelectionCriteriaTest.

public void mappedKeyMapContainerPolicyEmbeddableMapKeyInSelectionCriteriaTest() {
    // 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);
        Corona corona = new Corona();
        corona.setAlcoholContent(5.0);
        CoronaTag tag = new CoronaTag();
        tag.setCode("123");
        tag.setNumber(123);
        consumer.addCoronaBeerToConsume(corona, tag);
        em.persist(corona);
        BeerConsumer consumer2 = new BeerConsumer();
        consumer2.setName("Marvin Monroe2");
        em.persist(consumer2);
        Corona corona2 = new Corona();
        corona2.setAlcoholContent(5.0);
        CoronaTag tag2 = new CoronaTag();
        tag2.setCode("1234");
        tag2.setNumber(1234);
        consumer2.addCoronaBeerToConsume(corona2, tag2);
        em.persist(corona2);
        em.flush();
        Vector expectedResult = new Vector();
        expectedResult.add(consumer);
        clearCache();
        String ejbqlString = "SELECT bc FROM BeerConsumer bc join bc.coronaBeersToConsume b where Key(b).code = :key";
        List result = em.createQuery(ejbqlString).setParameter("key", "123").getResultList();
        Assert.assertTrue("mappedKeyMapContainerPolicyEmbeddableMapKeyInSelectionCriteriaTest 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) CoronaTag(org.eclipse.persistence.testing.models.jpa.inherited.CoronaTag) Corona(org.eclipse.persistence.testing.models.jpa.inherited.Corona) 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) Vector(java.util.Vector)

Aggregations

EntityManager (jakarta.persistence.EntityManager)3 BeerConsumer (org.eclipse.persistence.testing.models.jpa.inherited.BeerConsumer)3 Corona (org.eclipse.persistence.testing.models.jpa.inherited.Corona)3 CoronaTag (org.eclipse.persistence.testing.models.jpa.inherited.CoronaTag)3 ExpertBeerConsumer (org.eclipse.persistence.testing.models.jpa.inherited.ExpertBeerConsumer)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Vector (java.util.Vector)2 JpaEntityManager (org.eclipse.persistence.jpa.JpaEntityManager)2 Oc4jPlatform (org.eclipse.persistence.platform.server.oc4j.Oc4jPlatform)2 NoviceBeerConsumer (org.eclipse.persistence.testing.models.jpa.inherited.NoviceBeerConsumer)1