IDEMPIERE-116 Logged database write operation together with transaction name
(transplanted from 159979f793dee69e0d035e6df5ea9ecae60de2f8)
This commit is contained in:
parent
17e9c39b28
commit
430f7e8e72
|
@ -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)");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue