Fixes issue 38828: TriggerHandler.enable no longer leaves triggers disabled
authorAugusto Mauch <augusto.mauch@openbravo.com>
Mon, 25 Jun 2018 14:52:03 +0200
changeset 34268 4887e05c89dc
parent 34267 42688f7eac68
child 34269 72eebae99400
Fixes issue 38828: TriggerHandler.enable no longer leaves triggers disabled

The problem was that if the flush indie TriggerHandler.enable (invoked when retrieving DAL's connection) failed, the clear method was not
invoked, and the ThreadLocal was not reset. The next time the thread was reused, it would work with disabled triggers.

Now that doesn't happen anymore because the flush is done inside the try block.
src/org/openbravo/dal/core/TriggerHandler.java
--- a/src/org/openbravo/dal/core/TriggerHandler.java	Thu Jun 14 19:20:21 2018 -0400
+++ b/src/org/openbravo/dal/core/TriggerHandler.java	Mon Jun 25 14:52:03 2018 +0200
@@ -101,21 +101,17 @@
     log.debug("Enabling triggers");
     Check.isNotNull(sessionStatus.get(), "SessionStatus not set, call disable "
         + "before calling this method");
-
-    Connection con = OBDal.getInstance().getConnection();
-    PreparedStatement ps = null;
     try {
-      ps = con.prepareStatement("DELETE FROM AD_SESSION_STATUS WHERE isimporting = 'Y'");
-      ps.executeUpdate();
+      Connection con = OBDal.getInstance().getConnection();
+      try (PreparedStatement ps = con
+          .prepareStatement("DELETE FROM AD_SESSION_STATUS WHERE isimporting = 'Y'")) {
+        ps.executeUpdate();
+      }
     } catch (Exception e) {
       throw new OBException("Couldn't disable triggers: ", e);
     } finally {
       // always clear the threadlocal
       clear();
-      try {
-        ps.close();
-      } catch (SQLException e) {
-      }
     }
   }
 }
\ No newline at end of file