Search in sources :

Example 1 with Category

use of org.jpwh.model.fetching.proxy.Category in project microservices by pwillhan.

the class LazyProxyCollections method storeTestData.

public FetchTestData storeTestData() throws Exception {
    UserTransaction tx = TM.getUserTransaction();
    tx.begin();
    EntityManager em = JPA.createEntityManager();
    Long[] categoryIds = new Long[3];
    Long[] itemIds = new Long[3];
    Long[] userIds = new Long[3];
    User johndoe = new User("johndoe");
    em.persist(johndoe);
    userIds[0] = johndoe.getId();
    User janeroe = new User("janeroe");
    em.persist(janeroe);
    userIds[1] = janeroe.getId();
    User robertdoe = new User("robertdoe");
    em.persist(robertdoe);
    userIds[2] = robertdoe.getId();
    Category category = new Category("Category One");
    em.persist(category);
    categoryIds[0] = category.getId();
    Item item = new Item("Item One", CalendarUtil.TOMORROW.getTime(), johndoe);
    em.persist(item);
    itemIds[0] = item.getId();
    category.getItems().add(item);
    item.getCategories().add(category);
    for (int i = 1; i <= 3; i++) {
        Bid bid = new Bid(item, robertdoe, new BigDecimal(9 + i));
        item.getBids().add(bid);
        em.persist(bid);
    }
    category = new Category("Category Two");
    em.persist(category);
    categoryIds[1] = category.getId();
    item = new Item("Item Two", CalendarUtil.TOMORROW.getTime(), johndoe);
    em.persist(item);
    itemIds[1] = item.getId();
    category.getItems().add(item);
    item.getCategories().add(category);
    for (int i = 1; i <= 1; i++) {
        Bid bid = new Bid(item, janeroe, new BigDecimal(2 + i));
        item.getBids().add(bid);
        em.persist(bid);
    }
    item = new Item("Item Three", CalendarUtil.AFTER_TOMORROW.getTime(), janeroe);
    em.persist(item);
    itemIds[2] = item.getId();
    category.getItems().add(item);
    item.getCategories().add(category);
    category = new Category("Category Three");
    em.persist(category);
    categoryIds[2] = category.getId();
    tx.commit();
    em.close();
    FetchTestData testData = new FetchTestData();
    testData.items = new TestData(itemIds);
    testData.users = new TestData(userIds);
    return testData;
}
Also used : UserTransaction(javax.transaction.UserTransaction) Item(org.jpwh.model.fetching.proxy.Item) EntityManager(javax.persistence.EntityManager) User(org.jpwh.model.fetching.proxy.User) Category(org.jpwh.model.fetching.proxy.Category) TestData(org.jpwh.shared.util.TestData) Bid(org.jpwh.model.fetching.proxy.Bid) BigDecimal(java.math.BigDecimal)

Aggregations

BigDecimal (java.math.BigDecimal)1 EntityManager (javax.persistence.EntityManager)1 UserTransaction (javax.transaction.UserTransaction)1 Bid (org.jpwh.model.fetching.proxy.Bid)1 Category (org.jpwh.model.fetching.proxy.Category)1 Item (org.jpwh.model.fetching.proxy.Item)1 User (org.jpwh.model.fetching.proxy.User)1 TestData (org.jpwh.shared.util.TestData)1