Disabled or made optional some statement loggings, to prevent infinite loops.
authorMarco Zanon <info@marcozanon.com>
Thu, 13 Dec 2018 14:07:50 +0000 (14:07 +0000)
committerMarco Zanon <info@marcozanon.com>
Thu, 13 Dec 2018 14:07:50 +0000 (14:07 +0000)
6.x/src/java/com/marcozanon/macaco/database/MDatabaseConnection.java
6.x/src/java/com/marcozanon/macaco/database/MSqlTable.java
6.x/src/java/com/marcozanon/macaco/logging/MLogDatabaseTable.java

index 6839866252545bc1d5f3d663dc8f658c38f69880..a2b70aaeee0ba6c56d12f1b5dac61c4dc9062d34 100644 (file)
@@ -87,7 +87,9 @@ public class MDatabaseConnection extends MObject {
         // Set SQL mode to standard ANSI and TRADITIONAL.
         try {
             this.getConnection().createStatement().executeUpdate("SET SQL_MODE = 'ANSI,TRADITIONAL'");
+/* Disabled to prevent an infinite loop.
             this.logStatement("### SET SQL_MODE = 'ANSI,TRADITIONAL' ###");
+*/
         }
         catch (SQLException exception) {
             throw new MDatabaseConnectionFailureException("Could not set SQL mode to ANSI and TRADITIONAL.", exception);
@@ -252,7 +254,7 @@ public class MDatabaseConnection extends MObject {
     /* Statements. */
 
     public MSqlStatementResults executePreparedStatement(String statement) throws MDatabaseConnectionFailureException, MSqlStatementException {
-        return this.executePreparedStatement(statement, new LinkedList<Object>(), this.getLocalTypesMode());
+        return this.executePreparedStatement(statement, new LinkedList<Object>());
     }
 
     public MSqlStatementResults executePreparedStatement(String statement, LinkedList<Object> parameters) throws MDatabaseConnectionFailureException, MSqlStatementException {
@@ -260,6 +262,10 @@ public class MDatabaseConnection extends MObject {
     }
 
     public MSqlStatementResults executePreparedStatement(String statement, LinkedList<Object> parameters, boolean localTypesMode) throws MDatabaseConnectionFailureException, MSqlStatementException {
+        return this.executePreparedStatement(statement, parameters, this.getLocalTypesMode(), true);
+    };
+
+    public MSqlStatementResults executePreparedStatement(String statement, LinkedList<Object> parameters, boolean localTypesMode, boolean loggableStatement) throws MDatabaseConnectionFailureException, MSqlStatementException {
         if (MText.isBlank(statement)) {
             throw new IllegalArgumentException("Invalid 'statement': null or empty.");
         }
@@ -280,7 +286,9 @@ public class MDatabaseConnection extends MObject {
             // Execute the statement and parse the results.
             preparedStatement.execute();
             results = new MSqlStatementResults(preparedStatement, localTypesMode);
-            this.logStatement(preparedStatement.toString());
+            if (loggableStatement) {
+                this.logStatement(preparedStatement.toString());
+            }
         }
         catch (MDatabaseConnectionFailureException exception) {
             if (MDatabaseConnection.TransactionStatus.SUCCESSFUL == this.getTransactionStatus()) {
index dc99401d6506cde955e1dc2280fe6db4de006364..0384c6fdd3d4b97e60aa36caa32a218cf4232ac3 100644 (file)
@@ -59,7 +59,7 @@ public class MSqlTable extends MObject {
 
     /* Statements. */
 
-    protected MSqlStatementResults insertRecord(LinkedHashMap<String, Object> map) throws MDatabaseConnectionFailureException, MSqlStatementException {
+    protected MSqlStatementResults insertRecord(LinkedHashMap<String, Object> map, boolean loggableStatement) throws MDatabaseConnectionFailureException, MSqlStatementException {
         if (null == map) {
             throw new IllegalArgumentException("Invalid 'map': null.");
         }
@@ -78,10 +78,10 @@ public class MSqlTable extends MObject {
         return this.getDatabaseConnection().executePreparedStatement(" INSERT INTO \"" + this.getTable() + "\""
                                                                    + "             (" + fields + ")"
                                                                    + " VALUES      (" + s + ")",
-                                                                     p);
+                                                                     p, true, loggableStatement);
     }
 
-    protected MSqlStatementResults updateRecord(LinkedHashMap<String, Object> map, Object id) throws MDatabaseConnectionFailureException, MSqlStatementException {
+    protected MSqlStatementResults updateRecord(LinkedHashMap<String, Object> map, Object id, boolean loggableStatement) throws MDatabaseConnectionFailureException, MSqlStatementException {
         if (null == map) {
             throw new IllegalArgumentException("Invalid 'map': null.");
         }
@@ -101,15 +101,19 @@ public class MSqlTable extends MObject {
         return this.getDatabaseConnection().executePreparedStatement(" UPDATE  \"" + this.getTable() + "\""
                                                                    + " SET     " + s
                                                                    + " WHERE   (\"" + this.getTable() + "\".\"" + this.getPrimaryKey() + "\" = ?)",
-                                                                     p);
+                                                                     p, true, loggableStatement);
     }
 
     public MSqlStatementResults setRecord(LinkedHashMap<String, Object> map, Object id) throws MDatabaseConnectionFailureException, MSqlStatementException {
+        return this.setRecord(map, id, true);
+    }
+
+    public MSqlStatementResults setRecord(LinkedHashMap<String, Object> map, Object id, boolean loggableStatement) throws MDatabaseConnectionFailureException, MSqlStatementException {
         if (null == id) {
-            return this.insertRecord(map);
+            return this.insertRecord(map, loggableStatement);
         }
         else {
-            return this.updateRecord(map, id);
+            return this.updateRecord(map, id, loggableStatement);
         }
     }
 
index af384295dd6920af18caaaabd5a983cedb9e72fb..0529c5f16dcd00349ba186b2b11bc74cdf717d46 100644 (file)
@@ -102,7 +102,7 @@ public class MLogDatabaseTable extends MLogTarget {
             //
             LinkedHashMap<String, Object> p = new LinkedHashMap<String, Object>();
             p.put(this.getLogDatabaseField(), timestamp + separator + message);
-            (new MSqlTable(databaseConnection, this.getLogDatabaseTable(), this.getLogDatabaseTablePrimaryKey())).setRecord(p, null);
+            (new MSqlTable(databaseConnection, this.getLogDatabaseTable(), this.getLogDatabaseTablePrimaryKey())).setRecord(p, null, false);
             //
             this.getDatabaseConnectionPool().pushDatabaseConnection(databaseConnection);
         }