details:   https://code.openbravo.com/erp/devel/pi/rev/f66c40dce8ca
changeset: 31073:f66c40dce8ca
user:      Asier Lostalé <asier.lostale <at> openbravo.com>
date:      Tue Jan 10 09:04:34 2017 +0100
summary:   fixed bug 34880: unneeded query execution when editing alert rules

  There is no need to execute the query defining the alert to check its 
metadata,
  it can be directly obtained from the statement without executing it.

details:   https://code.openbravo.com/erp/devel/pi/rev/30095891fd55
changeset: 31074:30095891fd55
user:      Asier Lostalé <asier.lostale <at> openbravo.com>
date:      Tue Jan 10 09:21:04 2017 +0100
summary:   related to bug 34880: some clean up

  - replaced printStackTrace with proper log
  - added class java doc

diffstat:

 src/org/openbravo/erpCommon/ad_callouts/SL_AlertRule_SQL.java |  24 +++++-----
 1 files changed, 11 insertions(+), 13 deletions(-)

diffs (73 lines):

diff -r a11bcc25fd0c -r 30095891fd55 
src/org/openbravo/erpCommon/ad_callouts/SL_AlertRule_SQL.java
--- a/src/org/openbravo/erpCommon/ad_callouts/SL_AlertRule_SQL.java     Thu Nov 
24 09:38:42 2016 -0800
+++ b/src/org/openbravo/erpCommon/ad_callouts/SL_AlertRule_SQL.java     Tue Jan 
10 09:21:04 2017 +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) 2001-2014 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2017 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -21,7 +21,6 @@
 import java.io.IOException;
 import java.io.PrintWriter;
 import java.sql.PreparedStatement;
-import java.sql.ResultSet;
 import java.sql.ResultSetMetaData;
 import java.sql.SQLException;
 
@@ -36,9 +35,15 @@
 import org.openbravo.exception.NoConnectionAvailableException;
 import org.openbravo.utils.FormatUtilities;
 import org.openbravo.xmlEngine.XmlDocument;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
+/**
+ * Checks the SQL in Alert Rule to ensure all required columns are included.
+ */
 public class SL_AlertRule_SQL extends HttpSecureAppServlet {
   private static final long serialVersionUID = 1L;
+  private static final Logger log = 
LoggerFactory.getLogger(SL_AlertRule_SQL.class);
 
   public void init(ServletConfig config) {
     super.init(config);
@@ -81,13 +86,11 @@
 
     if (!strSQL.equals("")) {
       if (strSQL.toUpperCase().trim().startsWith("SELECT ")) {
-        ResultSet result = null;
         PreparedStatement st = null;
         try {
           this.getConnection().setReadOnly(true);
           st = this.getPreparedStatement(strSQL);
-          result = st.executeQuery();
-          ResultSetMetaData rmeta = result.getMetaData();
+          ResultSetMetaData rmeta = st.getMetaData();
           if (!existsColumn(rmeta, "AD_CLIENT_ID"))
             msg = "AD_CLIENT_ID ";
           if (!existsColumn(rmeta, "AD_ORG_ID"))
@@ -119,18 +122,13 @@
         } finally {
           try {
             this.getConnection().setReadOnly(false);
-            if (result != null) {
-              result.close();
-            }
-          } catch (SQLException e) {
-            e.printStackTrace();
-          } catch (NoConnectionAvailableException e) {
-            e.printStackTrace();
+          } catch (SQLException | NoConnectionAvailableException e) {
+            log.error("Error resetting readonly to connection in Alert Rule 
query: {}", e);
           }
           try {
             this.releasePreparedStatement(st);
           } catch (SQLException e) {
-            e.printStackTrace();
+            log.error("Error releasing statement in Alert Rule query: {}", e);
           }
         }
       } else {

------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today. http://sdm.link/xeonphi
_______________________________________________
Openbravo-commits mailing list
Openbravo-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to