Fixed issue 26349: Robustness:Improve handling of disabling triggers.
authorInigo Sanchez <inigo.sanchez@openbravo.com>
Mon, 14 Dec 2015 14:11:12 +0100
changeset 28127 67bf31e6746a
parent 28126 f8182b504a55
child 28128 45c7d09e8fd0
Fixed issue 26349: Robustness:Improve handling of disabling triggers.

It has been improved the handling of disabling triggers by throwing
exceptions in enable() and disable() methods instead of error logs.

Now an exception is thrown if there is a problem in enable() and
disable() methods.

Besides it has been added a change to improve where clear() method
is invoked.
src/org/openbravo/dal/core/TriggerHandler.java
src/org/openbravo/service/system/SystemService.java
--- a/src/org/openbravo/dal/core/TriggerHandler.java	Thu Dec 10 19:24:07 2015 +0100
+++ b/src/org/openbravo/dal/core/TriggerHandler.java	Mon Dec 14 14:11:12 2015 +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-2012 Openbravo SLU 
+ * All portions are Copyright (C) 2008-2015 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -24,6 +24,7 @@
 import java.sql.SQLException;
 
 import org.apache.log4j.Logger;
+import org.openbravo.base.exception.OBException;
 import org.openbravo.base.provider.OBProvider;
 import org.openbravo.base.util.Check;
 import org.openbravo.dal.service.OBDal;
@@ -68,7 +69,7 @@
       ps.executeUpdate();
       sessionStatus.set(Boolean.TRUE);
     } catch (Exception e) {
-      log.error("Couldn't disable triggers: ", e);
+      throw new OBException("Couldn't disable triggers: ", e);
     } finally {
       try {
         ps.close();
@@ -105,10 +106,11 @@
     try {
       ps = con.prepareStatement("DELETE FROM AD_SESSION_STATUS");
       ps.executeUpdate();
-      sessionStatus.set(null);
     } catch (Exception e) {
-      log.error("Couldn't enable triggers: ", e);
+      throw new OBException("Couldn't disable triggers: ", e);
     } finally {
+      // always clear the threadlocal
+      clear();
       try {
         ps.close();
       } catch (SQLException e) {
--- a/src/org/openbravo/service/system/SystemService.java	Thu Dec 10 19:24:07 2015 +0100
+++ b/src/org/openbravo/service/system/SystemService.java	Mon Dec 14 14:11:12 2015 +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-2014 Openbravo SLU 
+ * All portions are Copyright (C) 2009-2015 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -226,6 +226,8 @@
       TriggerHandler.getInstance().enable();
       OBDal.getInstance().commitAndClose();
     } finally {
+      // always clear the threadlocal
+      TriggerHandler.getInstance().clear();
       OBContext.restorePreviousMode();
     }
   }