Fixed 9637: Optimize product selector direct search (via enter key) with many products
authorStefan Hühner <stefan.huehner@openbravo.com>
Thu, 25 Jun 2009 15:05:11 +0200
changeset 4063 858c73b68f2c
parent 4062 bd1b69317dd1
child 4064 79d24670c339
Fixed 9637: Optimize product selector direct search (via enter key) with many products
- Limit resultset to <= 2 records as only count 0,1,2 and perhaps data of a single product is needed
src/org/openbravo/erpCommon/info/Product.java
--- a/src/org/openbravo/erpCommon/info/Product.java	Thu Jun 25 14:13:44 2009 +0200
+++ b/src/org/openbravo/erpCommon/info/Product.java	Thu Jun 25 15:05:11 2009 +0200
@@ -146,9 +146,22 @@
 
       String strPriceListVersion = getPriceListVersion(vars, strPriceList, strDate);
       vars.setSessionValue("Product.priceListVersion", strPriceListVersion);
-      ProductData[] data = ProductData.select(this, strWarehouse, "1", strKeyValue + "%", "",
+
+      // two cases are interesting in the result:
+      // - exactly one row (and row content is needed)
+      // - zero or more than one row (row content not needed)
+      // so limit <= 2 records to get both info from result without needing to fetch all rows
+      String rownum = "0", oraLimit1 = null, oraLimit2 = null, pgLimit = null;
+      if (this.myPool.getRDBMS().equalsIgnoreCase("ORACLE")) {
+        oraLimit1 = "2";
+        oraLimit2 = "1 AND 2";
+        rownum = "ROWNUM";
+      } else {
+        pgLimit = "2";
+      }
+      ProductData[] data = ProductData.select(this, strWarehouse, rownum, strKeyValue + "%", "",
           Utility.getContext(this, vars, "#User_Client", "Product"), Utility.getContext(this, vars,
-              "#User_Org", "Product"), strPriceListVersion, "1", "", "", "");
+              "#User_Org", "Product"), strPriceListVersion, "1", oraLimit1, oraLimit2, pgLimit);
       if (data != null && data.length == 1)
         printPageKey(response, vars, data, strWarehouse, strPriceListVersion);
       else