use of org.jpwh.model.customsql.Image in project microservices by pwillhan.
the class CustomSQL method create.
public CustomSQLTestData create() throws Exception {
UserTransaction tx = TM.getUserTransaction();
tx.begin();
EntityManager em = JPA.createEntityManager();
CustomSQLTestData testData = new CustomSQLTestData();
testData.categories = new TestData(new Long[1]);
testData.items = new TestData(new Long[2]);
testData.bids = new TestData(new Long[3]);
testData.users = new TestData(new Long[2]);
User johndoe = new User("johndoe");
em.persist(johndoe);
testData.users.identifiers[0] = johndoe.getId();
User janeroe = new User("janeroe");
em.persist(janeroe);
testData.users.identifiers[1] = janeroe.getId();
Category category = new Category();
category.setName("Foo");
em.persist(category);
testData.categories.identifiers[0] = category.getId();
Item item = new Item();
item.setName("Some item");
item.setCategory(category);
item.setSeller(johndoe);
item.setAuctionEnd(CalendarUtil.TOMORROW.getTime());
item.getImages().add(new Image("foo.jpg", 640, 480));
item.getImages().add(new Image("bar.jpg", 800, 600));
item.getImages().add(new Image("baz.jpg", 640, 480));
em.persist(item);
testData.items.identifiers[0] = item.getId();
for (int i = 1; i <= 3; i++) {
Bid bid = new Bid();
bid.setAmount(new BigDecimal(10 + i));
bid.setItem(item);
bid.setBidder(janeroe);
em.persist(bid);
testData.bids.identifiers[i - 1] = bid.getId();
}
Item otherItem = new Item(category, "Inactive item", CalendarUtil.TOMORROW.getTime(), johndoe);
otherItem.setActive(false);
em.persist(otherItem);
tx.commit();
em.close();
return testData;
}
Aggregations