@Test public void getItemListByProduct_shouldFindListWithExistingItemByProduct() { List<Item> items = persistence.getItemListByProduct(existingProduct.getProductId()); assertThat(items.size(), is(1)); assertHaveSamePersistentFields(existingItem, items.get(0), "supplier"); }
@Override public List<Item> getItemListByProduct(@Nonnull final String productId) { Query query = getEntityManager().createQuery("select i from Item i where i.productId = :productId"); query.setParameter("productId", productId); @SuppressWarnings("unchecked") List<Item> items = (List<Item>) query.getResultList(); closeEntityManager(); for (Item item : items) { Product product = productBasePersistence.getProduct(item.getProductId()); item.setProduct(product); } logger.info("Read [{}] item(s) with product id[{}]", items.size(), productId); return items; }
ItemBasePersistence extends AbstractBasePersistence<Item, String> implements ItemMapper { @Override public List<Item> getItemListByProduct(@Nonnull final String productId) { Query query = getEntityManager().createQuery("select i from Item i where i.productId = :productId"); query.setParameter("productId", productId); @SuppressWarnings("unchecked") List<Item> items = (List<Item>) query.getResultList(); closeEntityManager(); for (Item item : items) { Product product = productBasePersistence.getProduct(item.getProductId()); item.setProduct(product); } logger.info("Read [{}] item(s) with product id[{}]", items.size(), productId); return items; } }
ItemBasePersistence extends AbstractBasePersistence<Item, String> implements ItemMapper { @Override public List<Item> getItemListByProduct(@Nonnull final String productId) { Query query = getEntityManager().createQuery("select i from Item i where i.productId = :productId"); query.setParameter("productId", productId); @SuppressWarnings("unchecked") List<Item> items = (List<Item>) query.getResultList(); closeEntityManager(); for (Item item : items) { Product product = productBasePersistence.getProduct(item.getProductId()); item.setProduct(product); } logger.info("Read [{}] item(s) with product id[{}]", items.size(), productId); return items; }  }
ItemBasePersistence extends AbstractBasePersistence<Item, String> implements ItemMapper { @Override public List<Item> getItemListByProduct(@Nonnull final String productId) { Query query = getEntityManager().createQuery("select i from Item i where i.productId = :productId"); query.setParameter("productId", productId); @SuppressWarnings("unchecked") List<Item> items = (List<Item>) query.getResultList(); closeEntityManager(); for (Item item : items) { Product product = productBasePersistence.getProduct(item.getProductId()); item.setProduct(product); } logger.info("Read [{}] item(s) with product id[{}]", items.size(), productId); return items; }  @Override void updateInventoryQuantity(@Nonnull final Map<String, Object> param); @Override int getInventoryQuantity(@Nonnull final String itemId); @Override List<Item> getItemListByProduct(@Nonnull final String productId); @Override Item getItem(@Nonnull final String itemId); }
ItemBasePersistence extends AbstractBasePersistence<Item, String> implements ItemMapper { @Override public List<Item> getItemListByProduct(@Nonnull final String productId) { Query query = getEntityManager().createQuery("select i from Item i where i.productId = :productId"); query.setParameter("productId", productId); @SuppressWarnings("unchecked") List<Item> items = (List<Item>) query.getResultList(); closeEntityManager(); for (Item item : items) { Product product = productBasePersistence.getProduct(item.getProductId()); item.setProduct(product); } logger.info("Read [{}] item(s) with product id[{}]", items.size(), productId); return items; }  @Override void updateInventoryQuantity(@Nonnull final Map<String, Object> param); @Override int getInventoryQuantity(@Nonnull final String itemId); @Override List<Item> getItemListByProduct(@Nonnull final String productId); @Override Item getItem(@Nonnull final String itemId);  }