diff --git a/src/nl/astraeus/jdbc/ConnectionLogger.java b/src/nl/astraeus/jdbc/ConnectionLogger.java index c359692..0bd1776 100644 --- a/src/nl/astraeus/jdbc/ConnectionLogger.java +++ b/src/nl/astraeus/jdbc/ConnectionLogger.java @@ -27,11 +27,11 @@ nano = System.nanoTime(); } - private void log(String sql) { + private void log(String sql) throws SQLException { long m = System.currentTimeMillis() - milli; long n = System.nanoTime() - nano; - JdbcLogger.log(QueryType.UNKNOWN, sql, m, n); + JdbcLogger.log(QueryType.UNKNOWN, sql, m, n, connection.getAutoCommit()); } public void commit() throws SQLException { diff --git a/src/nl/astraeus/jdbc/ConnectionLogger.java b/src/nl/astraeus/jdbc/ConnectionLogger.java index c359692..0bd1776 100644 --- a/src/nl/astraeus/jdbc/ConnectionLogger.java +++ b/src/nl/astraeus/jdbc/ConnectionLogger.java @@ -27,11 +27,11 @@ nano = System.nanoTime(); } - private void log(String sql) { + private void log(String sql) throws SQLException { long m = System.currentTimeMillis() - milli; long n = System.nanoTime() - nano; - JdbcLogger.log(QueryType.UNKNOWN, sql, m, n); + JdbcLogger.log(QueryType.UNKNOWN, sql, m, n, connection.getAutoCommit()); } public void commit() throws SQLException { diff --git a/src/nl/astraeus/jdbc/JdbcLogger.java b/src/nl/astraeus/jdbc/JdbcLogger.java index 2a22033..3019d9b 100644 --- a/src/nl/astraeus/jdbc/JdbcLogger.java +++ b/src/nl/astraeus/jdbc/JdbcLogger.java @@ -29,9 +29,10 @@ private long nano; private int hash; private int count; + private boolean autoCommit; private StackTraceElement[] stackTrace = null; - public LogEntry(int hash, QueryType type, String sql, long milli, long nano) { + public LogEntry(int hash, QueryType type, String sql, long milli, long nano, boolean isAutoCommit) { this.threadId = Thread.currentThread().getId(); this.timeStamp = System.currentTimeMillis(); this.hash = hash; @@ -39,6 +40,7 @@ this.sql = sql; this.milli = milli; this.nano = nano; + this.autoCommit = isAutoCommit; this.count = 1; } @@ -50,6 +52,7 @@ this.milli = le.milli; this.nano = le.nano; this.count = le.count; + this.autoCommit = le.autoCommit; } public QueryType getType() { @@ -101,7 +104,23 @@ } public String getSql() { - return sql; + String tmp = sql.toLowerCase(); + + tmp = tmp.replaceAll("create table ", "CREATE TABLE "); + tmp = tmp.replaceAll("insert into ", "INSERT INTO "); + tmp = tmp.replaceAll("delete from ", "DELETE FROM "); + + tmp = tmp.replaceAll("select ", "SELECT "); + tmp = tmp.replaceAll(" from ", " \nFROM "); + tmp = tmp.replaceAll(" where ", " \nWHERE "); + tmp = tmp.replaceAll(" order by ", " \nORDER BY "); + tmp = tmp.replaceAll(" group by ", " \nGROUP BY "); + tmp = tmp.replaceAll(" having ", " \nHAVING "); + + tmp = tmp.replaceAll("update ", "UPDATE "); + tmp = tmp.replaceAll(" set ", " \nSET "); + + return tmp; } public void addCount(LogEntry le) { @@ -122,6 +141,10 @@ public StackTraceElement[] getStackTrace() { return stackTrace; } + + public boolean isAutoCommit() { + return autoCommit; + } } private final List queries; @@ -155,10 +178,10 @@ this.cacheSize = cacheSize; } - public void logEntry(QueryType type, String sql, long milli, long nano) { + public void logEntry(QueryType type, String sql, long milli, long nano, boolean isAutoCommit) { int hash = sql.hashCode(); - LogEntry entry = new LogEntry(hash, type, sql, milli, nano); + LogEntry entry = new LogEntry(hash, type, sql, milli, nano, isAutoCommit); if (recording) { try { @@ -178,8 +201,8 @@ } } - public static void log(QueryType type, String sql, long milli, long nano) { - instance.logEntry(type, sql, milli, nano); + public static void log(QueryType type, String sql, long milli, long nano, boolean isAutoCommit) { + instance.logEntry(type, sql, milli, nano, isAutoCommit); } public List getEntries() { diff --git a/src/nl/astraeus/jdbc/ConnectionLogger.java b/src/nl/astraeus/jdbc/ConnectionLogger.java index c359692..0bd1776 100644 --- a/src/nl/astraeus/jdbc/ConnectionLogger.java +++ b/src/nl/astraeus/jdbc/ConnectionLogger.java @@ -27,11 +27,11 @@ nano = System.nanoTime(); } - private void log(String sql) { + private void log(String sql) throws SQLException { long m = System.currentTimeMillis() - milli; long n = System.nanoTime() - nano; - JdbcLogger.log(QueryType.UNKNOWN, sql, m, n); + JdbcLogger.log(QueryType.UNKNOWN, sql, m, n, connection.getAutoCommit()); } public void commit() throws SQLException { diff --git a/src/nl/astraeus/jdbc/JdbcLogger.java b/src/nl/astraeus/jdbc/JdbcLogger.java index 2a22033..3019d9b 100644 --- a/src/nl/astraeus/jdbc/JdbcLogger.java +++ b/src/nl/astraeus/jdbc/JdbcLogger.java @@ -29,9 +29,10 @@ private long nano; private int hash; private int count; + private boolean autoCommit; private StackTraceElement[] stackTrace = null; - public LogEntry(int hash, QueryType type, String sql, long milli, long nano) { + public LogEntry(int hash, QueryType type, String sql, long milli, long nano, boolean isAutoCommit) { this.threadId = Thread.currentThread().getId(); this.timeStamp = System.currentTimeMillis(); this.hash = hash; @@ -39,6 +40,7 @@ this.sql = sql; this.milli = milli; this.nano = nano; + this.autoCommit = isAutoCommit; this.count = 1; } @@ -50,6 +52,7 @@ this.milli = le.milli; this.nano = le.nano; this.count = le.count; + this.autoCommit = le.autoCommit; } public QueryType getType() { @@ -101,7 +104,23 @@ } public String getSql() { - return sql; + String tmp = sql.toLowerCase(); + + tmp = tmp.replaceAll("create table ", "CREATE TABLE "); + tmp = tmp.replaceAll("insert into ", "INSERT INTO "); + tmp = tmp.replaceAll("delete from ", "DELETE FROM "); + + tmp = tmp.replaceAll("select ", "SELECT "); + tmp = tmp.replaceAll(" from ", " \nFROM "); + tmp = tmp.replaceAll(" where ", " \nWHERE "); + tmp = tmp.replaceAll(" order by ", " \nORDER BY "); + tmp = tmp.replaceAll(" group by ", " \nGROUP BY "); + tmp = tmp.replaceAll(" having ", " \nHAVING "); + + tmp = tmp.replaceAll("update ", "UPDATE "); + tmp = tmp.replaceAll(" set ", " \nSET "); + + return tmp; } public void addCount(LogEntry le) { @@ -122,6 +141,10 @@ public StackTraceElement[] getStackTrace() { return stackTrace; } + + public boolean isAutoCommit() { + return autoCommit; + } } private final List queries; @@ -155,10 +178,10 @@ this.cacheSize = cacheSize; } - public void logEntry(QueryType type, String sql, long milli, long nano) { + public void logEntry(QueryType type, String sql, long milli, long nano, boolean isAutoCommit) { int hash = sql.hashCode(); - LogEntry entry = new LogEntry(hash, type, sql, milli, nano); + LogEntry entry = new LogEntry(hash, type, sql, milli, nano, isAutoCommit); if (recording) { try { @@ -178,8 +201,8 @@ } } - public static void log(QueryType type, String sql, long milli, long nano) { - instance.logEntry(type, sql, milli, nano); + public static void log(QueryType type, String sql, long milli, long nano, boolean isAutoCommit) { + instance.logEntry(type, sql, milli, nano, isAutoCommit); } public List getEntries() { diff --git a/src/nl/astraeus/jdbc/PreparedStatementLogger.java b/src/nl/astraeus/jdbc/PreparedStatementLogger.java index cc6c2c1..fca3e5c 100644 --- a/src/nl/astraeus/jdbc/PreparedStatementLogger.java +++ b/src/nl/astraeus/jdbc/PreparedStatementLogger.java @@ -38,11 +38,11 @@ nano = System.nanoTime(); } - private void log(QueryType type, String sql) { + private void log(QueryType type, String sql) throws SQLException { long m = System.currentTimeMillis() - milli; long n = System.nanoTime() - nano; - JdbcLogger.log(type, sql, m, n); + JdbcLogger.log(type, sql, m, n, getConnection().getAutoCommit()); } public PreparedStatementLogger(Connection connection, String sql) throws SQLException { diff --git a/src/nl/astraeus/jdbc/ConnectionLogger.java b/src/nl/astraeus/jdbc/ConnectionLogger.java index c359692..0bd1776 100644 --- a/src/nl/astraeus/jdbc/ConnectionLogger.java +++ b/src/nl/astraeus/jdbc/ConnectionLogger.java @@ -27,11 +27,11 @@ nano = System.nanoTime(); } - private void log(String sql) { + private void log(String sql) throws SQLException { long m = System.currentTimeMillis() - milli; long n = System.nanoTime() - nano; - JdbcLogger.log(QueryType.UNKNOWN, sql, m, n); + JdbcLogger.log(QueryType.UNKNOWN, sql, m, n, connection.getAutoCommit()); } public void commit() throws SQLException { diff --git a/src/nl/astraeus/jdbc/JdbcLogger.java b/src/nl/astraeus/jdbc/JdbcLogger.java index 2a22033..3019d9b 100644 --- a/src/nl/astraeus/jdbc/JdbcLogger.java +++ b/src/nl/astraeus/jdbc/JdbcLogger.java @@ -29,9 +29,10 @@ private long nano; private int hash; private int count; + private boolean autoCommit; private StackTraceElement[] stackTrace = null; - public LogEntry(int hash, QueryType type, String sql, long milli, long nano) { + public LogEntry(int hash, QueryType type, String sql, long milli, long nano, boolean isAutoCommit) { this.threadId = Thread.currentThread().getId(); this.timeStamp = System.currentTimeMillis(); this.hash = hash; @@ -39,6 +40,7 @@ this.sql = sql; this.milli = milli; this.nano = nano; + this.autoCommit = isAutoCommit; this.count = 1; } @@ -50,6 +52,7 @@ this.milli = le.milli; this.nano = le.nano; this.count = le.count; + this.autoCommit = le.autoCommit; } public QueryType getType() { @@ -101,7 +104,23 @@ } public String getSql() { - return sql; + String tmp = sql.toLowerCase(); + + tmp = tmp.replaceAll("create table ", "CREATE TABLE "); + tmp = tmp.replaceAll("insert into ", "INSERT INTO "); + tmp = tmp.replaceAll("delete from ", "DELETE FROM "); + + tmp = tmp.replaceAll("select ", "SELECT "); + tmp = tmp.replaceAll(" from ", " \nFROM "); + tmp = tmp.replaceAll(" where ", " \nWHERE "); + tmp = tmp.replaceAll(" order by ", " \nORDER BY "); + tmp = tmp.replaceAll(" group by ", " \nGROUP BY "); + tmp = tmp.replaceAll(" having ", " \nHAVING "); + + tmp = tmp.replaceAll("update ", "UPDATE "); + tmp = tmp.replaceAll(" set ", " \nSET "); + + return tmp; } public void addCount(LogEntry le) { @@ -122,6 +141,10 @@ public StackTraceElement[] getStackTrace() { return stackTrace; } + + public boolean isAutoCommit() { + return autoCommit; + } } private final List queries; @@ -155,10 +178,10 @@ this.cacheSize = cacheSize; } - public void logEntry(QueryType type, String sql, long milli, long nano) { + public void logEntry(QueryType type, String sql, long milli, long nano, boolean isAutoCommit) { int hash = sql.hashCode(); - LogEntry entry = new LogEntry(hash, type, sql, milli, nano); + LogEntry entry = new LogEntry(hash, type, sql, milli, nano, isAutoCommit); if (recording) { try { @@ -178,8 +201,8 @@ } } - public static void log(QueryType type, String sql, long milli, long nano) { - instance.logEntry(type, sql, milli, nano); + public static void log(QueryType type, String sql, long milli, long nano, boolean isAutoCommit) { + instance.logEntry(type, sql, milli, nano, isAutoCommit); } public List getEntries() { diff --git a/src/nl/astraeus/jdbc/PreparedStatementLogger.java b/src/nl/astraeus/jdbc/PreparedStatementLogger.java index cc6c2c1..fca3e5c 100644 --- a/src/nl/astraeus/jdbc/PreparedStatementLogger.java +++ b/src/nl/astraeus/jdbc/PreparedStatementLogger.java @@ -38,11 +38,11 @@ nano = System.nanoTime(); } - private void log(QueryType type, String sql) { + private void log(QueryType type, String sql) throws SQLException { long m = System.currentTimeMillis() - milli; long n = System.nanoTime() - nano; - JdbcLogger.log(type, sql, m, n); + JdbcLogger.log(type, sql, m, n, getConnection().getAutoCommit()); } public PreparedStatementLogger(Connection connection, String sql) throws SQLException { diff --git a/src/nl/astraeus/jdbc/StatementLogger.java b/src/nl/astraeus/jdbc/StatementLogger.java index c440e43..d9838e0 100644 --- a/src/nl/astraeus/jdbc/StatementLogger.java +++ b/src/nl/astraeus/jdbc/StatementLogger.java @@ -26,11 +26,11 @@ nano = System.nanoTime(); } - private void log(QueryType type, String sql) { + private void log(QueryType type, String sql) throws SQLException { long m = System.currentTimeMillis() - milli; long n = System.nanoTime() - nano; - JdbcLogger.log(type, sql, m, n); + JdbcLogger.log(type, sql, m, n, getConnection() == null ? true : getConnection().getAutoCommit()); } public ResultSet executeQuery(String sql) throws SQLException { diff --git a/src/nl/astraeus/jdbc/ConnectionLogger.java b/src/nl/astraeus/jdbc/ConnectionLogger.java index c359692..0bd1776 100644 --- a/src/nl/astraeus/jdbc/ConnectionLogger.java +++ b/src/nl/astraeus/jdbc/ConnectionLogger.java @@ -27,11 +27,11 @@ nano = System.nanoTime(); } - private void log(String sql) { + private void log(String sql) throws SQLException { long m = System.currentTimeMillis() - milli; long n = System.nanoTime() - nano; - JdbcLogger.log(QueryType.UNKNOWN, sql, m, n); + JdbcLogger.log(QueryType.UNKNOWN, sql, m, n, connection.getAutoCommit()); } public void commit() throws SQLException { diff --git a/src/nl/astraeus/jdbc/JdbcLogger.java b/src/nl/astraeus/jdbc/JdbcLogger.java index 2a22033..3019d9b 100644 --- a/src/nl/astraeus/jdbc/JdbcLogger.java +++ b/src/nl/astraeus/jdbc/JdbcLogger.java @@ -29,9 +29,10 @@ private long nano; private int hash; private int count; + private boolean autoCommit; private StackTraceElement[] stackTrace = null; - public LogEntry(int hash, QueryType type, String sql, long milli, long nano) { + public LogEntry(int hash, QueryType type, String sql, long milli, long nano, boolean isAutoCommit) { this.threadId = Thread.currentThread().getId(); this.timeStamp = System.currentTimeMillis(); this.hash = hash; @@ -39,6 +40,7 @@ this.sql = sql; this.milli = milli; this.nano = nano; + this.autoCommit = isAutoCommit; this.count = 1; } @@ -50,6 +52,7 @@ this.milli = le.milli; this.nano = le.nano; this.count = le.count; + this.autoCommit = le.autoCommit; } public QueryType getType() { @@ -101,7 +104,23 @@ } public String getSql() { - return sql; + String tmp = sql.toLowerCase(); + + tmp = tmp.replaceAll("create table ", "CREATE TABLE "); + tmp = tmp.replaceAll("insert into ", "INSERT INTO "); + tmp = tmp.replaceAll("delete from ", "DELETE FROM "); + + tmp = tmp.replaceAll("select ", "SELECT "); + tmp = tmp.replaceAll(" from ", " \nFROM "); + tmp = tmp.replaceAll(" where ", " \nWHERE "); + tmp = tmp.replaceAll(" order by ", " \nORDER BY "); + tmp = tmp.replaceAll(" group by ", " \nGROUP BY "); + tmp = tmp.replaceAll(" having ", " \nHAVING "); + + tmp = tmp.replaceAll("update ", "UPDATE "); + tmp = tmp.replaceAll(" set ", " \nSET "); + + return tmp; } public void addCount(LogEntry le) { @@ -122,6 +141,10 @@ public StackTraceElement[] getStackTrace() { return stackTrace; } + + public boolean isAutoCommit() { + return autoCommit; + } } private final List queries; @@ -155,10 +178,10 @@ this.cacheSize = cacheSize; } - public void logEntry(QueryType type, String sql, long milli, long nano) { + public void logEntry(QueryType type, String sql, long milli, long nano, boolean isAutoCommit) { int hash = sql.hashCode(); - LogEntry entry = new LogEntry(hash, type, sql, milli, nano); + LogEntry entry = new LogEntry(hash, type, sql, milli, nano, isAutoCommit); if (recording) { try { @@ -178,8 +201,8 @@ } } - public static void log(QueryType type, String sql, long milli, long nano) { - instance.logEntry(type, sql, milli, nano); + public static void log(QueryType type, String sql, long milli, long nano, boolean isAutoCommit) { + instance.logEntry(type, sql, milli, nano, isAutoCommit); } public List getEntries() { diff --git a/src/nl/astraeus/jdbc/PreparedStatementLogger.java b/src/nl/astraeus/jdbc/PreparedStatementLogger.java index cc6c2c1..fca3e5c 100644 --- a/src/nl/astraeus/jdbc/PreparedStatementLogger.java +++ b/src/nl/astraeus/jdbc/PreparedStatementLogger.java @@ -38,11 +38,11 @@ nano = System.nanoTime(); } - private void log(QueryType type, String sql) { + private void log(QueryType type, String sql) throws SQLException { long m = System.currentTimeMillis() - milli; long n = System.nanoTime() - nano; - JdbcLogger.log(type, sql, m, n); + JdbcLogger.log(type, sql, m, n, getConnection().getAutoCommit()); } public PreparedStatementLogger(Connection connection, String sql) throws SQLException { diff --git a/src/nl/astraeus/jdbc/StatementLogger.java b/src/nl/astraeus/jdbc/StatementLogger.java index c440e43..d9838e0 100644 --- a/src/nl/astraeus/jdbc/StatementLogger.java +++ b/src/nl/astraeus/jdbc/StatementLogger.java @@ -26,11 +26,11 @@ nano = System.nanoTime(); } - private void log(QueryType type, String sql) { + private void log(QueryType type, String sql) throws SQLException { long m = System.currentTimeMillis() - milli; long n = System.nanoTime() - nano; - JdbcLogger.log(type, sql, m, n); + JdbcLogger.log(type, sql, m, n, getConnection() == null ? true : getConnection().getAutoCommit()); } public ResultSet executeQuery(String sql) throws SQLException { diff --git a/src/nl/astraeus/jdbc/web/JdbcStatisticsServlet.java b/src/nl/astraeus/jdbc/web/JdbcStatisticsServlet.java index 7785ccf..add3005 100644 --- a/src/nl/astraeus/jdbc/web/JdbcStatisticsServlet.java +++ b/src/nl/astraeus/jdbc/web/JdbcStatisticsServlet.java @@ -2,10 +2,7 @@ import nl.astraeus.jdbc.util.IOUtils; import nl.astraeus.jdbc.util.Util; -import nl.astraeus.jdbc.web.page.Menu; -import nl.astraeus.jdbc.web.page.Page; -import nl.astraeus.jdbc.web.page.QueryOverview; -import nl.astraeus.jdbc.web.page.Settings; +import nl.astraeus.jdbc.web.page.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -67,6 +64,8 @@ if (page == null || "menumain".equals(req.getParameter("action"))) { page = new QueryOverview(); + } else if ("menutransactions".equals(req.getParameter("action"))) { + page = new TransactionOverview(); } else if ("menusettings".equals(req.getParameter("action"))) { page = new Settings(); } else if ("diagnostics".equals(req.getParameter("action"))) { diff --git a/src/nl/astraeus/jdbc/ConnectionLogger.java b/src/nl/astraeus/jdbc/ConnectionLogger.java index c359692..0bd1776 100644 --- a/src/nl/astraeus/jdbc/ConnectionLogger.java +++ b/src/nl/astraeus/jdbc/ConnectionLogger.java @@ -27,11 +27,11 @@ nano = System.nanoTime(); } - private void log(String sql) { + private void log(String sql) throws SQLException { long m = System.currentTimeMillis() - milli; long n = System.nanoTime() - nano; - JdbcLogger.log(QueryType.UNKNOWN, sql, m, n); + JdbcLogger.log(QueryType.UNKNOWN, sql, m, n, connection.getAutoCommit()); } public void commit() throws SQLException { diff --git a/src/nl/astraeus/jdbc/JdbcLogger.java b/src/nl/astraeus/jdbc/JdbcLogger.java index 2a22033..3019d9b 100644 --- a/src/nl/astraeus/jdbc/JdbcLogger.java +++ b/src/nl/astraeus/jdbc/JdbcLogger.java @@ -29,9 +29,10 @@ private long nano; private int hash; private int count; + private boolean autoCommit; private StackTraceElement[] stackTrace = null; - public LogEntry(int hash, QueryType type, String sql, long milli, long nano) { + public LogEntry(int hash, QueryType type, String sql, long milli, long nano, boolean isAutoCommit) { this.threadId = Thread.currentThread().getId(); this.timeStamp = System.currentTimeMillis(); this.hash = hash; @@ -39,6 +40,7 @@ this.sql = sql; this.milli = milli; this.nano = nano; + this.autoCommit = isAutoCommit; this.count = 1; } @@ -50,6 +52,7 @@ this.milli = le.milli; this.nano = le.nano; this.count = le.count; + this.autoCommit = le.autoCommit; } public QueryType getType() { @@ -101,7 +104,23 @@ } public String getSql() { - return sql; + String tmp = sql.toLowerCase(); + + tmp = tmp.replaceAll("create table ", "CREATE TABLE "); + tmp = tmp.replaceAll("insert into ", "INSERT INTO "); + tmp = tmp.replaceAll("delete from ", "DELETE FROM "); + + tmp = tmp.replaceAll("select ", "SELECT "); + tmp = tmp.replaceAll(" from ", " \nFROM "); + tmp = tmp.replaceAll(" where ", " \nWHERE "); + tmp = tmp.replaceAll(" order by ", " \nORDER BY "); + tmp = tmp.replaceAll(" group by ", " \nGROUP BY "); + tmp = tmp.replaceAll(" having ", " \nHAVING "); + + tmp = tmp.replaceAll("update ", "UPDATE "); + tmp = tmp.replaceAll(" set ", " \nSET "); + + return tmp; } public void addCount(LogEntry le) { @@ -122,6 +141,10 @@ public StackTraceElement[] getStackTrace() { return stackTrace; } + + public boolean isAutoCommit() { + return autoCommit; + } } private final List queries; @@ -155,10 +178,10 @@ this.cacheSize = cacheSize; } - public void logEntry(QueryType type, String sql, long milli, long nano) { + public void logEntry(QueryType type, String sql, long milli, long nano, boolean isAutoCommit) { int hash = sql.hashCode(); - LogEntry entry = new LogEntry(hash, type, sql, milli, nano); + LogEntry entry = new LogEntry(hash, type, sql, milli, nano, isAutoCommit); if (recording) { try { @@ -178,8 +201,8 @@ } } - public static void log(QueryType type, String sql, long milli, long nano) { - instance.logEntry(type, sql, milli, nano); + public static void log(QueryType type, String sql, long milli, long nano, boolean isAutoCommit) { + instance.logEntry(type, sql, milli, nano, isAutoCommit); } public List getEntries() { diff --git a/src/nl/astraeus/jdbc/PreparedStatementLogger.java b/src/nl/astraeus/jdbc/PreparedStatementLogger.java index cc6c2c1..fca3e5c 100644 --- a/src/nl/astraeus/jdbc/PreparedStatementLogger.java +++ b/src/nl/astraeus/jdbc/PreparedStatementLogger.java @@ -38,11 +38,11 @@ nano = System.nanoTime(); } - private void log(QueryType type, String sql) { + private void log(QueryType type, String sql) throws SQLException { long m = System.currentTimeMillis() - milli; long n = System.nanoTime() - nano; - JdbcLogger.log(type, sql, m, n); + JdbcLogger.log(type, sql, m, n, getConnection().getAutoCommit()); } public PreparedStatementLogger(Connection connection, String sql) throws SQLException { diff --git a/src/nl/astraeus/jdbc/StatementLogger.java b/src/nl/astraeus/jdbc/StatementLogger.java index c440e43..d9838e0 100644 --- a/src/nl/astraeus/jdbc/StatementLogger.java +++ b/src/nl/astraeus/jdbc/StatementLogger.java @@ -26,11 +26,11 @@ nano = System.nanoTime(); } - private void log(QueryType type, String sql) { + private void log(QueryType type, String sql) throws SQLException { long m = System.currentTimeMillis() - milli; long n = System.nanoTime() - nano; - JdbcLogger.log(type, sql, m, n); + JdbcLogger.log(type, sql, m, n, getConnection() == null ? true : getConnection().getAutoCommit()); } public ResultSet executeQuery(String sql) throws SQLException { diff --git a/src/nl/astraeus/jdbc/web/JdbcStatisticsServlet.java b/src/nl/astraeus/jdbc/web/JdbcStatisticsServlet.java index 7785ccf..add3005 100644 --- a/src/nl/astraeus/jdbc/web/JdbcStatisticsServlet.java +++ b/src/nl/astraeus/jdbc/web/JdbcStatisticsServlet.java @@ -2,10 +2,7 @@ import nl.astraeus.jdbc.util.IOUtils; import nl.astraeus.jdbc.util.Util; -import nl.astraeus.jdbc.web.page.Menu; -import nl.astraeus.jdbc.web.page.Page; -import nl.astraeus.jdbc.web.page.QueryOverview; -import nl.astraeus.jdbc.web.page.Settings; +import nl.astraeus.jdbc.web.page.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -67,6 +64,8 @@ if (page == null || "menumain".equals(req.getParameter("action"))) { page = new QueryOverview(); + } else if ("menutransactions".equals(req.getParameter("action"))) { + page = new TransactionOverview(); } else if ("menusettings".equals(req.getParameter("action"))) { page = new Settings(); } else if ("diagnostics".equals(req.getParameter("action"))) { diff --git a/src/nl/astraeus/jdbc/web/page/Menu.html b/src/nl/astraeus/jdbc/web/page/Menu.html index 1935d6f..99cb516 100644 --- a/src/nl/astraeus/jdbc/web/page/Menu.html +++ b/src/nl/astraeus/jdbc/web/page/Menu.html @@ -9,7 +9,10 @@ Simple JDBC Statistics
+ {escapehtml(html|br)}

{sql}

+ {escapeend}
diff --git a/src/nl/astraeus/jdbc/ConnectionLogger.java b/src/nl/astraeus/jdbc/ConnectionLogger.java index c359692..0bd1776 100644 --- a/src/nl/astraeus/jdbc/ConnectionLogger.java +++ b/src/nl/astraeus/jdbc/ConnectionLogger.java @@ -27,11 +27,11 @@ nano = System.nanoTime(); } - private void log(String sql) { + private void log(String sql) throws SQLException { long m = System.currentTimeMillis() - milli; long n = System.nanoTime() - nano; - JdbcLogger.log(QueryType.UNKNOWN, sql, m, n); + JdbcLogger.log(QueryType.UNKNOWN, sql, m, n, connection.getAutoCommit()); } public void commit() throws SQLException { diff --git a/src/nl/astraeus/jdbc/JdbcLogger.java b/src/nl/astraeus/jdbc/JdbcLogger.java index 2a22033..3019d9b 100644 --- a/src/nl/astraeus/jdbc/JdbcLogger.java +++ b/src/nl/astraeus/jdbc/JdbcLogger.java @@ -29,9 +29,10 @@ private long nano; private int hash; private int count; + private boolean autoCommit; private StackTraceElement[] stackTrace = null; - public LogEntry(int hash, QueryType type, String sql, long milli, long nano) { + public LogEntry(int hash, QueryType type, String sql, long milli, long nano, boolean isAutoCommit) { this.threadId = Thread.currentThread().getId(); this.timeStamp = System.currentTimeMillis(); this.hash = hash; @@ -39,6 +40,7 @@ this.sql = sql; this.milli = milli; this.nano = nano; + this.autoCommit = isAutoCommit; this.count = 1; } @@ -50,6 +52,7 @@ this.milli = le.milli; this.nano = le.nano; this.count = le.count; + this.autoCommit = le.autoCommit; } public QueryType getType() { @@ -101,7 +104,23 @@ } public String getSql() { - return sql; + String tmp = sql.toLowerCase(); + + tmp = tmp.replaceAll("create table ", "CREATE TABLE "); + tmp = tmp.replaceAll("insert into ", "INSERT INTO "); + tmp = tmp.replaceAll("delete from ", "DELETE FROM "); + + tmp = tmp.replaceAll("select ", "SELECT "); + tmp = tmp.replaceAll(" from ", " \nFROM "); + tmp = tmp.replaceAll(" where ", " \nWHERE "); + tmp = tmp.replaceAll(" order by ", " \nORDER BY "); + tmp = tmp.replaceAll(" group by ", " \nGROUP BY "); + tmp = tmp.replaceAll(" having ", " \nHAVING "); + + tmp = tmp.replaceAll("update ", "UPDATE "); + tmp = tmp.replaceAll(" set ", " \nSET "); + + return tmp; } public void addCount(LogEntry le) { @@ -122,6 +141,10 @@ public StackTraceElement[] getStackTrace() { return stackTrace; } + + public boolean isAutoCommit() { + return autoCommit; + } } private final List queries; @@ -155,10 +178,10 @@ this.cacheSize = cacheSize; } - public void logEntry(QueryType type, String sql, long milli, long nano) { + public void logEntry(QueryType type, String sql, long milli, long nano, boolean isAutoCommit) { int hash = sql.hashCode(); - LogEntry entry = new LogEntry(hash, type, sql, milli, nano); + LogEntry entry = new LogEntry(hash, type, sql, milli, nano, isAutoCommit); if (recording) { try { @@ -178,8 +201,8 @@ } } - public static void log(QueryType type, String sql, long milli, long nano) { - instance.logEntry(type, sql, milli, nano); + public static void log(QueryType type, String sql, long milli, long nano, boolean isAutoCommit) { + instance.logEntry(type, sql, milli, nano, isAutoCommit); } public List getEntries() { diff --git a/src/nl/astraeus/jdbc/PreparedStatementLogger.java b/src/nl/astraeus/jdbc/PreparedStatementLogger.java index cc6c2c1..fca3e5c 100644 --- a/src/nl/astraeus/jdbc/PreparedStatementLogger.java +++ b/src/nl/astraeus/jdbc/PreparedStatementLogger.java @@ -38,11 +38,11 @@ nano = System.nanoTime(); } - private void log(QueryType type, String sql) { + private void log(QueryType type, String sql) throws SQLException { long m = System.currentTimeMillis() - milli; long n = System.nanoTime() - nano; - JdbcLogger.log(type, sql, m, n); + JdbcLogger.log(type, sql, m, n, getConnection().getAutoCommit()); } public PreparedStatementLogger(Connection connection, String sql) throws SQLException { diff --git a/src/nl/astraeus/jdbc/StatementLogger.java b/src/nl/astraeus/jdbc/StatementLogger.java index c440e43..d9838e0 100644 --- a/src/nl/astraeus/jdbc/StatementLogger.java +++ b/src/nl/astraeus/jdbc/StatementLogger.java @@ -26,11 +26,11 @@ nano = System.nanoTime(); } - private void log(QueryType type, String sql) { + private void log(QueryType type, String sql) throws SQLException { long m = System.currentTimeMillis() - milli; long n = System.nanoTime() - nano; - JdbcLogger.log(type, sql, m, n); + JdbcLogger.log(type, sql, m, n, getConnection() == null ? true : getConnection().getAutoCommit()); } public ResultSet executeQuery(String sql) throws SQLException { diff --git a/src/nl/astraeus/jdbc/web/JdbcStatisticsServlet.java b/src/nl/astraeus/jdbc/web/JdbcStatisticsServlet.java index 7785ccf..add3005 100644 --- a/src/nl/astraeus/jdbc/web/JdbcStatisticsServlet.java +++ b/src/nl/astraeus/jdbc/web/JdbcStatisticsServlet.java @@ -2,10 +2,7 @@ import nl.astraeus.jdbc.util.IOUtils; import nl.astraeus.jdbc.util.Util; -import nl.astraeus.jdbc.web.page.Menu; -import nl.astraeus.jdbc.web.page.Page; -import nl.astraeus.jdbc.web.page.QueryOverview; -import nl.astraeus.jdbc.web.page.Settings; +import nl.astraeus.jdbc.web.page.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -67,6 +64,8 @@ if (page == null || "menumain".equals(req.getParameter("action"))) { page = new QueryOverview(); + } else if ("menutransactions".equals(req.getParameter("action"))) { + page = new TransactionOverview(); } else if ("menusettings".equals(req.getParameter("action"))) { page = new Settings(); } else if ("diagnostics".equals(req.getParameter("action"))) { diff --git a/src/nl/astraeus/jdbc/web/page/Menu.html b/src/nl/astraeus/jdbc/web/page/Menu.html index 1935d6f..99cb516 100644 --- a/src/nl/astraeus/jdbc/web/page/Menu.html +++ b/src/nl/astraeus/jdbc/web/page/Menu.html @@ -9,7 +9,10 @@ Simple JDBC Statistics
+ {escape(html|br)}

{sql}

+ {escapeend}
+ {escape(html|br)} + {escapeend} {eachend} diff --git a/src/nl/astraeus/jdbc/web/page/ShowStacktrace.html b/src/nl/astraeus/jdbc/web/page/ShowStacktrace.html index 7d4b983..5273c19 100644 --- a/src/nl/astraeus/jdbc/web/page/ShowStacktrace.html +++ b/src/nl/astraeus/jdbc/web/page/ShowStacktrace.html @@ -9,7 +9,9 @@
+ {escapehtml(html|br)}

{sql}

+ {escapeend}
{q.total} {q.formattedNano} {q.count}{q.sql}
diff --git a/src/nl/astraeus/jdbc/web/page/TransactionOverview.html b/src/nl/astraeus/jdbc/web/page/TransactionOverview.html new file mode 100644 index 0000000..e9fdc81 --- /dev/null +++ b/src/nl/astraeus/jdbc/web/page/TransactionOverview.html @@ -0,0 +1,53 @@ + + +
+
+ +
# Queries: {count}
+
Time span: {deltaTime} ({fromTime} - {toTime})
+
Avg. time/query: {avgTime}
+
+ +
+ Clear +
+
+ + + +
+ + + + + + + + + + + {foreach(transactions as t)} + + + + + + {escape(html|br)} + + {escapeend} + + {eachend} + +
Total time (ms)Avg. time (ms)# CallsSql
{t.totalTime}{t.avgTime}{t.count}{t.sql}
diff --git a/src/nl/astraeus/jdbc/ConnectionLogger.java b/src/nl/astraeus/jdbc/ConnectionLogger.java index c359692..0bd1776 100644 --- a/src/nl/astraeus/jdbc/ConnectionLogger.java +++ b/src/nl/astraeus/jdbc/ConnectionLogger.java @@ -27,11 +27,11 @@ nano = System.nanoTime(); } - private void log(String sql) { + private void log(String sql) throws SQLException { long m = System.currentTimeMillis() - milli; long n = System.nanoTime() - nano; - JdbcLogger.log(QueryType.UNKNOWN, sql, m, n); + JdbcLogger.log(QueryType.UNKNOWN, sql, m, n, connection.getAutoCommit()); } public void commit() throws SQLException { diff --git a/src/nl/astraeus/jdbc/JdbcLogger.java b/src/nl/astraeus/jdbc/JdbcLogger.java index 2a22033..3019d9b 100644 --- a/src/nl/astraeus/jdbc/JdbcLogger.java +++ b/src/nl/astraeus/jdbc/JdbcLogger.java @@ -29,9 +29,10 @@ private long nano; private int hash; private int count; + private boolean autoCommit; private StackTraceElement[] stackTrace = null; - public LogEntry(int hash, QueryType type, String sql, long milli, long nano) { + public LogEntry(int hash, QueryType type, String sql, long milli, long nano, boolean isAutoCommit) { this.threadId = Thread.currentThread().getId(); this.timeStamp = System.currentTimeMillis(); this.hash = hash; @@ -39,6 +40,7 @@ this.sql = sql; this.milli = milli; this.nano = nano; + this.autoCommit = isAutoCommit; this.count = 1; } @@ -50,6 +52,7 @@ this.milli = le.milli; this.nano = le.nano; this.count = le.count; + this.autoCommit = le.autoCommit; } public QueryType getType() { @@ -101,7 +104,23 @@ } public String getSql() { - return sql; + String tmp = sql.toLowerCase(); + + tmp = tmp.replaceAll("create table ", "CREATE TABLE "); + tmp = tmp.replaceAll("insert into ", "INSERT INTO "); + tmp = tmp.replaceAll("delete from ", "DELETE FROM "); + + tmp = tmp.replaceAll("select ", "SELECT "); + tmp = tmp.replaceAll(" from ", " \nFROM "); + tmp = tmp.replaceAll(" where ", " \nWHERE "); + tmp = tmp.replaceAll(" order by ", " \nORDER BY "); + tmp = tmp.replaceAll(" group by ", " \nGROUP BY "); + tmp = tmp.replaceAll(" having ", " \nHAVING "); + + tmp = tmp.replaceAll("update ", "UPDATE "); + tmp = tmp.replaceAll(" set ", " \nSET "); + + return tmp; } public void addCount(LogEntry le) { @@ -122,6 +141,10 @@ public StackTraceElement[] getStackTrace() { return stackTrace; } + + public boolean isAutoCommit() { + return autoCommit; + } } private final List queries; @@ -155,10 +178,10 @@ this.cacheSize = cacheSize; } - public void logEntry(QueryType type, String sql, long milli, long nano) { + public void logEntry(QueryType type, String sql, long milli, long nano, boolean isAutoCommit) { int hash = sql.hashCode(); - LogEntry entry = new LogEntry(hash, type, sql, milli, nano); + LogEntry entry = new LogEntry(hash, type, sql, milli, nano, isAutoCommit); if (recording) { try { @@ -178,8 +201,8 @@ } } - public static void log(QueryType type, String sql, long milli, long nano) { - instance.logEntry(type, sql, milli, nano); + public static void log(QueryType type, String sql, long milli, long nano, boolean isAutoCommit) { + instance.logEntry(type, sql, milli, nano, isAutoCommit); } public List getEntries() { diff --git a/src/nl/astraeus/jdbc/PreparedStatementLogger.java b/src/nl/astraeus/jdbc/PreparedStatementLogger.java index cc6c2c1..fca3e5c 100644 --- a/src/nl/astraeus/jdbc/PreparedStatementLogger.java +++ b/src/nl/astraeus/jdbc/PreparedStatementLogger.java @@ -38,11 +38,11 @@ nano = System.nanoTime(); } - private void log(QueryType type, String sql) { + private void log(QueryType type, String sql) throws SQLException { long m = System.currentTimeMillis() - milli; long n = System.nanoTime() - nano; - JdbcLogger.log(type, sql, m, n); + JdbcLogger.log(type, sql, m, n, getConnection().getAutoCommit()); } public PreparedStatementLogger(Connection connection, String sql) throws SQLException { diff --git a/src/nl/astraeus/jdbc/StatementLogger.java b/src/nl/astraeus/jdbc/StatementLogger.java index c440e43..d9838e0 100644 --- a/src/nl/astraeus/jdbc/StatementLogger.java +++ b/src/nl/astraeus/jdbc/StatementLogger.java @@ -26,11 +26,11 @@ nano = System.nanoTime(); } - private void log(QueryType type, String sql) { + private void log(QueryType type, String sql) throws SQLException { long m = System.currentTimeMillis() - milli; long n = System.nanoTime() - nano; - JdbcLogger.log(type, sql, m, n); + JdbcLogger.log(type, sql, m, n, getConnection() == null ? true : getConnection().getAutoCommit()); } public ResultSet executeQuery(String sql) throws SQLException { diff --git a/src/nl/astraeus/jdbc/web/JdbcStatisticsServlet.java b/src/nl/astraeus/jdbc/web/JdbcStatisticsServlet.java index 7785ccf..add3005 100644 --- a/src/nl/astraeus/jdbc/web/JdbcStatisticsServlet.java +++ b/src/nl/astraeus/jdbc/web/JdbcStatisticsServlet.java @@ -2,10 +2,7 @@ import nl.astraeus.jdbc.util.IOUtils; import nl.astraeus.jdbc.util.Util; -import nl.astraeus.jdbc.web.page.Menu; -import nl.astraeus.jdbc.web.page.Page; -import nl.astraeus.jdbc.web.page.QueryOverview; -import nl.astraeus.jdbc.web.page.Settings; +import nl.astraeus.jdbc.web.page.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -67,6 +64,8 @@ if (page == null || "menumain".equals(req.getParameter("action"))) { page = new QueryOverview(); + } else if ("menutransactions".equals(req.getParameter("action"))) { + page = new TransactionOverview(); } else if ("menusettings".equals(req.getParameter("action"))) { page = new Settings(); } else if ("diagnostics".equals(req.getParameter("action"))) { diff --git a/src/nl/astraeus/jdbc/web/page/Menu.html b/src/nl/astraeus/jdbc/web/page/Menu.html index 1935d6f..99cb516 100644 --- a/src/nl/astraeus/jdbc/web/page/Menu.html +++ b/src/nl/astraeus/jdbc/web/page/Menu.html @@ -9,7 +9,10 @@ Simple JDBC Statistics
+ {escape(html|br)}

{sql}

+ {escapeend}