Search in sources :

Example 1 with Alpine

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

the class EmbeddableSuperclassJunitTest method testInsertNewAlpine.

public void testInsertNewAlpine() {
    Alpine alpine = null;
    EntityManager em = createEntityManager();
    // Part 1 ... add an alpine beer to the collection.
    BeerConsumer beerConsumer = em.find(BeerConsumer.class, m_beerConsumerId2);
    beginTransaction(em);
    try {
        beerConsumer = em.merge(beerConsumer);
        SerialNumber serialNumber = new SerialNumber();
        em.persist(serialNumber);
        alpine = new Alpine(serialNumber);
        em.persist(alpine);
        alpine.setBestBeforeDate(Helper.dateFromYearMonthDate(2005, 8, 18));
        alpine.setAlcoholContent(5.4);
        alpine.setClassification(Alpine.Classification.BITTER);
        beerConsumer.addAlpineBeerToConsume(alpine, 0);
        commitTransaction(em);
    } catch (RuntimeException e) {
        if (isTransactionActive(em)) {
            rollbackTransaction(em);
        }
        closeEntityManager(em);
        throw e;
    }
    // Part 2 ... read from cache.
    beerConsumer = em.find(BeerConsumer.class, m_beerConsumerId2);
    // Read the beerConsumer back from the cache, check the ordering.
    Vector alpinesFromCache = (Vector) beerConsumer.getAlpineBeersToConsume();
    assertTrue("The new alpine was not added at the correct index in the cache.", alpinesFromCache.indexOf(alpine) == 0);
    // Part 3 ... read from database.
    clearCache();
    em.clear();
    beerConsumer = em.find(BeerConsumer.class, m_beerConsumerId2);
    // Read the beerConsumer back from the database, check the ordering.
    Vector alpinesFromDB = (Vector) beerConsumer.getAlpineBeersToConsume();
    assertTrue("The new alpine was not added at the correct index when retrieving from the database.", alpinesFromDB.indexOf(alpine) == 1);
}
Also used : EntityManager(jakarta.persistence.EntityManager) SerialNumber(org.eclipse.persistence.testing.models.jpa.inherited.SerialNumber) Alpine(org.eclipse.persistence.testing.models.jpa.inherited.Alpine) BeerConsumer(org.eclipse.persistence.testing.models.jpa.inherited.BeerConsumer) Vector(java.util.Vector)

Example 2 with Alpine

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

the class EmbeddableSuperclassJunitTest method testReadAlpine.

public void testReadAlpine() {
    Alpine alpine = createEntityManager().find(Alpine.class, m_alpineId);
    assertTrue("Error on reading back an Alpine beer", alpine != null);
    assertTrue("The enum was not read back in properly.", alpine.getClassification() == Alpine.Classification.BITTER);
}
Also used : Alpine(org.eclipse.persistence.testing.models.jpa.inherited.Alpine)

Example 3 with Alpine

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

the class EmbeddableSuperclassJunitTest method testUpdateAlpine.

public void testUpdateAlpine() {
    EntityManager em = createEntityManager();
    beginTransaction(em);
    try {
        Alpine alpine = em.find(Alpine.class, m_alpineId);
        alpine.setBestBeforeDate(Helper.dateFromYearMonthDate(2005, 8, 19));
        em.merge(alpine);
        commitTransaction(em);
    } catch (RuntimeException e) {
        if (isTransactionActive(em)) {
            rollbackTransaction(em);
        }
        closeEntityManager(em);
        throw e;
    }
    clearCache();
    em.clear();
    Alpine newAlpine = em.find(Alpine.class, m_alpineId);
    assertTrue("Error updating an Alpine beer.", newAlpine.getBestBeforeDate().equals(Helper.dateFromYearMonthDate(2005, 8, 19)));
}
Also used : EntityManager(jakarta.persistence.EntityManager) Alpine(org.eclipse.persistence.testing.models.jpa.inherited.Alpine)

Example 4 with Alpine

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

the class EmbeddableSuperclassJunitTest method testInsertNewAlpineAndModifyOrderOfExistingAlpines.

public void testInsertNewAlpineAndModifyOrderOfExistingAlpines() {
    Alpine alpine1 = null, alpine2 = null;
    EntityManager em = createEntityManager();
    // Part 1 ... add an alpine beer to the collection.
    BeerConsumer beerConsumer = em.find(BeerConsumer.class, m_beerConsumerId2);
    beginTransaction(em);
    try {
        beerConsumer = em.merge(beerConsumer);
        SerialNumber serialNumber = new SerialNumber();
        em.persist(serialNumber);
        alpine1 = new Alpine(serialNumber);
        em.persist(alpine1);
        alpine1.setBestBeforeDate(Helper.dateFromYearMonthDate(2005, 8, 16));
        alpine1.setAlcoholContent(5.6);
        alpine1.setClassification(Alpine.Classification.STRONG);
        beerConsumer.addAlpineBeerToConsume(alpine1, 0);
        // Part 2 ... change the date, hence the index, of an alpine.
        alpine2 = beerConsumer.getAlpineBeerToConsume(4);
        alpine2.setBestBeforeDate(Helper.dateFromYearMonthDate(2005, 8, 20));
        beerConsumer.moveAlpineBeerToConsume(4, 3);
        // Part 3 ... remove 2 alpines ...
        beerConsumer.removeAlpineBeerToConsume(4);
        beerConsumer.removeAlpineBeerToConsume(2);
        commitTransaction(em);
    } catch (RuntimeException e) {
        if (isTransactionActive(em)) {
            rollbackTransaction(em);
        }
        closeEntityManager(em);
        throw e;
    }
    // Part 3 ... read from cache.
    beerConsumer = em.find(BeerConsumer.class, m_beerConsumerId2);
    // Read the beerConsumer back from the cache, check the ordering.
    Vector alpinesFromCache = (Vector) beerConsumer.getAlpineBeersToConsume();
    assertTrue("The new alpine was not added at the correct index in the cache.", alpinesFromCache.indexOf(alpine1) == 0);
    assertTrue("The alpine was not moved to the correct index in the cache.", alpinesFromCache.indexOf(alpine2) == 2);
    // Part 4 ... read from database.
    clearCache();
    em.clear();
    beerConsumer = em.find(BeerConsumer.class, m_beerConsumerId2);
    // Read the beerConsumer back from the database, check the ordering.
    Vector alpinesFromDB = (Vector) beerConsumer.getAlpineBeersToConsume();
    assertTrue("The new alpine was not added at the correct index when retrieving from the database.", alpinesFromDB.indexOf(alpine1) == 0);
    assertTrue("The alpine was not moved to the correct index when retrieving from the database.", alpinesFromDB.indexOf(alpine2) == 2);
}
Also used : EntityManager(jakarta.persistence.EntityManager) SerialNumber(org.eclipse.persistence.testing.models.jpa.inherited.SerialNumber) Alpine(org.eclipse.persistence.testing.models.jpa.inherited.Alpine) BeerConsumer(org.eclipse.persistence.testing.models.jpa.inherited.BeerConsumer) Vector(java.util.Vector)

Example 5 with Alpine

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

the class EmbeddableSuperclassJunitTest method testUpdateAlpineThroughBeerConsumer.

public void testUpdateAlpineThroughBeerConsumer() {
    int id = 0;
    EntityManager em = createEntityManager();
    beginTransaction(em);
    try {
        BeerConsumer beerConsumer = em.find(BeerConsumer.class, m_beerConsumerId2);
        Alpine alpine = (Alpine) beerConsumer.getAlpineBeersToConsume().iterator().next();
        alpine.setBestBeforeDate(Helper.dateFromYearMonthDate(2005, 9, 19));
        id = alpine.getId();
        commitTransaction(em);
    } catch (RuntimeException e) {
        if (isTransactionActive(em)) {
            rollbackTransaction(em);
        }
        closeEntityManager(em);
        throw e;
    }
    clearCache();
    em.clear();
    Alpine newAlpine = em.find(Alpine.class, id);
    closeEntityManager(em);
    assertTrue("Error updating an Alpine beer.", newAlpine.getBestBeforeDate().equals(Helper.dateFromYearMonthDate(2005, 9, 19)));
}
Also used : EntityManager(jakarta.persistence.EntityManager) Alpine(org.eclipse.persistence.testing.models.jpa.inherited.Alpine) BeerConsumer(org.eclipse.persistence.testing.models.jpa.inherited.BeerConsumer)

Aggregations

Alpine (org.eclipse.persistence.testing.models.jpa.inherited.Alpine)16 EntityManager (jakarta.persistence.EntityManager)15 BeerConsumer (org.eclipse.persistence.testing.models.jpa.inherited.BeerConsumer)11 SerialNumber (org.eclipse.persistence.testing.models.jpa.inherited.SerialNumber)10 Date (java.util.Date)5 Vector (java.util.Vector)5 ExpertBeerConsumer (org.eclipse.persistence.testing.models.jpa.inherited.ExpertBeerConsumer)2 BigDecimal (java.math.BigDecimal)1 BigInteger (java.math.BigInteger)1 BlueLight (org.eclipse.persistence.testing.models.jpa.inherited.BlueLight)1 NoviceBeerConsumer (org.eclipse.persistence.testing.models.jpa.inherited.NoviceBeerConsumer)1