details:   /erp/devel/pi/rev/b535611b2394
changeset: 6972:b535611b2394
user:      Martin Taal <martin.taal <at> openbravo.com>
date:      Fri Apr 09 21:11:28 2010 +0200
summary:   fixes issue 12918: DAL: Exception in commitTransaction leaves 
Postgres connection in illegal state

details:   /erp/devel/pi/rev/253f727de17e
changeset: 6973:253f727de17e
user:      Martin Taal <martin.taal <at> openbravo.com>
date:      Fri Apr 09 21:12:35 2010 +0200
summary:   fixes issue 12901: OBDal.getInstance().getConnection() does not 
setup dateFormat correctly

diffstat:

 src/org/openbravo/dal/core/DalSessionFactory.java |  13 +++++++++++--
 src/org/openbravo/dal/core/SessionHandler.java    |  10 ++++++++++
 src/org/openbravo/dal/service/OBDal.java          |  21 ++++++---------------
 3 files changed, 27 insertions(+), 17 deletions(-)

diffs (118 lines):

diff -r 6c78ad9d5176 -r 253f727de17e 
src/org/openbravo/dal/core/DalSessionFactory.java
--- a/src/org/openbravo/dal/core/DalSessionFactory.java Fri Apr 09 19:17:41 
2010 +0200
+++ b/src/org/openbravo/dal/core/DalSessionFactory.java Fri Apr 09 21:12:35 
2010 +0200
@@ -21,7 +21,9 @@
 
 import java.io.Serializable;
 import java.sql.Connection;
+import java.sql.PreparedStatement;
 import java.util.Map;
+import java.util.Properties;
 import java.util.Set;
 
 import javax.naming.NamingException;
@@ -167,10 +169,17 @@
     final ClassLoader currentLoader = 
Thread.currentThread().getContextClassLoader();
     try {
       
Thread.currentThread().setContextClassLoader(BorrowedConnectionProxy.class.getClassLoader());
+      final Properties props = 
OBPropertiesProvider.getInstance().getOpenbravoProperties();
       Connection conn = ((SessionImplementor) session).connection();
-      SessionInfo.initDB(conn, 
OBPropertiesProvider.getInstance().getOpenbravoProperties()
-          .getProperty("bbdd.rdbms"));
+      SessionInfo.initDB(conn, props.getProperty("bbdd.rdbms"));
       SessionInfo.setDBSessionInfo(conn);
+      try {
+        final String dbSessionConfig = props.getProperty("bbdd.sessionConfig");
+        PreparedStatement pstmt = conn.prepareStatement(dbSessionConfig);
+        pstmt.executeQuery();
+      } catch (Exception e) {
+        throw new IllegalStateException(e);
+      }
     } finally {
       Thread.currentThread().setContextClassLoader(currentLoader);
     }
diff -r 6c78ad9d5176 -r 253f727de17e 
src/org/openbravo/dal/core/SessionHandler.java
--- a/src/org/openbravo/dal/core/SessionHandler.java    Fri Apr 09 19:17:41 
2010 +0200
+++ b/src/org/openbravo/dal/core/SessionHandler.java    Fri Apr 09 21:12:35 
2010 +0200
@@ -205,11 +205,21 @@
    * work.
    */
   public void commitAndClose() {
+    boolean err = true;
     try {
       checkInvariant();
       tx.commit();
       tx = null;
+      err = false;
     } finally {
+      if (err) {
+        try {
+          tx.rollback();
+          tx = null;
+        } catch (Throwable t) {
+          // ignore these exception not to hide others
+        }
+      }
       deleteSessionHandler();
       closeSession();
     }
diff -r 6c78ad9d5176 -r 253f727de17e src/org/openbravo/dal/service/OBDal.java
--- a/src/org/openbravo/dal/service/OBDal.java  Fri Apr 09 19:17:41 2010 +0200
+++ b/src/org/openbravo/dal/service/OBDal.java  Fri Apr 09 21:12:35 2010 +0200
@@ -20,10 +20,8 @@
 package org.openbravo.dal.service;
 
 import java.sql.Connection;
-import java.sql.PreparedStatement;
 import java.util.ArrayList;
 import java.util.List;
-import java.util.Properties;
 
 import org.apache.log4j.Logger;
 import org.hibernate.Session;
@@ -36,7 +34,6 @@
 import org.openbravo.base.model.UniqueConstraint;
 import org.openbravo.base.provider.OBProvider;
 import org.openbravo.base.provider.OBSingleton;
-import org.openbravo.base.session.OBPropertiesProvider;
 import org.openbravo.base.structure.BaseOBObject;
 import org.openbravo.base.structure.ClientEnabled;
 import org.openbravo.base.structure.OrganizationEnabled;
@@ -95,16 +92,6 @@
       
Thread.currentThread().setContextClassLoader(BorrowedConnectionProxy.class.getClassLoader());
       final Connection connection = ((SessionImplementor) 
SessionHandler.getInstance().getSession())
           .connection();
-
-      // set the date formatting
-      try {
-        final Properties props = 
OBPropertiesProvider.getInstance().getOpenbravoProperties();
-        final String dbSessionConfig = props.getProperty("bbdd.sessionConfig");
-        PreparedStatement pstmt = connection.prepareStatement(dbSessionConfig);
-        pstmt.executeQuery();
-      } catch (Exception e) {
-        throw new IllegalStateException(e);
-      }
       return connection;
     } finally {
       Thread.currentThread().setContextClassLoader(currentLoader);
@@ -131,14 +118,18 @@
    * Rolls back the transaction and closes the session.
    */
   public void rollbackAndClose() {
-    SessionHandler.getInstance().rollback();
+    if (SessionHandler.isSessionHandlerPresent()) {
+      SessionHandler.getInstance().rollback();
+    }
   }
 
   /**
    * Flushes the current state to the database.
    */
   public void flush() {
-    SessionHandler.getInstance().getSession().flush();
+    if (SessionHandler.isSessionHandlerPresent()) {
+      SessionHandler.getInstance().getSession().flush();
+    }
   }
 
   /**

------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to