Search in sources :

Example 1 with Official

use of org.eclipse.persistence.testing.models.jpa.inherited.Official 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 2 with Official

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

the class InheritedModelJunitTest method testColumnUpdatableAndInsertable.

public void testColumnUpdatableAndInsertable() {
    EntityManager em = createEntityManager();
    try {
        // Create an official
        beginTransaction(em);
        OfficialEntry officialEntry = new OfficialEntry();
        em.persist(officialEntry);
        Official initialOfficial = new Official();
        // insertable=true, updatable=false
        initialOfficial.setName("Gui Pelletier");
        // insertable=false, updatable=true
        initialOfficial.setAge(25);
        // insertable=true, updatable=false
        initialOfficial.setSalary(50000);
        // insertable=false, updatable=true
        initialOfficial.setBonus(10000);
        // Tests multiple mappings to the same column. The M-1 is read only
        // and the basic is the writable mapping.
        // insertable=false, updatable=false
        initialOfficial.setOfficialEntry(officialEntry);
        // insertable=true, updatable=true
        initialOfficial.setOfficialEntryId(officialEntry.getId());
        ServiceTime service = new ServiceTime();
        // insertable=true, updatable=false
        service.setStartDate("Jan 1, 2008");
        // insertable=false, updatable=true
        service.setEndDate("Jul 1, 2010");
        initialOfficial.setServiceTime(service);
        em.persist(initialOfficial);
        commitTransaction(em);
        // Close the EM, clear cache and get new EM.
        closeEntityManager(em);
        clearCache();
        em = createEntityManager();
        // Read the official and verify its content
        beginTransaction(em);
        Official official = em.find(Official.class, initialOfficial.getId());
        assertTrue("The name was not inserted", official.getName().equals("Gui Pelletier"));
        assertTrue("The age was inserted", official.getAge() == null);
        assertTrue("The salary was not inserted", official.getSalary() == 50000);
        assertTrue("The bonus was inserted", official.getBonus() == null);
        assertTrue("The official entry was not inserted", official.getOfficialEntryId() == officialEntry.getId());
        assertTrue("The embeddable start date was not inserted", official.getServiceTime().getStartDate().equals("Jan 1, 2008"));
        assertTrue("The embeddable end date was inserted", official.getServiceTime().getEndDate() == null);
        // Change the updatable=false fields:
        official.setName("Guy Pelletier");
        official.setSalary(100000);
        official.getServiceTime().setStartDate("Jan 30, 2008");
        // Update the insertable=false fields:
        official.setAge(25);
        official.setBonus(10000);
        official.getServiceTime().setEndDate("Jul 1, 2010");
        commitTransaction(em);
        // Close the EM, clear cache and get new EM.
        closeEntityManager(em);
        clearCache();
        em = createEntityManager();
        // The refreshed official at this point should not have had any
        // update changes to name but age should now be updated.
        Official refreshedOfficial = em.find(Official.class, initialOfficial.getId());
        assertTrue("The refreshedOfficial did not match the original", getServerSession().compareObjects(initialOfficial, refreshedOfficial));
    } catch (RuntimeException e) {
        if (isTransactionActive(em)) {
            rollbackTransaction(em);
        }
        fail("An exception was caught during create operation: [" + e.getMessage() + "]");
    } finally {
        closeEntityManager(em);
    }
}
Also used : EntityManager(jakarta.persistence.EntityManager) Official(org.eclipse.persistence.testing.models.jpa.inherited.Official) OfficialEntry(org.eclipse.persistence.testing.models.jpa.inherited.OfficialEntry) ServiceTime(org.eclipse.persistence.testing.models.jpa.inherited.ServiceTime)

Example 3 with Official

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

the class InheritedModelJunitTest method testColumnUpdatableAndInsertableThroughQuery.

public void testColumnUpdatableAndInsertableThroughQuery() {
    if ((JUnitTestCase.getServerSession()).getPlatform().isSymfoware()) {
        getServerSession().logMessage("Test testColumnUpdatableAndInsertableThroughQuery skipped for this platform, " + "Symfoware doesn't support UpdateAll/DeleteAll on multi-table objects (see rfe 298193).");
        return;
    }
    EntityManager em = createEntityManager();
    try {
        // Create an official
        beginTransaction(em);
        Official initialOfficial = new Official();
        initialOfficial.setName("Gui Pelletier");
        em.persist(initialOfficial);
        commitTransaction(em);
        // Close the EM, clear cache and get new EM.
        closeEntityManager(em);
        clearCache();
        em = createEntityManager();
        // Update the official using a named query.
        beginTransaction(em);
        Query query = em.createNamedQuery("UpdateOfficalName");
        query.setParameter("name", "Guy");
        query.setParameter("id", initialOfficial.getId());
        query.executeUpdate();
        Official modifiedOfficial = em.find(Official.class, initialOfficial.getId());
        assertTrue("The name was not updated after executing the named query", modifiedOfficial.getName().equals("Guy"));
        commitTransaction(em);
        // Close the EM, clear cache and get new EM.
        closeEntityManager(em);
        clearCache();
        em = createEntityManager();
        Official refreshedOfficial = em.find(Official.class, modifiedOfficial.getId());
        assertTrue("The refreshedOfficial did not match the modified", getServerSession().compareObjects(modifiedOfficial, refreshedOfficial));
    } catch (Exception e) {
        if (isTransactionActive(em)) {
            rollbackTransaction(em);
        }
        fail("Update query failed: " + e.getMessage());
    } finally {
        closeEntityManager(em);
    }
}
Also used : EntityManager(jakarta.persistence.EntityManager) Query(jakarta.persistence.Query) Official(org.eclipse.persistence.testing.models.jpa.inherited.Official) QueryException(org.eclipse.persistence.exceptions.QueryException)

Example 4 with Official

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

the class InheritedModelJunitTest method testCreateExpertBeerConsumer.

public void testCreateExpertBeerConsumer() {
    EntityManager em = createEntityManager();
    beginTransaction(em);
    ExpertBeerConsumer beerConsumer = new ExpertBeerConsumer();
    try {
        beerConsumer.setName("Expert Beer Consumer");
        beerConsumer.setIQ(110);
        beerConsumer.getAcclaims().add("A");
        beerConsumer.getAcclaims().add("B");
        beerConsumer.getAcclaims().add("C");
        // Commenting out this mapping until bug 272298 is resolved.
        // The compareObjects check below would fail in some configurations
        // as a result of this.
        // beerConsumer.getAudio().add(new byte[]{1});
        // beerConsumer.getAudio().add(new byte[]{2});
        // beerConsumer.getAudio().add(new byte[]{3});
        beerConsumer.getAwards().put("A", "A");
        beerConsumer.getAwards().put("B", "B");
        beerConsumer.getAwards().put("C", "C");
        beerConsumer.getDesignations().add("A");
        beerConsumer.getDesignations().add("B");
        m_quote1Stamp = Helper.timestampFromDate(Helper.dateFromYearMonthDate(2009, 1, 1));
        beerConsumer.getQuotes().put(m_quote1Stamp, QUOTE_ONE);
        m_quote2Stamp = Helper.timestampFromDate(Helper.dateFromYearMonthDate(2005, 7, 9));
        beerConsumer.getQuotes().put(m_quote2Stamp, QUOTE_TWO);
        Record record1 = new Record();
        record1.setDescription("Fastest beer ever consumed - 10 ms");
        record1.setDate(Helper.dateFromYearMonthDate(2009, 10, 10));
        record1.setLocation(new Location("Ottawa", "Canada"));
        Venue venue1 = new Venue();
        venue1.setAttendance(10000);
        venue1.setName("Scotiabank PLace");
        record1.setVenue(venue1);
        beerConsumer.getRecords().add(record1);
        Record record2 = new Record();
        record2.setDescription("Most beers consumed upside down - 12");
        record2.setDate(Helper.dateFromYearMonthDate(2007, 11, 11));
        record2.setLocation(new Location("Sydney", "Australia"));
        Venue venue2 = new Venue();
        venue2.setAttendance(2678);
        venue2.setName("Opera House");
        record2.setVenue(venue2);
        beerConsumer.getRecords().add(record2);
        Record record3 = new Record();
        record3.setDescription("Most beers consumed in a second - 5");
        record3.setDate(Helper.dateFromYearMonthDate(2005, 12, 12));
        record3.setLocation(new Location("Miami", "USA"));
        Venue venue3 = new Venue();
        venue3.setAttendance(63000);
        venue3.setName("Dolphin Stadium");
        record3.setVenue(venue3);
        beerConsumer.getRecords().add(record3);
        Accredidation accredidation = new Accredidation();
        accredidation.setDetails("Elite, absolutely elite!");
        Witness witness1 = new Witness();
        witness1.setName("Big Bobby");
        accredidation.addWitness(witness1);
        Witness witness2 = new Witness();
        witness2.setName("Little Bobby");
        accredidation.addWitness(witness2);
        Official official = new Official();
        official.setName("Authority Joe");
        accredidation.addOfficial(official);
        beerConsumer.setAccredidation(accredidation);
        Birthday birthday1 = new Birthday();
        birthday1.setDay(9);
        birthday1.setMonth(7);
        birthday1.setYear(2005);
        beerConsumer.addCelebration(birthday1, "Drank a 24 of Heineken");
        Birthday birthday2 = new Birthday();
        birthday2.setDay(10);
        birthday2.setMonth(7);
        birthday2.setYear(2006);
        beerConsumer.addCelebration(birthday2, "Drank a 24 of Becks");
        Committee committee1 = new Committee();
        committee1.setDescription("New beer committee");
        CommitteeDates committee1Dates = new CommitteeDates();
        committee1Dates.setStartDate("Jan 1, 2010");
        committee1.setCommitteeDates(committee1Dates);
        beerConsumer.addCommittee(committee1);
        Committee committee2 = new Committee();
        committee2.setDescription("Alcohol content regulation");
        CommitteeDates committee2Dates = new CommitteeDates();
        committee2Dates.setStartDate("Jan 1, 1970");
        committee2Dates.setEndDate("Jan 1, 2001");
        committee2.setCommitteeDates(committee2Dates);
        beerConsumer.addCommittee(committee2);
        em.persist(beerConsumer);
        m_expertBeerConsumerId = beerConsumer.getId();
        commitTransaction(em);
    } catch (RuntimeException e) {
        if (isTransactionActive(em)) {
            rollbackTransaction(em);
        }
        closeEntityManager(em);
        fail("An exception was caught during create operation for an expert beer consumer: [" + e.getMessage() + "]");
    }
    closeEntityManager(em);
    clearCache();
    em = createEntityManager();
    BeerConsumer refreshedBC = em.find(BeerConsumer.class, m_expertBeerConsumerId);
    assertTrue("The expert beer consumer read back did not match the original", getServerSession().compareObjects(beerConsumer, refreshedBC));
}
Also used : ExpertBeerConsumer(org.eclipse.persistence.testing.models.jpa.inherited.ExpertBeerConsumer) Venue(org.eclipse.persistence.testing.models.jpa.inherited.Venue) Birthday(org.eclipse.persistence.testing.models.jpa.inherited.Birthday) Committee(org.eclipse.persistence.testing.models.jpa.inherited.Committee) CommitteeDates(org.eclipse.persistence.testing.models.jpa.inherited.CommitteeDates) EntityManager(jakarta.persistence.EntityManager) Official(org.eclipse.persistence.testing.models.jpa.inherited.Official) Accredidation(org.eclipse.persistence.testing.models.jpa.inherited.Accredidation) Witness(org.eclipse.persistence.testing.models.jpa.inherited.Witness) Record(org.eclipse.persistence.testing.models.jpa.inherited.Record) 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) Location(org.eclipse.persistence.testing.models.jpa.inherited.Location)

Aggregations

EntityManager (jakarta.persistence.EntityManager)4 Official (org.eclipse.persistence.testing.models.jpa.inherited.Official)4 BeerConsumer (org.eclipse.persistence.testing.models.jpa.inherited.BeerConsumer)2 ExpertBeerConsumer (org.eclipse.persistence.testing.models.jpa.inherited.ExpertBeerConsumer)2 NoviceBeerConsumer (org.eclipse.persistence.testing.models.jpa.inherited.NoviceBeerConsumer)2 Query (jakarta.persistence.Query)1 QueryException (org.eclipse.persistence.exceptions.QueryException)1 Accredidation (org.eclipse.persistence.testing.models.jpa.inherited.Accredidation)1 Birthday (org.eclipse.persistence.testing.models.jpa.inherited.Birthday)1 Committee (org.eclipse.persistence.testing.models.jpa.inherited.Committee)1 CommitteeDates (org.eclipse.persistence.testing.models.jpa.inherited.CommitteeDates)1 Location (org.eclipse.persistence.testing.models.jpa.inherited.Location)1 OfficialEntry (org.eclipse.persistence.testing.models.jpa.inherited.OfficialEntry)1 Record (org.eclipse.persistence.testing.models.jpa.inherited.Record)1 RedStripe (org.eclipse.persistence.testing.models.jpa.inherited.RedStripe)1 ServiceTime (org.eclipse.persistence.testing.models.jpa.inherited.ServiceTime)1 Venue (org.eclipse.persistence.testing.models.jpa.inherited.Venue)1 Witness (org.eclipse.persistence.testing.models.jpa.inherited.Witness)1