This is an automated email from the ASF dual-hosted git repository.

paulfoxworthy pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 404cb9fd02 Fixed: Log SQL statement in exceptions in 
EntitySQLProcessor (OFBIZ-12837)
404cb9fd02 is described below

commit 404cb9fd0260778c801f6b7edaf7d810e4324fec
Author: paul <p...@cohsoft.com.au>
AuthorDate: Sat Jul 22 17:08:35 2023 +1000

    Fixed: Log SQL statement in exceptions in EntitySQLProcessor (OFBIZ-12837)
    
    The combination of OFBIZ-11926 and OFBIZ-12386 means the field
    
           SQLProcessor.sql
    
    is never set, but it was originally designed to cache the SQL command and 
is assumed to be there in several catches.
    
    If an exception occurs, you'll get a "null" and not the statement that 
caused the exception.
---
 .../main/java/org/apache/ofbiz/entity/jdbc/SQLProcessor.java | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git 
a/framework/entity/src/main/java/org/apache/ofbiz/entity/jdbc/SQLProcessor.java 
b/framework/entity/src/main/java/org/apache/ofbiz/entity/jdbc/SQLProcessor.java
index eebc1a7db5..30c2a7f2f1 100644
--- 
a/framework/entity/src/main/java/org/apache/ofbiz/entity/jdbc/SQLProcessor.java
+++ 
b/framework/entity/src/main/java/org/apache/ofbiz/entity/jdbc/SQLProcessor.java
@@ -368,6 +368,8 @@ public class SQLProcessor implements AutoCloseable {
             Debug.logVerbose("[SQLProcessor.prepareStatement] sql=" + sql, 
MODULE);
         }
 
+        this.sql = sql;
+
         if (connection == null) {
             getConnection();
         }
@@ -393,7 +395,7 @@ public class SQLProcessor implements AutoCloseable {
             }
             this.setFetchSize(ps, fetchSize);
         } catch (SQLException sqle) {
-            throw new GenericDataSourceException("SQL Exception while 
executing the following:" + sql, sqle);
+            throw new GenericDataSourceException("SQL Exception while 
executing the following:" + this.sql, sqle);
         }
     }
 
@@ -408,7 +410,7 @@ public class SQLProcessor implements AutoCloseable {
             resultSet = ps.executeQuery();
         } catch (SQLException sqle) {
             this.checkLockWaitInfo(sqle);
-            throw new GenericDataSourceException("SQL Exception while 
executing the following:" + sql, sqle);
+            throw new GenericDataSourceException("SQL Exception while 
executing the following:" + this.sql, sqle);
         }
 
         return resultSet;
@@ -440,7 +442,7 @@ public class SQLProcessor implements AutoCloseable {
             this.checkLockWaitInfo(sqle);
             // don't display this here, may not be critical, allow handling 
further up...
             // Debug.logError(sqle, "SQLProcessor.executeUpdate() : ERROR : ", 
MODULE);
-            throw new GenericDataSourceException("SQL Exception while 
executing the following:" + sql, sqle);
+            throw new GenericDataSourceException("SQL Exception while 
executing the following:" + this.sql, sqle);
         }
     }
 
@@ -469,7 +471,7 @@ public class SQLProcessor implements AutoCloseable {
         try {
             return resultSet.next();
         } catch (SQLException sqle) {
-            throw new GenericDataSourceException("SQL Exception while 
executing the following:" + sql, sqle);
+            throw new GenericDataSourceException("SQL Exception while 
executing the following:" + this.sql, sqle);
         }
     }
 
@@ -850,7 +852,7 @@ public class SQLProcessor implements AutoCloseable {
         // see if there is a lock wait timeout error, if so try to get and 
print more info about it
         //   the string for Derby is "A lock could not be obtained within the 
time requested"
         //   the string for MySQL is "Lock wait timeout exceeded; try 
restarting transaction"
-        if (eMsg.indexOf("A lock could not be obtained within the time 
requested") >= 0 || eMsg.indexOf("Lock wait timeout exceeded") >= 0) {
+        if (eMsg.contains("A lock could not be obtained within the time 
requested") || eMsg.contains("Lock wait timeout exceeded")) {
             Debug.logWarning(sqle, "Lock wait timeout error found in thread [" 
+ Thread.currentThread().getId() + "]: (" + eMsg
                     + ") when executing the SQL [" + sql + "]", MODULE);
             TransactionUtil.printAllThreadsTransactionBeginStacks();

Reply via email to