Search in sources :

Example 1 with RedStripe

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

the class InheritedModelJunitTest method testVersionUpdateOnElementCollectionChange.

public void testVersionUpdateOnElementCollectionChange() {
    EntityManager em = createEntityManager();
    beginTransaction(em);
    try {
        BeerConsumer beerConsumer = (BeerConsumer) em.createQuery("select b from BeerConsumer b join b.redStripes r").getResultList().get(0);
        int currentVersion = beerConsumer.getVersion();
        beerConsumer.getRedStripes().put("version", new RedStripe(Double.valueOf("343")));
        commitTransaction(em);
        assertTrue("Did not increment version for change to element collection", beerConsumer.getVersion() == ++currentVersion);
    } 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) RedStripe(org.eclipse.persistence.testing.models.jpa.inherited.RedStripe) 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 RedStripe

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

the class InheritedModelJunitTest method testEmbeddableAggregateCollectionAndAggregate.

// Bug 334175
public void testEmbeddableAggregateCollectionAndAggregate() {
    EntityManager em = createEntityManager();
    beginTransaction(em);
    BeerConsumer consumer = new BeerConsumer();
    consumer.setName("Lionel");
    RedStripe rs = new RedStripe();
    rs.setAlcoholContent(4.5);
    consumer.addRedStripeByAlcoholContent(rs);
    em.persist(consumer);
    Official official = new Official();
    official.setName("George");
    rs = new RedStripe();
    rs.setAlcoholContent(4.6);
    official.setLastRedStripeConsumed(rs);
    em.persist(official);
    em.flush();
    em.clear();
    clearCache();
    consumer = em.find(BeerConsumer.class, consumer.getId());
    assertNotNull("BeerConsumer had null red stripes.", consumer.getRedStripes());
    assertTrue("BeerConsumer had wrong number of red stripes.", consumer.getRedStripesByAlcoholContent().size() == 1);
    assertTrue("BeerConsumer had wrong red stripe.", consumer.getRedStripesByAlcoholContent().get(4.5) != null);
    official = em.find(Official.class, official.getId());
    assertNotNull("Official had null red stripe.", official.getLastRedStripeConsumed());
    assertTrue("Official had the wrong red stripe", official.getLastRedStripeConsumed().getAlcoholContent() == 4.6);
    rollbackTransaction(em);
}
Also used : EntityManager(jakarta.persistence.EntityManager) RedStripe(org.eclipse.persistence.testing.models.jpa.inherited.RedStripe) Official(org.eclipse.persistence.testing.models.jpa.inherited.Official) 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 3 with RedStripe

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

the class InheritedModelJunitTest method testRedStripeExpertConsumer.

public void testRedStripeExpertConsumer() {
    EntityManager em = createEntityManager();
    beginTransaction(em);
    ExpertBeerConsumer initialEBC = new ExpertBeerConsumer();
    initialEBC.setAccredidation(new Accredidation());
    int beerConsumerId = 0;
    try {
        RedStripe redStripe1 = new RedStripe();
        redStripe1.setAlcoholContent(5.0);
        initialEBC.addRedStripeBeersToConsume(redStripe1, "1");
        RedStripe redStripe2 = new RedStripe();
        redStripe2.setAlcoholContent(5.0);
        initialEBC.addRedStripeBeersToConsume(redStripe2, "2");
        initialEBC.setName("Expert Red Stripe Consumer");
        em.persist(initialEBC);
        beerConsumerId = initialEBC.getId();
        commitTransaction(em);
    } catch (RuntimeException e) {
        e.printStackTrace();
        if (isTransactionActive(em)) {
            rollbackTransaction(em);
        }
        closeEntityManager(em);
        fail("An exception was caught during create operation: [" + e.getMessage() + "]");
    }
    closeEntityManager(em);
    clearCache();
    em = createEntityManager();
    ExpertBeerConsumer refreshedEBC = em.find(ExpertBeerConsumer.class, beerConsumerId);
    assertTrue("The expert beer consumer read back did not match the original", getServerSession().compareObjects(initialEBC, refreshedEBC));
}
Also used : EntityManager(jakarta.persistence.EntityManager) ExpertBeerConsumer(org.eclipse.persistence.testing.models.jpa.inherited.ExpertBeerConsumer) RedStripe(org.eclipse.persistence.testing.models.jpa.inherited.RedStripe) Accredidation(org.eclipse.persistence.testing.models.jpa.inherited.Accredidation)

Example 4 with RedStripe

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

the class InheritedModelJunitTest method testRedStripeNoviceConsumer.

public void testRedStripeNoviceConsumer() {
    EntityManager em = createEntityManager();
    beginTransaction(em);
    NoviceBeerConsumer initialNBC = new NoviceBeerConsumer();
    initialNBC.setAccredidation(new Accredidation());
    int beerConsumerId = 0;
    try {
        RedStripe redStripe1 = new RedStripe();
        redStripe1.setAlcoholContent(5.0);
        initialNBC.addRedStripeBeersToConsume(redStripe1, "3");
        RedStripe redStripe2 = new RedStripe();
        redStripe2.setAlcoholContent(5.0);
        initialNBC.addRedStripeBeersToConsume(redStripe2, "4");
        initialNBC.setName("Novice Red Stripe Consumer");
        em.persist(initialNBC);
        beerConsumerId = initialNBC.getId();
        commitTransaction(em);
    } catch (RuntimeException e) {
        e.printStackTrace();
        if (isTransactionActive(em)) {
            rollbackTransaction(em);
        }
        closeEntityManager(em);
        fail("An exception was caught during create operation: [" + e.getMessage() + "]");
    }
    closeEntityManager(em);
    clearCache();
    em = createEntityManager();
    NoviceBeerConsumer refreshedNBC = em.find(NoviceBeerConsumer.class, beerConsumerId);
    assertTrue("The novice beer consumer read back did not match the original", getServerSession().compareObjects(initialNBC, refreshedNBC));
}
Also used : EntityManager(jakarta.persistence.EntityManager) NoviceBeerConsumer(org.eclipse.persistence.testing.models.jpa.inherited.NoviceBeerConsumer) RedStripe(org.eclipse.persistence.testing.models.jpa.inherited.RedStripe) Accredidation(org.eclipse.persistence.testing.models.jpa.inherited.Accredidation)

Example 5 with RedStripe

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

the class InheritedModelJunitTest method testElementCollectionMapEmbeddable.

public void testElementCollectionMapEmbeddable() {
    EntityManager em = createEntityManager();
    try {
        // Create an official
        beginTransaction(em);
        BeerConsumer consumer = new BeerConsumer();
        consumer.setName("Lionel");
        RedStripe rs = new RedStripe();
        rs.setAlcoholContent(4.5);
        consumer.addRedStripeByAlcoholContent(rs);
        em.persist(consumer);
        em.flush();
        rs = new RedStripe();
        rs.setAlcoholContent(3.5);
        consumer.addRedStripeByAlcoholContent(rs);
        em.flush();
    } finally {
        rollbackTransaction(em);
    }
}
Also used : EntityManager(jakarta.persistence.EntityManager) RedStripe(org.eclipse.persistence.testing.models.jpa.inherited.RedStripe) 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)

Aggregations

EntityManager (jakarta.persistence.EntityManager)6 RedStripe (org.eclipse.persistence.testing.models.jpa.inherited.RedStripe)6 ExpertBeerConsumer (org.eclipse.persistence.testing.models.jpa.inherited.ExpertBeerConsumer)5 NoviceBeerConsumer (org.eclipse.persistence.testing.models.jpa.inherited.NoviceBeerConsumer)5 BeerConsumer (org.eclipse.persistence.testing.models.jpa.inherited.BeerConsumer)4 Accredidation (org.eclipse.persistence.testing.models.jpa.inherited.Accredidation)2 BigInteger (java.math.BigInteger)1 Official (org.eclipse.persistence.testing.models.jpa.inherited.Official)1