details:   https://code.openbravo.com/erp/devel/pi/rev/2268a549839c
changeset: 27067:2268a549839c
user:      Carlos Aristu <carlos.aristu <at> openbravo.com>
date:      Fri Jul 03 19:31:11 2015 +0200
summary:   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

diffstat:

 
modules/org.openbravo.service.json/src/org/openbravo/service/json/DefaultJsonDataService.java
 |   7 +--
 src/org/openbravo/dal/service/OBDal.java                                       
               |  16 ++++++++++
 2 files changed, 19 insertions(+), 4 deletions(-)

diffs (46 lines):

diff -r f6dcfa9328cf -r 2268a549839c 
modules/org.openbravo.service.json/src/org/openbravo/service/json/DefaultJsonDataService.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()
diff -r f6dcfa9328cf -r 2268a549839c src/org/openbravo/dal/service/OBDal.java
--- 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

------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
_______________________________________________
Openbravo-commits mailing list
Openbravo-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to