details:   https://code.openbravo.com/erp/devel/pi/rev/b05271bc5119
changeset: 29877:b05271bc5119
user:      Stefan Hühner <stefan.huehner <at> openbravo.com>
date:      Fri Aug 12 17:02:22 2016 +0200
summary:   Fixed 33703. Avoid double query by using .uniqueResult instead of 
twice .list()

details:   https://code.openbravo.com/erp/devel/pi/rev/4289cc0c5136
changeset: 29878:4289cc0c5136
user:      Stefan Hühner <stefan.huehner <at> openbravo.com>
date:      Fri Aug 12 17:08:13 2016 +0200
summary:   Fixed 33704. Remove double query by saving .list() result

instead of calling .count() and then .list() which does 2 selects for the same.

details:   https://code.openbravo.com/erp/devel/pi/rev/805737524388
changeset: 29879:805737524388
user:      Stefan Hühner <stefan.huehner <at> openbravo.com>
date:      Fri Aug 12 17:27:25 2016 +0200
summary:   Fixed 33705. Avoid double query with .count() + .list(). Add limit 1 
to query

Query did .count() + then retrieve 1 record after adding extra order by.

This change removes the count as it only adds extra overhead and directly
does the real .list() query.
As the code only uses single row of result add extra limit 1 to reduce
number of result rows loaded into memory if many match the filter.
Simply code to use .uniqueResult() instead of .list().get(0)

details:   https://code.openbravo.com/erp/devel/pi/rev/741a356c2150
changeset: 29880:741a356c2150
user:      Stefan Hühner <stefan.huehner <at> openbravo.com>
date:      Fri Aug 12 17:43:20 2016 +0200
summary:   Fixed 33706. Replace triple .list() call by single query.

Avoid 2 extra queries by saving .list() result instead of calling it 3 times.

Simplify query to OBDal.get (by primary key) as that is only filter which was
used in the OBCriteria.

details:   https://code.openbravo.com/erp/devel/pi/rev/e905f809d409
changeset: 29881:e905f809d409
user:      Stefan Hühner <stefan.huehner <at> openbravo.com>
date:      Fri Aug 12 17:54:08 2016 +0200
summary:   Fixed 33707. Avoid triple query use single .uniqueResult instead.

Filter in that OBQuery is on 'value' field having uniqueConstraint. So not
checking for >1 rows in result is necessary as it can never happen, so remove
that check completely.

Collapse the other 2 .list() calls into a single .uniqueResult avoiding
yet another query.

diffstat:

 
modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/DataSourceServiceProvider.java
        |   5 ++-
 
modules/org.openbravo.userinterface.selector/src/org/openbravo/userinterface/selector/SelectorDataSourceFilter.java
 |  15 ++++-----
 src/org/openbravo/erpCommon/info/PriceListVersionFilterExpression.java         
                                     |   8 ++---
 src/org/openbravo/erpCommon/utility/OBMessageUtils.java                        
                                     |  10 ++----
 4 files changed, 16 insertions(+), 22 deletions(-)

diffs (97 lines):

diff -r 2378e48d2b8d -r e905f809d409 
modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/DataSourceServiceProvider.java
--- 
a/modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/DataSourceServiceProvider.java
      Tue Aug 23 12:25:06 2016 +0000
+++ 
b/modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/DataSourceServiceProvider.java
      Fri Aug 12 17:54:08 2016 +0200
@@ -119,8 +119,9 @@
     DataSource dataSource = null;
     final OBCriteria<Table> qTable = 
OBDal.getInstance().createCriteria(Table.class);
     qTable.add(Restrictions.eq(Table.PROPERTY_NAME, tableName));
-    if (!qTable.list().isEmpty()) {
-      Table table = qTable.list().get(0);
+    // ad_table.name is unique
+    Table table = (Table) qTable.uniqueResult();
+    if (table != null) {
       if 
(ApplicationConstants.DATASOURCEBASEDTABLE.equals(table.getDataOriginType())) {
         // If the table is based on a manual datasource, return that 
particular datasource
         dataSource = table.getObserdsDatasource();
diff -r 2378e48d2b8d -r e905f809d409 
modules/org.openbravo.userinterface.selector/src/org/openbravo/userinterface/selector/SelectorDataSourceFilter.java
--- 
a/modules/org.openbravo.userinterface.selector/src/org/openbravo/userinterface/selector/SelectorDataSourceFilter.java
       Tue Aug 23 12:25:06 2016 +0000
+++ 
b/modules/org.openbravo.userinterface.selector/src/org/openbravo/userinterface/selector/SelectorDataSourceFilter.java
       Fri Aug 12 17:54:08 2016 +0200
@@ -97,14 +97,12 @@
 
       String processId = 
parameters.get(SelectorConstants.DS_REQUEST_PROCESS_DEFINITION_ID);
       if (!StringUtils.isEmpty(processId)) {
-        OBCriteria<Parameter> qParam = 
OBDal.getInstance().createCriteria(Parameter.class);
-        qParam.add(Restrictions.eq(Parameter.PROPERTY_ID,
-            parameters.get(SelectorConstants.DS_REQUEST_SELECTOR_FIELD_ID)));
-        Parameter param = qParam.list().get(0);
-        Validation validation = qParam.list().get(0).getValidation();
+        Parameter param = OBDal.getInstance().get(Parameter.class,
+            parameters.get(SelectorConstants.DS_REQUEST_SELECTOR_FIELD_ID));
+        Validation validation = param.getValidation();
         if (validation != null) {
           if (validation.getType().equals("HQL_JS")) {
-            String validationCode = 
qParam.list().get(0).getValidation().getValidationCode();
+            String validationCode = param.getValidation().getValidationCode();
             String validationHQL = applyFilterExpression(validationCode, sel, 
parameters, request);
 
             if (!StringUtils.isEmpty(validationHQL)) {
@@ -311,7 +309,8 @@
       OBCriteria<SelectorField> sfc, HttpServletRequest request, String 
hqlFilterClause) {
 
     String currentWhere = "";
-    if (sfc.count() == 0) {
+    List<SelectorField> selectorFields = sfc.list();
+    if (selectorFields.size() == 0) {
       return;
     }
 
@@ -336,7 +335,7 @@
 
     Entity entity = 
ModelProvider.getInstance().getEntityByTableId(sel.getTable().getId());
 
-    for (SelectorField sf : sfc.list()) {
+    for (SelectorField sf : selectorFields) {
       // skip selector fields which do not have a property defined (needed for 
selector definitions
       // using a custom query
       if (sf.getProperty() == null) {
diff -r 2378e48d2b8d -r e905f809d409 
src/org/openbravo/erpCommon/info/PriceListVersionFilterExpression.java
--- a/src/org/openbravo/erpCommon/info/PriceListVersionFilterExpression.java    
Tue Aug 23 12:25:06 2016 +0000
+++ b/src/org/openbravo/erpCommon/info/PriceListVersionFilterExpression.java    
Fri Aug 12 17:54:08 2016 +0200
@@ -108,11 +108,9 @@
         PriceListVersion.class);
     plVersionCrit.add(Restrictions.eq(PriceListVersion.PROPERTY_PRICELIST, 
priceList));
     plVersionCrit.add(Restrictions.le(PriceListVersion.PROPERTY_VALIDFROMDATE, 
date));
-    if (plVersionCrit.count() > 0) {
-      plVersionCrit.addOrderBy(PriceListVersion.PROPERTY_VALIDFROMDATE, false);
-      return plVersionCrit.list().get(0);
-    }
-    return null;
+    plVersionCrit.addOrderBy(PriceListVersion.PROPERTY_VALIDFROMDATE, false);
+    plVersionCrit.setMaxResults(1);
+    return (PriceListVersion) plVersionCrit.uniqueResult();
   }
 
   private boolean isSalesTransaction() {
diff -r 2378e48d2b8d -r e905f809d409 
src/org/openbravo/erpCommon/utility/OBMessageUtils.java
--- a/src/org/openbravo/erpCommon/utility/OBMessageUtils.java   Tue Aug 23 
12:25:06 2016 +0000
+++ b/src/org/openbravo/erpCommon/utility/OBMessageUtils.java   Fri Aug 12 
17:54:08 2016 +0200
@@ -514,16 +514,12 @@
       final OBQuery<Message> messages = 
OBDal.getInstance().createQuery(Message.class,
           Message.PROPERTY_SEARCHKEY + "=:key");
       messages.setNamedParameter("key", key);
-      if (messages.list().isEmpty()) {
+
+      final Message message = messages.uniqueResult();
+      if (message == null) {
         return null;
       }
 
-      if (messages.list().size() > 1) {
-        log4j.warn("More than one message found using key " + key);
-      }
-
-      // pick the first one
-      final Message message = messages.list().get(0);
       String label = message.getMessageText();
       final String languageId = OBContext.getOBContext().getLanguage().getId();
       for (MessageTrl messageTrl : message.getADMessageTrlList()) {

------------------------------------------------------------------------------
_______________________________________________
Openbravo-commits mailing list
Openbravo-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to