Add max limit on OBDao.getOneInstance method for performance reasons.
authorGorka Ion Damián <gorkaion.damian@openbravo.com>
Thu, 03 Mar 2011 13:18:26 +0100
changeset 10991 8fe8a3602973
parent 10990 10c7295f015a
child 10992 1cd103b3bf2a
Add max limit on OBDao.getOneInstance method for performance reasons.
src/org/openbravo/dal/service/OBDao.java
--- a/src/org/openbravo/dal/service/OBDao.java	Thu Mar 03 13:15:42 2011 +0100
+++ b/src/org/openbravo/dal/service/OBDao.java	Thu Mar 03 13:18:26 2011 +0100
@@ -115,11 +115,13 @@
    */
   public static <T extends BaseOBObject> T getOneInstance(Class<T> clazz, boolean setClientFilter,
       boolean setOrganizationFilter, Constraint... constraints) {
-    List<T> criteria = getAllInstances(clazz, setClientFilter, setOrganizationFilter, constraints);
-    if (criteria.isEmpty()) {
+    OBCriteria<T> criteria = getFilteredCriteria(clazz, setClientFilter, setOrganizationFilter,
+        constraints);
+    criteria.setMaxResults(1);
+    if (criteria.list().isEmpty()) {
       return null;
     }
-    return criteria.get(0);
+    return criteria.list().get(0);
   }
 
   /**