From: Marco Zanon Date: Thu, 13 Dec 2018 14:07:50 +0000 (+0000) Subject: Disabled or made optional some statement loggings, to prevent infinite loops. X-Git-Tag: 6.4.0~2 X-Git-Url: https://gitweb.marcozanon.com/?a=commitdiff_plain;h=4908da6bfb55abcd19fb4e3854012e3d5761062b;p=Macaco Disabled or made optional some statement loggings, to prevent infinite loops. --- diff --git a/src/java/com/marcozanon/macaco/database/MDatabaseConnection.java b/src/java/com/marcozanon/macaco/database/MDatabaseConnection.java index 6839866..a2b70aa 100644 --- a/src/java/com/marcozanon/macaco/database/MDatabaseConnection.java +++ b/src/java/com/marcozanon/macaco/database/MDatabaseConnection.java @@ -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(), this.getLocalTypesMode()); + return this.executePreparedStatement(statement, new LinkedList()); } public MSqlStatementResults executePreparedStatement(String statement, LinkedList parameters) throws MDatabaseConnectionFailureException, MSqlStatementException { @@ -260,6 +262,10 @@ public class MDatabaseConnection extends MObject { } public MSqlStatementResults executePreparedStatement(String statement, LinkedList parameters, boolean localTypesMode) throws MDatabaseConnectionFailureException, MSqlStatementException { + return this.executePreparedStatement(statement, parameters, this.getLocalTypesMode(), true); + }; + + public MSqlStatementResults executePreparedStatement(String statement, LinkedList 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()) { diff --git a/src/java/com/marcozanon/macaco/database/MSqlTable.java b/src/java/com/marcozanon/macaco/database/MSqlTable.java index dc99401..0384c6f 100644 --- a/src/java/com/marcozanon/macaco/database/MSqlTable.java +++ b/src/java/com/marcozanon/macaco/database/MSqlTable.java @@ -59,7 +59,7 @@ public class MSqlTable extends MObject { /* Statements. */ - protected MSqlStatementResults insertRecord(LinkedHashMap map) throws MDatabaseConnectionFailureException, MSqlStatementException { + protected MSqlStatementResults insertRecord(LinkedHashMap 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 map, Object id) throws MDatabaseConnectionFailureException, MSqlStatementException { + protected MSqlStatementResults updateRecord(LinkedHashMap 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 map, Object id) throws MDatabaseConnectionFailureException, MSqlStatementException { + return this.setRecord(map, id, true); + } + + public MSqlStatementResults setRecord(LinkedHashMap 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); } } diff --git a/src/java/com/marcozanon/macaco/logging/MLogDatabaseTable.java b/src/java/com/marcozanon/macaco/logging/MLogDatabaseTable.java index af38429..0529c5f 100644 --- a/src/java/com/marcozanon/macaco/logging/MLogDatabaseTable.java +++ b/src/java/com/marcozanon/macaco/logging/MLogDatabaseTable.java @@ -102,7 +102,7 @@ public class MLogDatabaseTable extends MLogTarget { // LinkedHashMap p = new LinkedHashMap(); 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); }