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();
}
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();
}
}
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();
}
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();
}
}
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();
}
Aggregations