public void testPagingInCollection() throws Exception { // create objects in database Formula formula = Formula.findByName("HTML TEST"); Ingredient ingredient = Ingredient.findByName("LECHE"); for (int x = 0; x <= 12; x++) { FormulaIngredient fi = new FormulaIngredient(); fi.setFormula(formula); fi.setIngredient(ingredient); XPersistence.getManager().persist(fi); } XPersistence.commit(); // execute("Mode.detailAndFirst"); assertValue("name", "HTML TEST"); assertCollectionRowCount("ingredients", 10); checkRowCollection("ingredients", 0); execute("List.goNextPage", "collection=ingredients"); execute("List.goPreviousPage", "collection=ingredients"); assertRowCollectionChecked("ingredients", 0); // remove objects from database String sentencia = " DELETE FROM FormulaIngredient WHERE ingredient.oid = :ingredient "; Query query = XPersistence.getManager().createQuery(sentencia); query.setParameter("ingredient", ingredient.getOid()); query.executeUpdate(); XPersistence.commit(); }
public Stock getStockByItem(int itemid) { // 用 商品編號 查出 該商品所在的某一貨架 Query query = XPersistence.getManager() .createQuery( "FROM Stock o WHERE o.item.oid = :itemid order by o.volume desc"); // JPQL query query.setParameter("itemid", itemid); List<Stock> beans = query.getResultList(); logger.debug("OrderPlaceDDAO.getStockByItem beans: " + beans); return beans.get(0); }
public Collection<Stock> getStocksByPlaceId(int placeid) { // 用上架單編號(單頭)查出明細檔 Query query = XPersistence.getManager() .createQuery( "FROM Stock o WHERE o.item.oid IN (SELECT p.item.oid FROM OrderPlaceD p WHERE p.orderPlace.oid = :placeid ORDER BY p.oid DESC) )"); // JPQL query query.setParameter("placeid", placeid); // select * FROM Stock o WHERE o.itemid IN (SELECT p.itemid FROM OrderPlaceD p WHERE // p.orderPlace_oid = '1' ORDER BY p.oid DESC) Collection stocks = query.getResultList(); logger.debug("OrderPlaceDDAO.getStocksByPlaceId stocks: " + stocks); return stocks; }
public static Product2 findByNumber(long number) throws NoResultException { Query query = XPersistence.getManager().createQuery("from Product2 as o where o.number = :number"); query.setParameter("number", new Long(number)); return (Product2) query.getSingleResult(); }