Made flush controllable when getting connection
authorMartin Taal <martin.taal@openbravo.com>
Mon, 24 Jan 2011 14:13:25 +0100
changeset 10090 dfcbfe6138cc
parent 10089 6ceba33c2320
child 10091 8eaee0bdefcd
Made flush controllable when getting connection
src/org/openbravo/dal/service/OBDal.java
src/org/openbravo/service/db/DalConnectionProvider.java
--- a/src/org/openbravo/dal/service/OBDal.java	Mon Jan 24 13:58:00 2011 +0100
+++ b/src/org/openbravo/dal/service/OBDal.java	Mon Jan 24 14:13:25 2011 +0100
@@ -11,7 +11,7 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2008 Openbravo SLU 
+ * All portions are Copyright (C) 2008-2011 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -81,9 +81,24 @@
    * @see #flush()
    */
   public Connection getConnection() {
-    // before returning a connection always flush all other hibernate actions
-    // to the database.
-    flush();
+    return getConnection(true);
+  }
+
+  /**
+   * Returns the connection used by the hibernate session.
+   * 
+   * @param doFlush
+   *          if true then the current actions are first flushed.
+   * 
+   * @return the current database connection
+   * @see #flush()
+   */
+  public Connection getConnection(boolean doFlush) {
+    if (doFlush) {
+      // before returning a connection flush all other hibernate actions
+      // to the database.
+      flush();
+    }
 
     // NOTE: workaround for this issue:
     // http://opensource.atlassian.com/projects/hibernate/browse/HHH-3529
--- a/src/org/openbravo/service/db/DalConnectionProvider.java	Mon Jan 24 13:58:00 2011 +0100
+++ b/src/org/openbravo/service/db/DalConnectionProvider.java	Mon Jan 24 14:13:25 2011 +0100
@@ -11,7 +11,7 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2009 Openbravo SLU 
+ * All portions are Copyright (C) 2009-2011 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -75,7 +75,7 @@
 
   public Connection getConnection() throws NoConnectionAvailableException {
     if (connection == null) {
-      connection = OBDal.getInstance().getConnection();
+      connection = OBDal.getInstance().getConnection(flush);
     }
 
     // always flush all remaining actions