From 430f7e8e72c4c1f6188670a21468809d48e1b712 Mon Sep 17 00:00:00 2001 From: Heng Sin Low Date: Sat, 21 Jan 2012 10:24:37 +0800 Subject: [PATCH] IDEMPIERE-116 Logged database write operation together with transaction name (transplanted from 159979f793dee69e0d035e6df5ea9ecae60de2f8) --- .../src/org/compiere/db/StatementProxy.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/org.adempiere.base/src/org/compiere/db/StatementProxy.java b/org.adempiere.base/src/org/compiere/db/StatementProxy.java index 936babe1b5..89dcc00bfd 100644 --- a/org.adempiere.base/src/org/compiere/db/StatementProxy.java +++ b/org.adempiere.base/src/org/compiere/db/StatementProxy.java @@ -19,6 +19,7 @@ import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; +import java.util.Date; import java.util.logging.Level; import javax.sql.RowSet; @@ -28,6 +29,7 @@ import org.compiere.util.CCachedRowSet; import org.compiere.util.CLogger; import org.compiere.util.CStatementVO; import org.compiere.util.DB; +import org.compiere.util.DisplayType; import org.compiere.util.Trx; /** @@ -94,6 +96,29 @@ public class StatementProxy implements InvocationHandler { return getSql(); } + String logSql = null; + String logOperation = null; + if (log.isLoggable(Level.FINE) && getSql() != null) + { + if (name.equals("executeUpdate") || name.equals("execute")) + { + logSql = getSql().toUpperCase(); + if (logSql.startsWith("UPDATE ")) { + logSql = logSql.substring("UPDATE ".length()).trim(); + logOperation = "Update"; + } else if (logSql.startsWith("INSERT INTO ")) { + logSql = logSql.substring("INSERT INTO ".length()).trim(); + logOperation = "Insert"; + } else if (logSql.startsWith("DELETE FROM ")) { + logSql = logSql.substring("DELETE FROM ".length()).trim(); + logOperation = "Delete"; + } + if (logOperation != null) { + logSql = logSql.substring(0, logSql.indexOf(' ')); + log.fine((DisplayType.getDateFormat(DisplayType.DateTime)).format(new Date(System.currentTimeMillis()))+","+logOperation+","+logSql+","+(p_vo.getTrxName() != null ? p_vo.getTrxName() : "")+" (begin)"); + } + } + } Method m = p_stmt.getClass().getMethod(name, method.getParameterTypes()); try { @@ -103,6 +128,13 @@ public class StatementProxy implements InvocationHandler { { throw DB.getSQLException(e); } + finally + { + if (log.isLoggable(Level.FINE) && logSql != null && logOperation != null) + { + log.fine((DisplayType.getDateFormat(DisplayType.DateTime)).format(new Date(System.currentTimeMillis()))+","+logOperation+","+logSql+","+(p_vo.getTrxName() != null ? p_vo.getTrxName() : "")+" (end)"); + } + } } /**