use of org.jpwh.model.customsql.Category in project microservices by pwillhan.
the class CustomSQL method readRestrictedCollection.
// The "ACTIVE = 'true'" SQL restriction doesn't work on Oracle, they
// still don't have a boolean datatype...
@Test(groups = { "H2", "POSTGRESQL" })
public void readRestrictedCollection() throws Exception {
CustomSQLTestData testData = create();
Long CATEGORY_ID = testData.categories.getFirstId();
Long ITEM_ID = testData.items.getFirstId();
UserTransaction tx = TM.getUserTransaction();
try {
tx.begin();
EntityManager em = JPA.createEntityManager();
{
Category category = em.find(Category.class, CATEGORY_ID);
assertEquals(loadEventListener.getLoadCount(Category.class), 1);
Set<Item> items = category.getItems();
assertEquals(items.size(), 1);
assertEquals(items.iterator().next().getId(), ITEM_ID);
}
em.clear();
loadEventListener.reset();
tx.commit();
em.close();
} finally {
TM.rollback();
}
}
use of org.jpwh.model.customsql.Category 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