Пример #1
0
  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);
  }
Пример #2
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;
  }
Пример #3
0
  public void testConverterWithMetaSets() throws Exception {
    // Creating new
    execute("CRUD.new");
    setValue("invoice.year", "2002");
    setValue("invoice.number", "1");
    setValue("type.number", "1");
    setValue("number", "66");
    setValue("description", "JUNIT");
    setValue("distance", usesAnnotatedPOJO() ? "1" : "2"); // National, in database 'N'
    execute("CRUD.save");
    assertNoErrors();
    assertValue("invoice.year", "");
    assertValue("invoice.number", "");
    assertValue("type.number", "");
    assertValue("number", "");
    assertValue("description", "");
    assertValue("distance", usesAnnotatedPOJO() ? "" : "0");
    // Search just created
    setValue("invoice.year", "2002");
    setValue("invoice.number", "1");
    setValue("type.number", "1");
    setValue("number", "66");
    execute("CRUD.refresh");
    assertNoErrors();
    assertValue("invoice.year", "2002");
    assertValue("invoice.number", "1");
    assertValue("type.number", "1");
    assertValue("number", "66");
    assertValue("description", "JUNIT");
    assertValue("distance", usesAnnotatedPOJO() ? "1" : "2");
    assertNoErrors();

    // Verifying database value
    Query query =
        XPersistence.getManager()
            .createNativeQuery(
                "select d.distance from XAVATEST.Delivery as d where "
                    + "invoice_year=2002 and invoice_number=1 and type=1 and number=66");
    String distanceDB = (String) query.getSingleResult();
    assertEquals("distance in database incorrect", "N", distanceDB);

    // Delete
    execute("CRUD.delete");
    assertNoErrors();
    assertMessage("Delivery deleted successfully");
  }
Пример #4
0
  public void testDeleteSelectedOnesAndOrderBy() throws Exception {
    // Creating new
    execute("CRUD.new");
    setValue("invoice.year", "2009");
    setValue("invoice.number", "1");
    setValue("type.number", "1");
    setValue("number", "1");
    setValue("description", "JUNIT");
    execute("CRUD.save");
    assertNoErrors();

    // To list mode and order
    execute("Mode.list");
    assertActions(listActions);
    execute("List.orderBy", "property=invoice.year"); // ascending
    execute("List.orderBy", "property=invoice.year"); // descending
    assertNoErrors();

    // Delete
    assertValueInList(0, "invoice.year", "2009");
    assertValueInList(0, "invoice.number", "1");
    assertValueInList(0, "type.number", "1");
    assertValueInList(0, "number", "1");

    checkRow(0);

    execute("CRUD.deleteSelected");
    assertNoErrors();
    assertRowUnchecked(0);

    // Verifying that it is deleted
    Query query =
        XPersistence.getManager()
            .createQuery(
                "from Delivery d where "
                    + "d.invoice.year=2009 and d.invoice.number=1 and d.type.number=1 and d.number=1");
    if (!query.getResultList().isEmpty()) {
      fail("Delivery would be deleted and it is not the case");
    }
  }