Related to issue 30308: created new refresh method in OBDal
authorCarlos Aristu <carlos.aristu@openbravo.com>
Fri, 03 Jul 2015 19:31:11 +0200
changeset 27067 2268a549839c
parent 27066 f6dcfa9328cf
child 27068 ec134f647522
Related to issue 30308: created new refresh method in OBDal

Place the solution in a new method in OBDal, to allow the usage of this approach in similar cases
modules/org.openbravo.service.json/src/org/openbravo/service/json/DefaultJsonDataService.java
src/org/openbravo/dal/service/OBDal.java
--- a/modules/org.openbravo.service.json/src/org/openbravo/service/json/DefaultJsonDataService.java	Wed Jun 24 16:56:47 2015 +0200
+++ b/modules/org.openbravo.service.json/src/org/openbravo/service/json/DefaultJsonDataService.java	Fri Jul 03 19:31:11 2015 +0200
@@ -704,13 +704,12 @@
         // refresh the objects from the db as they can have changed
         // put the refreshed objects into a new array as we are going to retrieve them using
         // OBDal.getInstance().get as performs better than OBDal.getInstance().getSession().refresh
+        // We use OBDal.getInstance().get inside OBDal.getInstance().refresh method after removing
+        // the bob from the session cache
         // See issue https://issues.openbravo.com/view.php?id=30308
         final List<BaseOBObject> refreshedBobs = new ArrayList<BaseOBObject>();
         for (BaseOBObject bob : bobs) {
-          // Remove the bob instance from the session cache with evict
-          OBDal.getInstance().getSession().evict(bob);
-          // With get() we retrieve the object from db as we have cleared it from cache with evict()
-          BaseOBObject refreshedBob = OBDal.getInstance().get(bob.getEntityName(), bob.getId());
+          BaseOBObject refreshedBob = OBDal.getInstance().refresh(bob, false);
           // if object has computed columns refresh from the database too
           if (refreshedBob.getEntity().hasComputedColumns()) {
             OBDal.getInstance().getSession()
--- a/src/org/openbravo/dal/service/OBDal.java	Wed Jun 24 16:56:47 2015 +0200
+++ b/src/org/openbravo/dal/service/OBDal.java	Fri Jul 03 19:31:11 2015 +0200
@@ -285,6 +285,22 @@
   }
 
   /**
+   * Refresh the given BaseOBObject.
+   * 
+   * @param bob
+   *          the BaseOBObject to refresh
+   * @return the BaseOBObject, or null if none found
+   */
+  public BaseOBObject refresh(BaseOBObject bob, boolean useCache) {
+    if (!useCache) {
+      // Remove the bob instance from the session cache with evict
+      // Now with get() we will retrieve the object from database
+      SessionHandler.getInstance().getSession().evict(bob);
+    }
+    return get(bob.getEntityName(), bob.getId());
+  }
+
+  /**
    * Retrieves an object from the database using the class and id.
    * 
    * @param clazz