Search in sources :

Example 6 with Item

use of org.jpwh.model.advanced.Item in project microservices by pwillhan.

the class TransformingColumns method storeItemAndBids.

public Long storeItemAndBids() throws Exception {
    UserTransaction tx = TM.getUserTransaction();
    tx.begin();
    EntityManager em = JPA.createEntityManager();
    Item item = new Item();
    item.setName("Some item");
    item.setMetricWeight(2);
    item.setDescription("This is some description.");
    em.persist(item);
    for (int i = 1; i <= 3; i++) {
        Bid bid = new Bid();
        bid.setAmount(new BigDecimal(10 + i));
        bid.setItem(item);
        em.persist(bid);
    }
    tx.commit();
    em.close();
    return item.getId();
}
Also used : UserTransaction(javax.transaction.UserTransaction) Item(org.jpwh.model.advanced.Item) EntityManager(javax.persistence.EntityManager) Bid(org.jpwh.model.advanced.Bid) BigDecimal(java.math.BigDecimal)

Example 7 with Item

use of org.jpwh.model.advanced.Item in project microservices by pwillhan.

the class AccessType method storeLoadAccessType.

@Test
public void storeLoadAccessType() throws Exception {
    UserTransaction tx = TM.getUserTransaction();
    try {
        tx.begin();
        EntityManager em = JPA.createEntityManager();
        Item someItem = new Item();
        someItem.setName("Some item");
        someItem.setDescription("This is some description.");
        em.persist(someItem);
        tx.commit();
        em.close();
        Long ITEM_ID = someItem.getId();
        tx.begin();
        em = JPA.createEntityManager();
        Item item = em.find(Item.class, ITEM_ID);
        assertEquals(item.getName(), "AUCTION: Some item");
        tx.commit();
        em.close();
    } finally {
        TM.rollback();
    }
}
Also used : UserTransaction(javax.transaction.UserTransaction) Item(org.jpwh.model.advanced.Item) EntityManager(javax.persistence.EntityManager) JPATest(org.jpwh.env.JPATest) Test(org.testng.annotations.Test)

Example 8 with Item

use of org.jpwh.model.advanced.Item in project microservices by pwillhan.

the class DerivedProperties method storeItemAndBids.

public Long storeItemAndBids() throws Exception {
    UserTransaction tx = TM.getUserTransaction();
    tx.begin();
    EntityManager em = JPA.createEntityManager();
    Item item = new Item();
    item.setName("Some item");
    item.setDescription("This is some description.");
    em.persist(item);
    for (int i = 1; i <= 3; i++) {
        Bid bid = new Bid();
        bid.setAmount(new BigDecimal(10 + i));
        bid.setItem(item);
        em.persist(bid);
    }
    tx.commit();
    em.close();
    return item.getId();
}
Also used : UserTransaction(javax.transaction.UserTransaction) Item(org.jpwh.model.advanced.Item) EntityManager(javax.persistence.EntityManager) Bid(org.jpwh.model.advanced.Bid) BigDecimal(java.math.BigDecimal)

Example 9 with Item

use of org.jpwh.model.advanced.Item in project microservices by pwillhan.

the class DerivedProperties method storeLoadFormulaSubselect.

@Test
public void storeLoadFormulaSubselect() throws Exception {
    long ITEM_ID = storeItemAndBids();
    UserTransaction tx = TM.getUserTransaction();
    try {
        tx.begin();
        EntityManager em = JPA.createEntityManager();
        Item item = em.find(Item.class, ITEM_ID);
        assertEquals(item.getAverageBidAmount().compareTo(new BigDecimal("12")), 0);
        tx.commit();
        em.close();
    } finally {
        TM.rollback();
    }
}
Also used : UserTransaction(javax.transaction.UserTransaction) Item(org.jpwh.model.advanced.Item) EntityManager(javax.persistence.EntityManager) BigDecimal(java.math.BigDecimal) JPATest(org.jpwh.env.JPATest) Test(org.testng.annotations.Test)

Example 10 with Item

use of org.jpwh.model.advanced.Item in project microservices by pwillhan.

the class GeneratedProperties method storeItemAndBids.

public Long storeItemAndBids() throws Exception {
    UserTransaction tx = TM.getUserTransaction();
    tx.begin();
    EntityManager em = JPA.createEntityManager();
    Item item = new Item();
    item.setName("Some item");
    item.setDescription("This is some description.");
    em.persist(item);
    for (int i = 1; i <= 3; i++) {
        Bid bid = new Bid();
        bid.setAmount(new BigDecimal(10 + i));
        bid.setItem(item);
        em.persist(bid);
    }
    tx.commit();
    em.close();
    return item.getId();
}
Also used : UserTransaction(javax.transaction.UserTransaction) Item(org.jpwh.model.advanced.Item) EntityManager(javax.persistence.EntityManager) Bid(org.jpwh.model.advanced.Bid) BigDecimal(java.math.BigDecimal)

Aggregations

EntityManager (javax.persistence.EntityManager)16 UserTransaction (javax.transaction.UserTransaction)16 Item (org.jpwh.model.advanced.Item)16 JPATest (org.jpwh.env.JPATest)12 Test (org.testng.annotations.Test)12 BigDecimal (java.math.BigDecimal)6 Bid (org.jpwh.model.advanced.Bid)4 Date (java.util.Date)2 Random (java.util.Random)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStream (java.io.InputStream)1 Blob (java.sql.Blob)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 Calendar (java.util.Calendar)1 GregorianCalendar (java.util.GregorianCalendar)1 List (java.util.List)1 Query (javax.persistence.Query)1