details:   https://code.openbravo.com/erp/devel/pi/rev/938e3500425d
changeset: 29954:938e3500425d
user:      Naroa Iriarte <naroa.iriarte <at> openbravo.com>
date:      Mon Aug 29 15:25:51 2016 +0200
summary:   Fixed issue 33601: Preferences.getPreferenceValue's performance 
improved

There are two methods called Preferences.getPrferenceValue. Before, one of them 
was getting the Client, org... objects and passing them as arguments to the 
other function. The other function was getting the Id from those objects to 
execute all the logic. This was not a good code, because one function was 
making queries to the database to get the objects just to pass them as 
arguments of the other function and in that funtion, those objects were only 
used to get the Id... so it has been modifyied. Now the function which before 
was called in the other is the one which calls the other function. Thanks to 
this change it is not needed to query the database to get the client, 
organization, user, role and window objects.

diffstat:

 src/org/openbravo/erpCommon/businessUtility/Preferences.java |  33 ++++-------
 1 files changed, 12 insertions(+), 21 deletions(-)

diffs (60 lines):

diff -r 55c319563446 -r 938e3500425d 
src/org/openbravo/erpCommon/businessUtility/Preferences.java
--- a/src/org/openbravo/erpCommon/businessUtility/Preferences.java      Wed Aug 
31 10:27:37 2016 +0200
+++ b/src/org/openbravo/erpCommon/businessUtility/Preferences.java      Mon Aug 
29 15:25:51 2016 +0200
@@ -182,10 +182,21 @@
       String userId = user == null ? null : user.getId();
       String roleId = role == null ? null : role.getId();
       String windowId = window == null ? null : window.getId();
+      return getPreferenceValue(property, isListProperty, clientId, orgId, 
userId, roleId, windowId);
+    } finally {
+      OBContext.restorePreviousMode();
+    }
+  }
 
+  /**
+   * @see Preferences#getPreferenceValue(String, boolean, Client, 
Organization, User, Role, Window)
+   */
+  public static String getPreferenceValue(String property, boolean 
isListProperty, String clientId,
+      String orgId, String userId, String roleId, String windowId) throws 
PropertyException {
+    OBContext.setAdminMode();
+    try {
       List<Preference> prefs = getPreferences(property, isListProperty, 
clientId, orgId, userId,
           roleId, windowId, false, true);
-
       Preference selectedPreference = null;
       List<String> parentTree = 
OBContext.getOBContext().getOrganizationStructureProvider(clientId)
           .getParentList(orgId, true);
@@ -210,7 +221,6 @@
           break;
         }
       }
-
       if (conflict) {
         throw new PropertyConflictException();
       }
@@ -224,25 +234,6 @@
   }
 
   /**
-   * @see Preferences#getPreferenceValue(String, boolean, Client, 
Organization, User, Role, Window)
-   */
-  public static String getPreferenceValue(String property, boolean 
isListProperty,
-      String strClient, String strOrg, String strUser, String strRole, String 
strWindow)
-      throws PropertyException {
-    try {
-      OBContext.setAdminMode();
-      Client client = OBDal.getInstance().get(Client.class, strClient == null 
? "" : strClient);
-      Organization org = OBDal.getInstance().get(Organization.class, strOrg == 
null ? "" : strOrg);
-      User user = OBDal.getInstance().get(User.class, strUser == null ? "" : 
strUser);
-      Role role = OBDal.getInstance().get(Role.class, strRole == null ? "" : 
strRole);
-      Window window = OBDal.getInstance().get(Window.class, strWindow == null 
? "" : strWindow);
-      return getPreferenceValue(property, isListProperty, client, org, user, 
role, window);
-    } finally {
-      OBContext.restorePreviousMode();
-    }
-  }
-
-  /**
    * Utility method to determine if exists a preference with the same settings 
passed as parameters
    * 
    * @param property

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

Reply via email to