diff --git a/.idea/checkstyle-idea.xml b/.idea/checkstyle-idea.xml new file mode 100644 index 0000000..b6e4700 --- /dev/null +++ b/.idea/checkstyle-idea.xml @@ -0,0 +1,16 @@ + + + + + + \ No newline at end of file diff --git a/.idea/checkstyle-idea.xml b/.idea/checkstyle-idea.xml new file mode 100644 index 0000000..b6e4700 --- /dev/null +++ b/.idea/checkstyle-idea.xml @@ -0,0 +1,16 @@ + + + + + + \ No newline at end of file diff --git a/.idea/hotswap_agent.xml b/.idea/hotswap_agent.xml new file mode 100644 index 0000000..8a869d9 --- /dev/null +++ b/.idea/hotswap_agent.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/checkstyle-idea.xml b/.idea/checkstyle-idea.xml new file mode 100644 index 0000000..b6e4700 --- /dev/null +++ b/.idea/checkstyle-idea.xml @@ -0,0 +1,16 @@ + + + + + + \ No newline at end of file diff --git a/.idea/hotswap_agent.xml b/.idea/hotswap_agent.xml new file mode 100644 index 0000000..8a869d9 --- /dev/null +++ b/.idea/hotswap_agent.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/libraries/lib1.xml b/.idea/libraries/lib1.xml index 8ce9ba1..7a6f4d3 100644 --- a/.idea/libraries/lib1.xml +++ b/.idea/libraries/lib1.xml @@ -2,7 +2,6 @@ - diff --git a/.idea/checkstyle-idea.xml b/.idea/checkstyle-idea.xml new file mode 100644 index 0000000..b6e4700 --- /dev/null +++ b/.idea/checkstyle-idea.xml @@ -0,0 +1,16 @@ + + + + + + \ No newline at end of file diff --git a/.idea/hotswap_agent.xml b/.idea/hotswap_agent.xml new file mode 100644 index 0000000..8a869d9 --- /dev/null +++ b/.idea/hotswap_agent.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/libraries/lib1.xml b/.idea/libraries/lib1.xml index 8ce9ba1..7a6f4d3 100644 --- a/.idea/libraries/lib1.xml +++ b/.idea/libraries/lib1.xml @@ -2,7 +2,6 @@ - diff --git a/.idea/modules/simple-jdbc-stats.iml b/.idea/modules/simple-jdbc-stats.iml index f17a5e9..ba2f28c 100644 --- a/.idea/modules/simple-jdbc-stats.iml +++ b/.idea/modules/simple-jdbc-stats.iml @@ -1,5 +1,5 @@ - + diff --git a/.idea/checkstyle-idea.xml b/.idea/checkstyle-idea.xml new file mode 100644 index 0000000..b6e4700 --- /dev/null +++ b/.idea/checkstyle-idea.xml @@ -0,0 +1,16 @@ + + + + + + \ No newline at end of file diff --git a/.idea/hotswap_agent.xml b/.idea/hotswap_agent.xml new file mode 100644 index 0000000..8a869d9 --- /dev/null +++ b/.idea/hotswap_agent.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/libraries/lib1.xml b/.idea/libraries/lib1.xml index 8ce9ba1..7a6f4d3 100644 --- a/.idea/libraries/lib1.xml +++ b/.idea/libraries/lib1.xml @@ -2,7 +2,6 @@ - diff --git a/.idea/modules/simple-jdbc-stats.iml b/.idea/modules/simple-jdbc-stats.iml index f17a5e9..ba2f28c 100644 --- a/.idea/modules/simple-jdbc-stats.iml +++ b/.idea/modules/simple-jdbc-stats.iml @@ -1,5 +1,5 @@ - + diff --git a/.idea/modules/simple-jdbc-stats_main.iml b/.idea/modules/simple-jdbc-stats_main.iml index 573880c..c646a2e 100644 --- a/.idea/modules/simple-jdbc-stats_main.iml +++ b/.idea/modules/simple-jdbc-stats_main.iml @@ -1,7 +1,7 @@ - + - + diff --git a/.idea/checkstyle-idea.xml b/.idea/checkstyle-idea.xml new file mode 100644 index 0000000..b6e4700 --- /dev/null +++ b/.idea/checkstyle-idea.xml @@ -0,0 +1,16 @@ + + + + + + \ No newline at end of file diff --git a/.idea/hotswap_agent.xml b/.idea/hotswap_agent.xml new file mode 100644 index 0000000..8a869d9 --- /dev/null +++ b/.idea/hotswap_agent.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/libraries/lib1.xml b/.idea/libraries/lib1.xml index 8ce9ba1..7a6f4d3 100644 --- a/.idea/libraries/lib1.xml +++ b/.idea/libraries/lib1.xml @@ -2,7 +2,6 @@ - diff --git a/.idea/modules/simple-jdbc-stats.iml b/.idea/modules/simple-jdbc-stats.iml index f17a5e9..ba2f28c 100644 --- a/.idea/modules/simple-jdbc-stats.iml +++ b/.idea/modules/simple-jdbc-stats.iml @@ -1,5 +1,5 @@ - + diff --git a/.idea/modules/simple-jdbc-stats_main.iml b/.idea/modules/simple-jdbc-stats_main.iml index 573880c..c646a2e 100644 --- a/.idea/modules/simple-jdbc-stats_main.iml +++ b/.idea/modules/simple-jdbc-stats_main.iml @@ -1,7 +1,7 @@ - + - + diff --git a/.idea/modules/simple-jdbc-stats_test.iml b/.idea/modules/simple-jdbc-stats_test.iml index 2e21d25..bac5915 100644 --- a/.idea/modules/simple-jdbc-stats_test.iml +++ b/.idea/modules/simple-jdbc-stats_test.iml @@ -1,7 +1,7 @@ - + - + diff --git a/.idea/checkstyle-idea.xml b/.idea/checkstyle-idea.xml new file mode 100644 index 0000000..b6e4700 --- /dev/null +++ b/.idea/checkstyle-idea.xml @@ -0,0 +1,16 @@ + + + + + + \ No newline at end of file diff --git a/.idea/hotswap_agent.xml b/.idea/hotswap_agent.xml new file mode 100644 index 0000000..8a869d9 --- /dev/null +++ b/.idea/hotswap_agent.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/libraries/lib1.xml b/.idea/libraries/lib1.xml index 8ce9ba1..7a6f4d3 100644 --- a/.idea/libraries/lib1.xml +++ b/.idea/libraries/lib1.xml @@ -2,7 +2,6 @@ - diff --git a/.idea/modules/simple-jdbc-stats.iml b/.idea/modules/simple-jdbc-stats.iml index f17a5e9..ba2f28c 100644 --- a/.idea/modules/simple-jdbc-stats.iml +++ b/.idea/modules/simple-jdbc-stats.iml @@ -1,5 +1,5 @@ - + diff --git a/.idea/modules/simple-jdbc-stats_main.iml b/.idea/modules/simple-jdbc-stats_main.iml index 573880c..c646a2e 100644 --- a/.idea/modules/simple-jdbc-stats_main.iml +++ b/.idea/modules/simple-jdbc-stats_main.iml @@ -1,7 +1,7 @@ - + - + diff --git a/.idea/modules/simple-jdbc-stats_test.iml b/.idea/modules/simple-jdbc-stats_test.iml index 2e21d25..bac5915 100644 --- a/.idea/modules/simple-jdbc-stats_test.iml +++ b/.idea/modules/simple-jdbc-stats_test.iml @@ -1,7 +1,7 @@ - + - + diff --git a/build.gradle b/build.gradle index 04938e8..69bad54 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ group 'nl.astraeus' -version '1.5.10-SNAPSHOT' +version '1.6.0' apply plugin: 'java' apply plugin: 'idea' diff --git a/.idea/checkstyle-idea.xml b/.idea/checkstyle-idea.xml new file mode 100644 index 0000000..b6e4700 --- /dev/null +++ b/.idea/checkstyle-idea.xml @@ -0,0 +1,16 @@ + + + + + + \ No newline at end of file diff --git a/.idea/hotswap_agent.xml b/.idea/hotswap_agent.xml new file mode 100644 index 0000000..8a869d9 --- /dev/null +++ b/.idea/hotswap_agent.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/libraries/lib1.xml b/.idea/libraries/lib1.xml index 8ce9ba1..7a6f4d3 100644 --- a/.idea/libraries/lib1.xml +++ b/.idea/libraries/lib1.xml @@ -2,7 +2,6 @@ - diff --git a/.idea/modules/simple-jdbc-stats.iml b/.idea/modules/simple-jdbc-stats.iml index f17a5e9..ba2f28c 100644 --- a/.idea/modules/simple-jdbc-stats.iml +++ b/.idea/modules/simple-jdbc-stats.iml @@ -1,5 +1,5 @@ - + diff --git a/.idea/modules/simple-jdbc-stats_main.iml b/.idea/modules/simple-jdbc-stats_main.iml index 573880c..c646a2e 100644 --- a/.idea/modules/simple-jdbc-stats_main.iml +++ b/.idea/modules/simple-jdbc-stats_main.iml @@ -1,7 +1,7 @@ - + - + diff --git a/.idea/modules/simple-jdbc-stats_test.iml b/.idea/modules/simple-jdbc-stats_test.iml index 2e21d25..bac5915 100644 --- a/.idea/modules/simple-jdbc-stats_test.iml +++ b/.idea/modules/simple-jdbc-stats_test.iml @@ -1,7 +1,7 @@ - + - + diff --git a/build.gradle b/build.gradle index 04938e8..69bad54 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ group 'nl.astraeus' -version '1.5.10-SNAPSHOT' +version '1.6.0' apply plugin: 'java' apply plugin: 'idea' diff --git a/src/nl/astraeus/jdbc/JdbcLogger.java b/src/nl/astraeus/jdbc/JdbcLogger.java index 737e1ec..67661df 100644 --- a/src/nl/astraeus/jdbc/JdbcLogger.java +++ b/src/nl/astraeus/jdbc/JdbcLogger.java @@ -1,15 +1,16 @@ package nl.astraeus.jdbc; +import nl.astraeus.jdbc.util.Util; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.HashSet; import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.concurrent.ConcurrentHashMap; -import nl.astraeus.jdbc.util.Util; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - /** * User: riennentjes * Date: Jul 12, 2008 @@ -44,8 +45,18 @@ private boolean autoCommit; private boolean formattedQueries; private StackTraceElement[] stackTrace = null; + private Set parameters = new HashSet(); - public LogEntry(int hash, QueryType type, String sql, long milli, long nano, boolean isAutoCommit, boolean formattedQueries) { + public LogEntry( + int hash, + QueryType type, + String sql, + long milli, + long nano, + boolean isAutoCommit, + boolean formattedQueries, + Set parameters + ) { this.threadId = Thread.currentThread().getId(); this.timeStamp = System.currentTimeMillis(); this.nanoTimeStamp = System.nanoTime(); @@ -57,6 +68,7 @@ this.autoCommit = isAutoCommit; this.count = 1; this.formattedQueries = formattedQueries; + this.parameters = parameters; } public LogEntry(LogEntry le) { @@ -64,12 +76,13 @@ this.nanoTimeStamp = System.nanoTime(); this.hash = le.hash; this.type = le.type; - this.sql = le .sql; + this.sql = le.sql; this.milli = le.milli; this.nano = le.nano; this.count = le.count; this.autoCommit = le.autoCommit; this.formattedQueries = le.formattedQueries; + this.parameters = le.parameters; } public QueryType getType() { @@ -113,11 +126,11 @@ } public String getFormattedMilli() { - return Util.formatNano(milli*1000000/count); + return Util.formatNano(milli * 1000000 / count); } public String getFormattedNano() { - return Util.formatNano(nano/count); + return Util.formatNano(nano / count); } public String getTotal() { @@ -132,6 +145,23 @@ } } + public String getParameters() { + StringBuilder result = new StringBuilder(); + + if (parameters != null && !parameters.isEmpty()) { + for (Parameter parameter : parameters) { + result.append(String.format( + "%4s, %12s, %24s\n", + parameter.getIndex(), + parameter.getType(), + parameter.getDisplayValue() + )); + } + } + + return result.toString(); + } + public boolean isEndOfTransaction() { return sql.toLowerCase().trim().equals("commit") || sql.toLowerCase().trim().equals("rollback") @@ -181,11 +211,37 @@ last100.clear(); } - public void logEntry(QueryType type, String sql, long milli, long nano, boolean isAutoCommit) { + public void logEntry( + QueryType type, + String sql, + long milli, + long nano, + boolean isAutoCommit + ) { + logEntry(type, sql, milli, nano, isAutoCommit, new HashSet()); + } + + public void logEntry( + QueryType type, + String sql, + long milli, + long nano, + boolean isAutoCommit, + Set parameters + ) { int hash = sql.hashCode(); Driver.StatsLogger logger = Driver.get(port); - LogEntry entry = new LogEntry(hash, type, sql, milli, nano, isAutoCommit, logger.getSettings().isFormattedQueries()); + LogEntry entry = new LogEntry( + hash, + type, + sql, + milli, + nano, + isAutoCommit, + logger.getSettings().isFormattedQueries(), + parameters + ); if (logger.getSettings().isRecordingStacktraces()) { try { diff --git a/.idea/checkstyle-idea.xml b/.idea/checkstyle-idea.xml new file mode 100644 index 0000000..b6e4700 --- /dev/null +++ b/.idea/checkstyle-idea.xml @@ -0,0 +1,16 @@ + + + + + + \ No newline at end of file diff --git a/.idea/hotswap_agent.xml b/.idea/hotswap_agent.xml new file mode 100644 index 0000000..8a869d9 --- /dev/null +++ b/.idea/hotswap_agent.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/libraries/lib1.xml b/.idea/libraries/lib1.xml index 8ce9ba1..7a6f4d3 100644 --- a/.idea/libraries/lib1.xml +++ b/.idea/libraries/lib1.xml @@ -2,7 +2,6 @@ - diff --git a/.idea/modules/simple-jdbc-stats.iml b/.idea/modules/simple-jdbc-stats.iml index f17a5e9..ba2f28c 100644 --- a/.idea/modules/simple-jdbc-stats.iml +++ b/.idea/modules/simple-jdbc-stats.iml @@ -1,5 +1,5 @@ - + diff --git a/.idea/modules/simple-jdbc-stats_main.iml b/.idea/modules/simple-jdbc-stats_main.iml index 573880c..c646a2e 100644 --- a/.idea/modules/simple-jdbc-stats_main.iml +++ b/.idea/modules/simple-jdbc-stats_main.iml @@ -1,7 +1,7 @@ - + - + diff --git a/.idea/modules/simple-jdbc-stats_test.iml b/.idea/modules/simple-jdbc-stats_test.iml index 2e21d25..bac5915 100644 --- a/.idea/modules/simple-jdbc-stats_test.iml +++ b/.idea/modules/simple-jdbc-stats_test.iml @@ -1,7 +1,7 @@ - + - + diff --git a/build.gradle b/build.gradle index 04938e8..69bad54 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ group 'nl.astraeus' -version '1.5.10-SNAPSHOT' +version '1.6.0' apply plugin: 'java' apply plugin: 'idea' diff --git a/src/nl/astraeus/jdbc/JdbcLogger.java b/src/nl/astraeus/jdbc/JdbcLogger.java index 737e1ec..67661df 100644 --- a/src/nl/astraeus/jdbc/JdbcLogger.java +++ b/src/nl/astraeus/jdbc/JdbcLogger.java @@ -1,15 +1,16 @@ package nl.astraeus.jdbc; +import nl.astraeus.jdbc.util.Util; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.HashSet; import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.concurrent.ConcurrentHashMap; -import nl.astraeus.jdbc.util.Util; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - /** * User: riennentjes * Date: Jul 12, 2008 @@ -44,8 +45,18 @@ private boolean autoCommit; private boolean formattedQueries; private StackTraceElement[] stackTrace = null; + private Set parameters = new HashSet(); - public LogEntry(int hash, QueryType type, String sql, long milli, long nano, boolean isAutoCommit, boolean formattedQueries) { + public LogEntry( + int hash, + QueryType type, + String sql, + long milli, + long nano, + boolean isAutoCommit, + boolean formattedQueries, + Set parameters + ) { this.threadId = Thread.currentThread().getId(); this.timeStamp = System.currentTimeMillis(); this.nanoTimeStamp = System.nanoTime(); @@ -57,6 +68,7 @@ this.autoCommit = isAutoCommit; this.count = 1; this.formattedQueries = formattedQueries; + this.parameters = parameters; } public LogEntry(LogEntry le) { @@ -64,12 +76,13 @@ this.nanoTimeStamp = System.nanoTime(); this.hash = le.hash; this.type = le.type; - this.sql = le .sql; + this.sql = le.sql; this.milli = le.milli; this.nano = le.nano; this.count = le.count; this.autoCommit = le.autoCommit; this.formattedQueries = le.formattedQueries; + this.parameters = le.parameters; } public QueryType getType() { @@ -113,11 +126,11 @@ } public String getFormattedMilli() { - return Util.formatNano(milli*1000000/count); + return Util.formatNano(milli * 1000000 / count); } public String getFormattedNano() { - return Util.formatNano(nano/count); + return Util.formatNano(nano / count); } public String getTotal() { @@ -132,6 +145,23 @@ } } + public String getParameters() { + StringBuilder result = new StringBuilder(); + + if (parameters != null && !parameters.isEmpty()) { + for (Parameter parameter : parameters) { + result.append(String.format( + "%4s, %12s, %24s\n", + parameter.getIndex(), + parameter.getType(), + parameter.getDisplayValue() + )); + } + } + + return result.toString(); + } + public boolean isEndOfTransaction() { return sql.toLowerCase().trim().equals("commit") || sql.toLowerCase().trim().equals("rollback") @@ -181,11 +211,37 @@ last100.clear(); } - public void logEntry(QueryType type, String sql, long milli, long nano, boolean isAutoCommit) { + public void logEntry( + QueryType type, + String sql, + long milli, + long nano, + boolean isAutoCommit + ) { + logEntry(type, sql, milli, nano, isAutoCommit, new HashSet()); + } + + public void logEntry( + QueryType type, + String sql, + long milli, + long nano, + boolean isAutoCommit, + Set parameters + ) { int hash = sql.hashCode(); Driver.StatsLogger logger = Driver.get(port); - LogEntry entry = new LogEntry(hash, type, sql, milli, nano, isAutoCommit, logger.getSettings().isFormattedQueries()); + LogEntry entry = new LogEntry( + hash, + type, + sql, + milli, + nano, + isAutoCommit, + logger.getSettings().isFormattedQueries(), + parameters + ); if (logger.getSettings().isRecordingStacktraces()) { try { diff --git a/src/nl/astraeus/jdbc/Parameter.java b/src/nl/astraeus/jdbc/Parameter.java new file mode 100644 index 0000000..8fed9f5 --- /dev/null +++ b/src/nl/astraeus/jdbc/Parameter.java @@ -0,0 +1,118 @@ +package nl.astraeus.jdbc; + +/** + * User: rnentjes + * Date: 26-1-18 + * Time: 11:08 + */ +public class Parameter { + + public interface DisplayFunction { + String display(Object o); + } + + private static DisplayFunction valueOf = new DisplayFunction() { + public String display(Object o) { + return String.valueOf(o); + } + }; + + private static DisplayFunction label(final String label) { + return new DisplayFunction() { + public String display(Object o) { + return label; + } + }; + } + + public enum ParameterType { + NULL(new DisplayFunction() { + public String display(Object o) { + return "NULL"; + } + }), + BOOLEAN(valueOf), + INT(valueOf), + LONG(valueOf), + STRING(new DisplayFunction() { + public String display(Object o) { + return (String)o; + } + }), + BLOB(valueOf), + CLOB(valueOf), + BYTE(valueOf), + SHORT(valueOf), + FLOAT(valueOf), + DOUBLE(valueOf), + BIG_DECIMAL(valueOf), + BYTES(new DisplayFunction() { + public String display(Object o) { + return "byte["+((byte[])o).length+"]"; + } + }), + DATE(valueOf), + TIME(valueOf), + TIMESTAMP(valueOf), + ASCII_STR(label("")), + UNICODE_STR(label("")), + BIN_STR(label("")), + OBJECT(valueOf), + CHAR_STR(label("")), + REF(valueOf), + ARRAY(valueOf), + URL(valueOf), + ROW_ID(valueOf), + NSTRING(valueOf), + NCHAR_STR(label("")), + NCLOB(label("")), + SQLXML(label("")); + + private DisplayFunction display; + + ParameterType(DisplayFunction display) { + this.display = display; + } + + public String toString(Object o) { + return display.display(o); + } + } + + private int index; + private ParameterType type; + private Object value; + + public Parameter( + int index, + ParameterType type + ) { + this(index, type, null); + } + + public Parameter( + int index, + ParameterType type, + Object value + ) { + this.index = index; + this.type = type; + this.value = value; + } + + public int getIndex() { + return index; + } + + public ParameterType getType() { + return type; + } + + public Object getValue() { + return value; + } + + public String getDisplayValue() { + return type.display.display(value); + } +} diff --git a/.idea/checkstyle-idea.xml b/.idea/checkstyle-idea.xml new file mode 100644 index 0000000..b6e4700 --- /dev/null +++ b/.idea/checkstyle-idea.xml @@ -0,0 +1,16 @@ + + + + + + \ No newline at end of file diff --git a/.idea/hotswap_agent.xml b/.idea/hotswap_agent.xml new file mode 100644 index 0000000..8a869d9 --- /dev/null +++ b/.idea/hotswap_agent.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/libraries/lib1.xml b/.idea/libraries/lib1.xml index 8ce9ba1..7a6f4d3 100644 --- a/.idea/libraries/lib1.xml +++ b/.idea/libraries/lib1.xml @@ -2,7 +2,6 @@ - diff --git a/.idea/modules/simple-jdbc-stats.iml b/.idea/modules/simple-jdbc-stats.iml index f17a5e9..ba2f28c 100644 --- a/.idea/modules/simple-jdbc-stats.iml +++ b/.idea/modules/simple-jdbc-stats.iml @@ -1,5 +1,5 @@ - + diff --git a/.idea/modules/simple-jdbc-stats_main.iml b/.idea/modules/simple-jdbc-stats_main.iml index 573880c..c646a2e 100644 --- a/.idea/modules/simple-jdbc-stats_main.iml +++ b/.idea/modules/simple-jdbc-stats_main.iml @@ -1,7 +1,7 @@ - + - + diff --git a/.idea/modules/simple-jdbc-stats_test.iml b/.idea/modules/simple-jdbc-stats_test.iml index 2e21d25..bac5915 100644 --- a/.idea/modules/simple-jdbc-stats_test.iml +++ b/.idea/modules/simple-jdbc-stats_test.iml @@ -1,7 +1,7 @@ - + - + diff --git a/build.gradle b/build.gradle index 04938e8..69bad54 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ group 'nl.astraeus' -version '1.5.10-SNAPSHOT' +version '1.6.0' apply plugin: 'java' apply plugin: 'idea' diff --git a/src/nl/astraeus/jdbc/JdbcLogger.java b/src/nl/astraeus/jdbc/JdbcLogger.java index 737e1ec..67661df 100644 --- a/src/nl/astraeus/jdbc/JdbcLogger.java +++ b/src/nl/astraeus/jdbc/JdbcLogger.java @@ -1,15 +1,16 @@ package nl.astraeus.jdbc; +import nl.astraeus.jdbc.util.Util; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.HashSet; import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.concurrent.ConcurrentHashMap; -import nl.astraeus.jdbc.util.Util; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - /** * User: riennentjes * Date: Jul 12, 2008 @@ -44,8 +45,18 @@ private boolean autoCommit; private boolean formattedQueries; private StackTraceElement[] stackTrace = null; + private Set parameters = new HashSet(); - public LogEntry(int hash, QueryType type, String sql, long milli, long nano, boolean isAutoCommit, boolean formattedQueries) { + public LogEntry( + int hash, + QueryType type, + String sql, + long milli, + long nano, + boolean isAutoCommit, + boolean formattedQueries, + Set parameters + ) { this.threadId = Thread.currentThread().getId(); this.timeStamp = System.currentTimeMillis(); this.nanoTimeStamp = System.nanoTime(); @@ -57,6 +68,7 @@ this.autoCommit = isAutoCommit; this.count = 1; this.formattedQueries = formattedQueries; + this.parameters = parameters; } public LogEntry(LogEntry le) { @@ -64,12 +76,13 @@ this.nanoTimeStamp = System.nanoTime(); this.hash = le.hash; this.type = le.type; - this.sql = le .sql; + this.sql = le.sql; this.milli = le.milli; this.nano = le.nano; this.count = le.count; this.autoCommit = le.autoCommit; this.formattedQueries = le.formattedQueries; + this.parameters = le.parameters; } public QueryType getType() { @@ -113,11 +126,11 @@ } public String getFormattedMilli() { - return Util.formatNano(milli*1000000/count); + return Util.formatNano(milli * 1000000 / count); } public String getFormattedNano() { - return Util.formatNano(nano/count); + return Util.formatNano(nano / count); } public String getTotal() { @@ -132,6 +145,23 @@ } } + public String getParameters() { + StringBuilder result = new StringBuilder(); + + if (parameters != null && !parameters.isEmpty()) { + for (Parameter parameter : parameters) { + result.append(String.format( + "%4s, %12s, %24s\n", + parameter.getIndex(), + parameter.getType(), + parameter.getDisplayValue() + )); + } + } + + return result.toString(); + } + public boolean isEndOfTransaction() { return sql.toLowerCase().trim().equals("commit") || sql.toLowerCase().trim().equals("rollback") @@ -181,11 +211,37 @@ last100.clear(); } - public void logEntry(QueryType type, String sql, long milli, long nano, boolean isAutoCommit) { + public void logEntry( + QueryType type, + String sql, + long milli, + long nano, + boolean isAutoCommit + ) { + logEntry(type, sql, milli, nano, isAutoCommit, new HashSet()); + } + + public void logEntry( + QueryType type, + String sql, + long milli, + long nano, + boolean isAutoCommit, + Set parameters + ) { int hash = sql.hashCode(); Driver.StatsLogger logger = Driver.get(port); - LogEntry entry = new LogEntry(hash, type, sql, milli, nano, isAutoCommit, logger.getSettings().isFormattedQueries()); + LogEntry entry = new LogEntry( + hash, + type, + sql, + milli, + nano, + isAutoCommit, + logger.getSettings().isFormattedQueries(), + parameters + ); if (logger.getSettings().isRecordingStacktraces()) { try { diff --git a/src/nl/astraeus/jdbc/Parameter.java b/src/nl/astraeus/jdbc/Parameter.java new file mode 100644 index 0000000..8fed9f5 --- /dev/null +++ b/src/nl/astraeus/jdbc/Parameter.java @@ -0,0 +1,118 @@ +package nl.astraeus.jdbc; + +/** + * User: rnentjes + * Date: 26-1-18 + * Time: 11:08 + */ +public class Parameter { + + public interface DisplayFunction { + String display(Object o); + } + + private static DisplayFunction valueOf = new DisplayFunction() { + public String display(Object o) { + return String.valueOf(o); + } + }; + + private static DisplayFunction label(final String label) { + return new DisplayFunction() { + public String display(Object o) { + return label; + } + }; + } + + public enum ParameterType { + NULL(new DisplayFunction() { + public String display(Object o) { + return "NULL"; + } + }), + BOOLEAN(valueOf), + INT(valueOf), + LONG(valueOf), + STRING(new DisplayFunction() { + public String display(Object o) { + return (String)o; + } + }), + BLOB(valueOf), + CLOB(valueOf), + BYTE(valueOf), + SHORT(valueOf), + FLOAT(valueOf), + DOUBLE(valueOf), + BIG_DECIMAL(valueOf), + BYTES(new DisplayFunction() { + public String display(Object o) { + return "byte["+((byte[])o).length+"]"; + } + }), + DATE(valueOf), + TIME(valueOf), + TIMESTAMP(valueOf), + ASCII_STR(label("")), + UNICODE_STR(label("")), + BIN_STR(label("")), + OBJECT(valueOf), + CHAR_STR(label("")), + REF(valueOf), + ARRAY(valueOf), + URL(valueOf), + ROW_ID(valueOf), + NSTRING(valueOf), + NCHAR_STR(label("")), + NCLOB(label("")), + SQLXML(label("")); + + private DisplayFunction display; + + ParameterType(DisplayFunction display) { + this.display = display; + } + + public String toString(Object o) { + return display.display(o); + } + } + + private int index; + private ParameterType type; + private Object value; + + public Parameter( + int index, + ParameterType type + ) { + this(index, type, null); + } + + public Parameter( + int index, + ParameterType type, + Object value + ) { + this.index = index; + this.type = type; + this.value = value; + } + + public int getIndex() { + return index; + } + + public ParameterType getType() { + return type; + } + + public Object getValue() { + return value; + } + + public String getDisplayValue() { + return type.display.display(value); + } +} diff --git a/src/nl/astraeus/jdbc/PreparedStatementLogger.java b/src/nl/astraeus/jdbc/PreparedStatementLogger.java index b7fd226..016c384 100644 --- a/src/nl/astraeus/jdbc/PreparedStatementLogger.java +++ b/src/nl/astraeus/jdbc/PreparedStatementLogger.java @@ -1,5 +1,8 @@ package nl.astraeus.jdbc; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.io.InputStream; import java.io.Reader; import java.math.BigDecimal; @@ -22,9 +25,9 @@ import java.sql.Time; import java.sql.Timestamp; import java.util.Calendar; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import java.util.Comparator; +import java.util.Set; +import java.util.TreeSet; /** * User: riennentjes @@ -43,7 +46,17 @@ private long milli; private long nano; - //private ArrayList parameters; + private Set parameters = new TreeSet(new Comparator() { + public int compare( + Parameter o1, + Parameter o2 + ) { + int x = o1.getIndex(); + int y = o2.getIndex(); + + return (x < y) ? -1 : ((x == y) ? 0 : 1); + } + }); public PreparedStatementLogger(JdbcLogger logger, PreparedStatement statement) throws SQLException { this.logger = logger; @@ -62,7 +75,7 @@ long m = System.currentTimeMillis() - milli; long n = System.nanoTime() - nano; - logger.logEntry(type, sql, m, n, autocommit); + logger.logEntry(type, sql, m, n, autocommit, parameters); } public PreparedStatementLogger(JdbcLogger logger, Connection connection, String sql) throws SQLException { @@ -242,194 +255,242 @@ public void setNull(int parameterIndex, int sqlType) throws SQLException { statement.setNull(parameterIndex, sqlType); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.NULL)); } public void setBoolean(int parameterIndex, boolean x) throws SQLException { statement.setBoolean(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.BOOLEAN, x)); } public void setByte(int parameterIndex, byte x) throws SQLException { statement.setByte(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.BYTE, x)); } public void setShort(int parameterIndex, short x) throws SQLException { statement.setShort(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.SHORT, x)); } public void setInt(int parameterIndex, int x) throws SQLException { statement.setInt(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.INT, x)); } public void setLong(int parameterIndex, long x) throws SQLException { statement.setLong(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.LONG, x)); } public void setFloat(int parameterIndex, float x) throws SQLException { statement.setFloat(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.FLOAT, x)); } public void setDouble(int parameterIndex, double x) throws SQLException { statement.setDouble(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.DOUBLE, x)); } public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException { statement.setBigDecimal(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.BIG_DECIMAL, x)); } public void setString(int parameterIndex, String x) throws SQLException { statement.setString(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.STRING, x)); } public void setBytes(int parameterIndex, byte x[]) throws SQLException { statement.setBytes(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.BYTES, x)); } public void setDate(int parameterIndex, Date x) throws SQLException { statement.setDate(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.DATE, x)); } public void setTime(int parameterIndex, Time x) throws SQLException { statement.setTime(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.TIME, x)); } public void setTimestamp(int parameterIndex, Timestamp x) throws SQLException { statement.setTimestamp(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.TIMESTAMP, x)); } public void setAsciiStream(int parameterIndex, InputStream x, int length) throws SQLException { statement.setAsciiStream(parameterIndex, x, length); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.ASCII_STR)); } public void setUnicodeStream(int parameterIndex, InputStream x, int length) throws SQLException { statement.setUnicodeStream(parameterIndex, x, length); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.UNICODE_STR)); } public void setBinaryStream(int parameterIndex, InputStream x, int length) throws SQLException { statement.setBinaryStream(parameterIndex, x, length); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.BIN_STR)); } public void setObject(int parameterIndex, Object x, int targetSqlType) throws SQLException { statement.setObject(parameterIndex, x, targetSqlType); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.OBJECT, x)); } public void setObject(int parameterIndex, Object x) throws SQLException { statement.setObject(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.OBJECT, x)); } public void setCharacterStream(int parameterIndex, Reader reader, int length) throws SQLException { statement.setCharacterStream(parameterIndex, reader, length); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.CHAR_STR, reader)); } public void setRef(int parameterIndex, Ref x) throws SQLException { statement.setRef(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.REF, x)); } public void setBlob(int parameterIndex, Blob x) throws SQLException { statement.setBlob(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.BLOB, x)); } public void setClob(int parameterIndex, Clob x) throws SQLException { statement.setClob(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.CLOB, x)); } public void setArray(int parameterIndex, Array x) throws SQLException { statement.setArray(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.ARRAY, x)); } public void setDate(int parameterIndex, Date x, Calendar cal) throws SQLException { statement.setDate(parameterIndex, x, cal); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.DATE, x)); } public void setTime(int parameterIndex, Time x, Calendar cal) throws SQLException { statement.setTime(parameterIndex, x, cal); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.TIME, x)); } public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal) throws SQLException { statement.setTimestamp(parameterIndex, x, cal); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.TIMESTAMP, x)); } public void setNull(int parameterIndex, int sqlType, String typeName) throws SQLException { statement.setNull(parameterIndex, sqlType, typeName); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.NULL)); } public void setURL(int parameterIndex, URL x) throws SQLException { statement.setURL(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.URL, x)); } public void setRowId(int parameterIndex, RowId x) throws SQLException { statement.setRowId(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.ROW_ID, x)); } public void setNString(int parameterIndex, String value) throws SQLException { statement.setNString(parameterIndex, value); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.NSTRING, value)); } public void setNCharacterStream(int parameterIndex, Reader value, long length) throws SQLException { statement.setNCharacterStream(parameterIndex, value, length); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.NCHAR_STR, value)); } public void setNClob(int parameterIndex, NClob value) throws SQLException { statement.setNClob(parameterIndex, value); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.NCLOB, value)); } public void setClob(int parameterIndex, Reader reader, long length) throws SQLException { statement.setClob(parameterIndex, reader, length); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.CLOB, reader)); } public void setBlob(int parameterIndex, InputStream inputStream, long length) throws SQLException { statement.setBlob(parameterIndex, inputStream, length); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.BLOB)); } public void setNClob(int parameterIndex, Reader reader, long length) throws SQLException { statement.setNClob(parameterIndex, reader, length); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.NCLOB)); } public void setSQLXML(int parameterIndex, SQLXML xmlObject) throws SQLException { statement.setSQLXML(parameterIndex, xmlObject); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.SQLXML)); } public void setObject(int parameterIndex, Object x, int targetSqlType, int scaleOrLength) throws SQLException { statement.setObject(parameterIndex, x, targetSqlType, scaleOrLength); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.OBJECT, x)); } public void setAsciiStream(int parameterIndex, InputStream x, long length) throws SQLException { statement.setAsciiStream(parameterIndex, x, length); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.ASCII_STR)); } public void setBinaryStream(int parameterIndex, InputStream x, long length) throws SQLException { statement.setBinaryStream(parameterIndex, x, length); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.BIN_STR)); } public void setCharacterStream(int parameterIndex, Reader reader, long length) throws SQLException { statement.setCharacterStream(parameterIndex, reader, length); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.CHAR_STR)); } public void setAsciiStream(int parameterIndex, InputStream x) throws SQLException { statement.setAsciiStream(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.ASCII_STR)); } public void setBinaryStream(int parameterIndex, InputStream x) throws SQLException { statement.setBinaryStream(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.BIN_STR)); } public void setCharacterStream(int parameterIndex, Reader reader) throws SQLException { statement.setCharacterStream(parameterIndex, reader); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.CHAR_STR)); } public void setNCharacterStream(int parameterIndex, Reader value) throws SQLException { statement.setNCharacterStream(parameterIndex, value); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.NCHAR_STR)); } public void setClob(int parameterIndex, Reader reader) throws SQLException { statement.setClob(parameterIndex, reader); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.CLOB)); } public void setBlob(int parameterIndex, InputStream inputStream) throws SQLException { statement.setBlob(parameterIndex, inputStream); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.BLOB)); } public void setNClob(int parameterIndex, Reader reader) throws SQLException { statement.setNClob(parameterIndex, reader); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.NCLOB)); } diff --git a/.idea/checkstyle-idea.xml b/.idea/checkstyle-idea.xml new file mode 100644 index 0000000..b6e4700 --- /dev/null +++ b/.idea/checkstyle-idea.xml @@ -0,0 +1,16 @@ + + + + + + \ No newline at end of file diff --git a/.idea/hotswap_agent.xml b/.idea/hotswap_agent.xml new file mode 100644 index 0000000..8a869d9 --- /dev/null +++ b/.idea/hotswap_agent.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/libraries/lib1.xml b/.idea/libraries/lib1.xml index 8ce9ba1..7a6f4d3 100644 --- a/.idea/libraries/lib1.xml +++ b/.idea/libraries/lib1.xml @@ -2,7 +2,6 @@ - diff --git a/.idea/modules/simple-jdbc-stats.iml b/.idea/modules/simple-jdbc-stats.iml index f17a5e9..ba2f28c 100644 --- a/.idea/modules/simple-jdbc-stats.iml +++ b/.idea/modules/simple-jdbc-stats.iml @@ -1,5 +1,5 @@ - + diff --git a/.idea/modules/simple-jdbc-stats_main.iml b/.idea/modules/simple-jdbc-stats_main.iml index 573880c..c646a2e 100644 --- a/.idea/modules/simple-jdbc-stats_main.iml +++ b/.idea/modules/simple-jdbc-stats_main.iml @@ -1,7 +1,7 @@ - + - + diff --git a/.idea/modules/simple-jdbc-stats_test.iml b/.idea/modules/simple-jdbc-stats_test.iml index 2e21d25..bac5915 100644 --- a/.idea/modules/simple-jdbc-stats_test.iml +++ b/.idea/modules/simple-jdbc-stats_test.iml @@ -1,7 +1,7 @@ - + - + diff --git a/build.gradle b/build.gradle index 04938e8..69bad54 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ group 'nl.astraeus' -version '1.5.10-SNAPSHOT' +version '1.6.0' apply plugin: 'java' apply plugin: 'idea' diff --git a/src/nl/astraeus/jdbc/JdbcLogger.java b/src/nl/astraeus/jdbc/JdbcLogger.java index 737e1ec..67661df 100644 --- a/src/nl/astraeus/jdbc/JdbcLogger.java +++ b/src/nl/astraeus/jdbc/JdbcLogger.java @@ -1,15 +1,16 @@ package nl.astraeus.jdbc; +import nl.astraeus.jdbc.util.Util; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.HashSet; import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.concurrent.ConcurrentHashMap; -import nl.astraeus.jdbc.util.Util; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - /** * User: riennentjes * Date: Jul 12, 2008 @@ -44,8 +45,18 @@ private boolean autoCommit; private boolean formattedQueries; private StackTraceElement[] stackTrace = null; + private Set parameters = new HashSet(); - public LogEntry(int hash, QueryType type, String sql, long milli, long nano, boolean isAutoCommit, boolean formattedQueries) { + public LogEntry( + int hash, + QueryType type, + String sql, + long milli, + long nano, + boolean isAutoCommit, + boolean formattedQueries, + Set parameters + ) { this.threadId = Thread.currentThread().getId(); this.timeStamp = System.currentTimeMillis(); this.nanoTimeStamp = System.nanoTime(); @@ -57,6 +68,7 @@ this.autoCommit = isAutoCommit; this.count = 1; this.formattedQueries = formattedQueries; + this.parameters = parameters; } public LogEntry(LogEntry le) { @@ -64,12 +76,13 @@ this.nanoTimeStamp = System.nanoTime(); this.hash = le.hash; this.type = le.type; - this.sql = le .sql; + this.sql = le.sql; this.milli = le.milli; this.nano = le.nano; this.count = le.count; this.autoCommit = le.autoCommit; this.formattedQueries = le.formattedQueries; + this.parameters = le.parameters; } public QueryType getType() { @@ -113,11 +126,11 @@ } public String getFormattedMilli() { - return Util.formatNano(milli*1000000/count); + return Util.formatNano(milli * 1000000 / count); } public String getFormattedNano() { - return Util.formatNano(nano/count); + return Util.formatNano(nano / count); } public String getTotal() { @@ -132,6 +145,23 @@ } } + public String getParameters() { + StringBuilder result = new StringBuilder(); + + if (parameters != null && !parameters.isEmpty()) { + for (Parameter parameter : parameters) { + result.append(String.format( + "%4s, %12s, %24s\n", + parameter.getIndex(), + parameter.getType(), + parameter.getDisplayValue() + )); + } + } + + return result.toString(); + } + public boolean isEndOfTransaction() { return sql.toLowerCase().trim().equals("commit") || sql.toLowerCase().trim().equals("rollback") @@ -181,11 +211,37 @@ last100.clear(); } - public void logEntry(QueryType type, String sql, long milli, long nano, boolean isAutoCommit) { + public void logEntry( + QueryType type, + String sql, + long milli, + long nano, + boolean isAutoCommit + ) { + logEntry(type, sql, milli, nano, isAutoCommit, new HashSet()); + } + + public void logEntry( + QueryType type, + String sql, + long milli, + long nano, + boolean isAutoCommit, + Set parameters + ) { int hash = sql.hashCode(); Driver.StatsLogger logger = Driver.get(port); - LogEntry entry = new LogEntry(hash, type, sql, milli, nano, isAutoCommit, logger.getSettings().isFormattedQueries()); + LogEntry entry = new LogEntry( + hash, + type, + sql, + milli, + nano, + isAutoCommit, + logger.getSettings().isFormattedQueries(), + parameters + ); if (logger.getSettings().isRecordingStacktraces()) { try { diff --git a/src/nl/astraeus/jdbc/Parameter.java b/src/nl/astraeus/jdbc/Parameter.java new file mode 100644 index 0000000..8fed9f5 --- /dev/null +++ b/src/nl/astraeus/jdbc/Parameter.java @@ -0,0 +1,118 @@ +package nl.astraeus.jdbc; + +/** + * User: rnentjes + * Date: 26-1-18 + * Time: 11:08 + */ +public class Parameter { + + public interface DisplayFunction { + String display(Object o); + } + + private static DisplayFunction valueOf = new DisplayFunction() { + public String display(Object o) { + return String.valueOf(o); + } + }; + + private static DisplayFunction label(final String label) { + return new DisplayFunction() { + public String display(Object o) { + return label; + } + }; + } + + public enum ParameterType { + NULL(new DisplayFunction() { + public String display(Object o) { + return "NULL"; + } + }), + BOOLEAN(valueOf), + INT(valueOf), + LONG(valueOf), + STRING(new DisplayFunction() { + public String display(Object o) { + return (String)o; + } + }), + BLOB(valueOf), + CLOB(valueOf), + BYTE(valueOf), + SHORT(valueOf), + FLOAT(valueOf), + DOUBLE(valueOf), + BIG_DECIMAL(valueOf), + BYTES(new DisplayFunction() { + public String display(Object o) { + return "byte["+((byte[])o).length+"]"; + } + }), + DATE(valueOf), + TIME(valueOf), + TIMESTAMP(valueOf), + ASCII_STR(label("")), + UNICODE_STR(label("")), + BIN_STR(label("")), + OBJECT(valueOf), + CHAR_STR(label("")), + REF(valueOf), + ARRAY(valueOf), + URL(valueOf), + ROW_ID(valueOf), + NSTRING(valueOf), + NCHAR_STR(label("")), + NCLOB(label("")), + SQLXML(label("")); + + private DisplayFunction display; + + ParameterType(DisplayFunction display) { + this.display = display; + } + + public String toString(Object o) { + return display.display(o); + } + } + + private int index; + private ParameterType type; + private Object value; + + public Parameter( + int index, + ParameterType type + ) { + this(index, type, null); + } + + public Parameter( + int index, + ParameterType type, + Object value + ) { + this.index = index; + this.type = type; + this.value = value; + } + + public int getIndex() { + return index; + } + + public ParameterType getType() { + return type; + } + + public Object getValue() { + return value; + } + + public String getDisplayValue() { + return type.display.display(value); + } +} diff --git a/src/nl/astraeus/jdbc/PreparedStatementLogger.java b/src/nl/astraeus/jdbc/PreparedStatementLogger.java index b7fd226..016c384 100644 --- a/src/nl/astraeus/jdbc/PreparedStatementLogger.java +++ b/src/nl/astraeus/jdbc/PreparedStatementLogger.java @@ -1,5 +1,8 @@ package nl.astraeus.jdbc; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.io.InputStream; import java.io.Reader; import java.math.BigDecimal; @@ -22,9 +25,9 @@ import java.sql.Time; import java.sql.Timestamp; import java.util.Calendar; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import java.util.Comparator; +import java.util.Set; +import java.util.TreeSet; /** * User: riennentjes @@ -43,7 +46,17 @@ private long milli; private long nano; - //private ArrayList parameters; + private Set parameters = new TreeSet(new Comparator() { + public int compare( + Parameter o1, + Parameter o2 + ) { + int x = o1.getIndex(); + int y = o2.getIndex(); + + return (x < y) ? -1 : ((x == y) ? 0 : 1); + } + }); public PreparedStatementLogger(JdbcLogger logger, PreparedStatement statement) throws SQLException { this.logger = logger; @@ -62,7 +75,7 @@ long m = System.currentTimeMillis() - milli; long n = System.nanoTime() - nano; - logger.logEntry(type, sql, m, n, autocommit); + logger.logEntry(type, sql, m, n, autocommit, parameters); } public PreparedStatementLogger(JdbcLogger logger, Connection connection, String sql) throws SQLException { @@ -242,194 +255,242 @@ public void setNull(int parameterIndex, int sqlType) throws SQLException { statement.setNull(parameterIndex, sqlType); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.NULL)); } public void setBoolean(int parameterIndex, boolean x) throws SQLException { statement.setBoolean(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.BOOLEAN, x)); } public void setByte(int parameterIndex, byte x) throws SQLException { statement.setByte(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.BYTE, x)); } public void setShort(int parameterIndex, short x) throws SQLException { statement.setShort(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.SHORT, x)); } public void setInt(int parameterIndex, int x) throws SQLException { statement.setInt(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.INT, x)); } public void setLong(int parameterIndex, long x) throws SQLException { statement.setLong(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.LONG, x)); } public void setFloat(int parameterIndex, float x) throws SQLException { statement.setFloat(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.FLOAT, x)); } public void setDouble(int parameterIndex, double x) throws SQLException { statement.setDouble(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.DOUBLE, x)); } public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException { statement.setBigDecimal(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.BIG_DECIMAL, x)); } public void setString(int parameterIndex, String x) throws SQLException { statement.setString(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.STRING, x)); } public void setBytes(int parameterIndex, byte x[]) throws SQLException { statement.setBytes(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.BYTES, x)); } public void setDate(int parameterIndex, Date x) throws SQLException { statement.setDate(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.DATE, x)); } public void setTime(int parameterIndex, Time x) throws SQLException { statement.setTime(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.TIME, x)); } public void setTimestamp(int parameterIndex, Timestamp x) throws SQLException { statement.setTimestamp(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.TIMESTAMP, x)); } public void setAsciiStream(int parameterIndex, InputStream x, int length) throws SQLException { statement.setAsciiStream(parameterIndex, x, length); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.ASCII_STR)); } public void setUnicodeStream(int parameterIndex, InputStream x, int length) throws SQLException { statement.setUnicodeStream(parameterIndex, x, length); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.UNICODE_STR)); } public void setBinaryStream(int parameterIndex, InputStream x, int length) throws SQLException { statement.setBinaryStream(parameterIndex, x, length); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.BIN_STR)); } public void setObject(int parameterIndex, Object x, int targetSqlType) throws SQLException { statement.setObject(parameterIndex, x, targetSqlType); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.OBJECT, x)); } public void setObject(int parameterIndex, Object x) throws SQLException { statement.setObject(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.OBJECT, x)); } public void setCharacterStream(int parameterIndex, Reader reader, int length) throws SQLException { statement.setCharacterStream(parameterIndex, reader, length); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.CHAR_STR, reader)); } public void setRef(int parameterIndex, Ref x) throws SQLException { statement.setRef(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.REF, x)); } public void setBlob(int parameterIndex, Blob x) throws SQLException { statement.setBlob(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.BLOB, x)); } public void setClob(int parameterIndex, Clob x) throws SQLException { statement.setClob(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.CLOB, x)); } public void setArray(int parameterIndex, Array x) throws SQLException { statement.setArray(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.ARRAY, x)); } public void setDate(int parameterIndex, Date x, Calendar cal) throws SQLException { statement.setDate(parameterIndex, x, cal); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.DATE, x)); } public void setTime(int parameterIndex, Time x, Calendar cal) throws SQLException { statement.setTime(parameterIndex, x, cal); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.TIME, x)); } public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal) throws SQLException { statement.setTimestamp(parameterIndex, x, cal); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.TIMESTAMP, x)); } public void setNull(int parameterIndex, int sqlType, String typeName) throws SQLException { statement.setNull(parameterIndex, sqlType, typeName); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.NULL)); } public void setURL(int parameterIndex, URL x) throws SQLException { statement.setURL(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.URL, x)); } public void setRowId(int parameterIndex, RowId x) throws SQLException { statement.setRowId(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.ROW_ID, x)); } public void setNString(int parameterIndex, String value) throws SQLException { statement.setNString(parameterIndex, value); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.NSTRING, value)); } public void setNCharacterStream(int parameterIndex, Reader value, long length) throws SQLException { statement.setNCharacterStream(parameterIndex, value, length); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.NCHAR_STR, value)); } public void setNClob(int parameterIndex, NClob value) throws SQLException { statement.setNClob(parameterIndex, value); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.NCLOB, value)); } public void setClob(int parameterIndex, Reader reader, long length) throws SQLException { statement.setClob(parameterIndex, reader, length); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.CLOB, reader)); } public void setBlob(int parameterIndex, InputStream inputStream, long length) throws SQLException { statement.setBlob(parameterIndex, inputStream, length); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.BLOB)); } public void setNClob(int parameterIndex, Reader reader, long length) throws SQLException { statement.setNClob(parameterIndex, reader, length); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.NCLOB)); } public void setSQLXML(int parameterIndex, SQLXML xmlObject) throws SQLException { statement.setSQLXML(parameterIndex, xmlObject); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.SQLXML)); } public void setObject(int parameterIndex, Object x, int targetSqlType, int scaleOrLength) throws SQLException { statement.setObject(parameterIndex, x, targetSqlType, scaleOrLength); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.OBJECT, x)); } public void setAsciiStream(int parameterIndex, InputStream x, long length) throws SQLException { statement.setAsciiStream(parameterIndex, x, length); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.ASCII_STR)); } public void setBinaryStream(int parameterIndex, InputStream x, long length) throws SQLException { statement.setBinaryStream(parameterIndex, x, length); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.BIN_STR)); } public void setCharacterStream(int parameterIndex, Reader reader, long length) throws SQLException { statement.setCharacterStream(parameterIndex, reader, length); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.CHAR_STR)); } public void setAsciiStream(int parameterIndex, InputStream x) throws SQLException { statement.setAsciiStream(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.ASCII_STR)); } public void setBinaryStream(int parameterIndex, InputStream x) throws SQLException { statement.setBinaryStream(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.BIN_STR)); } public void setCharacterStream(int parameterIndex, Reader reader) throws SQLException { statement.setCharacterStream(parameterIndex, reader); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.CHAR_STR)); } public void setNCharacterStream(int parameterIndex, Reader value) throws SQLException { statement.setNCharacterStream(parameterIndex, value); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.NCHAR_STR)); } public void setClob(int parameterIndex, Reader reader) throws SQLException { statement.setClob(parameterIndex, reader); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.CLOB)); } public void setBlob(int parameterIndex, InputStream inputStream) throws SQLException { statement.setBlob(parameterIndex, inputStream); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.BLOB)); } public void setNClob(int parameterIndex, Reader reader) throws SQLException { statement.setNClob(parameterIndex, reader); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.NCLOB)); } diff --git a/src/nl/astraeus/jdbc/web/page/HeaderPage.html b/src/nl/astraeus/jdbc/web/page/HeaderPage.html index 3788989..b4b4b2d 100644 --- a/src/nl/astraeus/jdbc/web/page/HeaderPage.html +++ b/src/nl/astraeus/jdbc/web/page/HeaderPage.html @@ -4,7 +4,7 @@ - Simple JDBC Statistics + JDBC Statistics diff --git a/.idea/checkstyle-idea.xml b/.idea/checkstyle-idea.xml new file mode 100644 index 0000000..b6e4700 --- /dev/null +++ b/.idea/checkstyle-idea.xml @@ -0,0 +1,16 @@ + + + + + + \ No newline at end of file diff --git a/.idea/hotswap_agent.xml b/.idea/hotswap_agent.xml new file mode 100644 index 0000000..8a869d9 --- /dev/null +++ b/.idea/hotswap_agent.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/libraries/lib1.xml b/.idea/libraries/lib1.xml index 8ce9ba1..7a6f4d3 100644 --- a/.idea/libraries/lib1.xml +++ b/.idea/libraries/lib1.xml @@ -2,7 +2,6 @@ - diff --git a/.idea/modules/simple-jdbc-stats.iml b/.idea/modules/simple-jdbc-stats.iml index f17a5e9..ba2f28c 100644 --- a/.idea/modules/simple-jdbc-stats.iml +++ b/.idea/modules/simple-jdbc-stats.iml @@ -1,5 +1,5 @@ - + diff --git a/.idea/modules/simple-jdbc-stats_main.iml b/.idea/modules/simple-jdbc-stats_main.iml index 573880c..c646a2e 100644 --- a/.idea/modules/simple-jdbc-stats_main.iml +++ b/.idea/modules/simple-jdbc-stats_main.iml @@ -1,7 +1,7 @@ - + - + diff --git a/.idea/modules/simple-jdbc-stats_test.iml b/.idea/modules/simple-jdbc-stats_test.iml index 2e21d25..bac5915 100644 --- a/.idea/modules/simple-jdbc-stats_test.iml +++ b/.idea/modules/simple-jdbc-stats_test.iml @@ -1,7 +1,7 @@ - + - + diff --git a/build.gradle b/build.gradle index 04938e8..69bad54 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ group 'nl.astraeus' -version '1.5.10-SNAPSHOT' +version '1.6.0' apply plugin: 'java' apply plugin: 'idea' diff --git a/src/nl/astraeus/jdbc/JdbcLogger.java b/src/nl/astraeus/jdbc/JdbcLogger.java index 737e1ec..67661df 100644 --- a/src/nl/astraeus/jdbc/JdbcLogger.java +++ b/src/nl/astraeus/jdbc/JdbcLogger.java @@ -1,15 +1,16 @@ package nl.astraeus.jdbc; +import nl.astraeus.jdbc.util.Util; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.HashSet; import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.concurrent.ConcurrentHashMap; -import nl.astraeus.jdbc.util.Util; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - /** * User: riennentjes * Date: Jul 12, 2008 @@ -44,8 +45,18 @@ private boolean autoCommit; private boolean formattedQueries; private StackTraceElement[] stackTrace = null; + private Set parameters = new HashSet(); - public LogEntry(int hash, QueryType type, String sql, long milli, long nano, boolean isAutoCommit, boolean formattedQueries) { + public LogEntry( + int hash, + QueryType type, + String sql, + long milli, + long nano, + boolean isAutoCommit, + boolean formattedQueries, + Set parameters + ) { this.threadId = Thread.currentThread().getId(); this.timeStamp = System.currentTimeMillis(); this.nanoTimeStamp = System.nanoTime(); @@ -57,6 +68,7 @@ this.autoCommit = isAutoCommit; this.count = 1; this.formattedQueries = formattedQueries; + this.parameters = parameters; } public LogEntry(LogEntry le) { @@ -64,12 +76,13 @@ this.nanoTimeStamp = System.nanoTime(); this.hash = le.hash; this.type = le.type; - this.sql = le .sql; + this.sql = le.sql; this.milli = le.milli; this.nano = le.nano; this.count = le.count; this.autoCommit = le.autoCommit; this.formattedQueries = le.formattedQueries; + this.parameters = le.parameters; } public QueryType getType() { @@ -113,11 +126,11 @@ } public String getFormattedMilli() { - return Util.formatNano(milli*1000000/count); + return Util.formatNano(milli * 1000000 / count); } public String getFormattedNano() { - return Util.formatNano(nano/count); + return Util.formatNano(nano / count); } public String getTotal() { @@ -132,6 +145,23 @@ } } + public String getParameters() { + StringBuilder result = new StringBuilder(); + + if (parameters != null && !parameters.isEmpty()) { + for (Parameter parameter : parameters) { + result.append(String.format( + "%4s, %12s, %24s\n", + parameter.getIndex(), + parameter.getType(), + parameter.getDisplayValue() + )); + } + } + + return result.toString(); + } + public boolean isEndOfTransaction() { return sql.toLowerCase().trim().equals("commit") || sql.toLowerCase().trim().equals("rollback") @@ -181,11 +211,37 @@ last100.clear(); } - public void logEntry(QueryType type, String sql, long milli, long nano, boolean isAutoCommit) { + public void logEntry( + QueryType type, + String sql, + long milli, + long nano, + boolean isAutoCommit + ) { + logEntry(type, sql, milli, nano, isAutoCommit, new HashSet()); + } + + public void logEntry( + QueryType type, + String sql, + long milli, + long nano, + boolean isAutoCommit, + Set parameters + ) { int hash = sql.hashCode(); Driver.StatsLogger logger = Driver.get(port); - LogEntry entry = new LogEntry(hash, type, sql, milli, nano, isAutoCommit, logger.getSettings().isFormattedQueries()); + LogEntry entry = new LogEntry( + hash, + type, + sql, + milli, + nano, + isAutoCommit, + logger.getSettings().isFormattedQueries(), + parameters + ); if (logger.getSettings().isRecordingStacktraces()) { try { diff --git a/src/nl/astraeus/jdbc/Parameter.java b/src/nl/astraeus/jdbc/Parameter.java new file mode 100644 index 0000000..8fed9f5 --- /dev/null +++ b/src/nl/astraeus/jdbc/Parameter.java @@ -0,0 +1,118 @@ +package nl.astraeus.jdbc; + +/** + * User: rnentjes + * Date: 26-1-18 + * Time: 11:08 + */ +public class Parameter { + + public interface DisplayFunction { + String display(Object o); + } + + private static DisplayFunction valueOf = new DisplayFunction() { + public String display(Object o) { + return String.valueOf(o); + } + }; + + private static DisplayFunction label(final String label) { + return new DisplayFunction() { + public String display(Object o) { + return label; + } + }; + } + + public enum ParameterType { + NULL(new DisplayFunction() { + public String display(Object o) { + return "NULL"; + } + }), + BOOLEAN(valueOf), + INT(valueOf), + LONG(valueOf), + STRING(new DisplayFunction() { + public String display(Object o) { + return (String)o; + } + }), + BLOB(valueOf), + CLOB(valueOf), + BYTE(valueOf), + SHORT(valueOf), + FLOAT(valueOf), + DOUBLE(valueOf), + BIG_DECIMAL(valueOf), + BYTES(new DisplayFunction() { + public String display(Object o) { + return "byte["+((byte[])o).length+"]"; + } + }), + DATE(valueOf), + TIME(valueOf), + TIMESTAMP(valueOf), + ASCII_STR(label("")), + UNICODE_STR(label("")), + BIN_STR(label("")), + OBJECT(valueOf), + CHAR_STR(label("")), + REF(valueOf), + ARRAY(valueOf), + URL(valueOf), + ROW_ID(valueOf), + NSTRING(valueOf), + NCHAR_STR(label("")), + NCLOB(label("")), + SQLXML(label("")); + + private DisplayFunction display; + + ParameterType(DisplayFunction display) { + this.display = display; + } + + public String toString(Object o) { + return display.display(o); + } + } + + private int index; + private ParameterType type; + private Object value; + + public Parameter( + int index, + ParameterType type + ) { + this(index, type, null); + } + + public Parameter( + int index, + ParameterType type, + Object value + ) { + this.index = index; + this.type = type; + this.value = value; + } + + public int getIndex() { + return index; + } + + public ParameterType getType() { + return type; + } + + public Object getValue() { + return value; + } + + public String getDisplayValue() { + return type.display.display(value); + } +} diff --git a/src/nl/astraeus/jdbc/PreparedStatementLogger.java b/src/nl/astraeus/jdbc/PreparedStatementLogger.java index b7fd226..016c384 100644 --- a/src/nl/astraeus/jdbc/PreparedStatementLogger.java +++ b/src/nl/astraeus/jdbc/PreparedStatementLogger.java @@ -1,5 +1,8 @@ package nl.astraeus.jdbc; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.io.InputStream; import java.io.Reader; import java.math.BigDecimal; @@ -22,9 +25,9 @@ import java.sql.Time; import java.sql.Timestamp; import java.util.Calendar; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import java.util.Comparator; +import java.util.Set; +import java.util.TreeSet; /** * User: riennentjes @@ -43,7 +46,17 @@ private long milli; private long nano; - //private ArrayList parameters; + private Set parameters = new TreeSet(new Comparator() { + public int compare( + Parameter o1, + Parameter o2 + ) { + int x = o1.getIndex(); + int y = o2.getIndex(); + + return (x < y) ? -1 : ((x == y) ? 0 : 1); + } + }); public PreparedStatementLogger(JdbcLogger logger, PreparedStatement statement) throws SQLException { this.logger = logger; @@ -62,7 +75,7 @@ long m = System.currentTimeMillis() - milli; long n = System.nanoTime() - nano; - logger.logEntry(type, sql, m, n, autocommit); + logger.logEntry(type, sql, m, n, autocommit, parameters); } public PreparedStatementLogger(JdbcLogger logger, Connection connection, String sql) throws SQLException { @@ -242,194 +255,242 @@ public void setNull(int parameterIndex, int sqlType) throws SQLException { statement.setNull(parameterIndex, sqlType); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.NULL)); } public void setBoolean(int parameterIndex, boolean x) throws SQLException { statement.setBoolean(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.BOOLEAN, x)); } public void setByte(int parameterIndex, byte x) throws SQLException { statement.setByte(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.BYTE, x)); } public void setShort(int parameterIndex, short x) throws SQLException { statement.setShort(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.SHORT, x)); } public void setInt(int parameterIndex, int x) throws SQLException { statement.setInt(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.INT, x)); } public void setLong(int parameterIndex, long x) throws SQLException { statement.setLong(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.LONG, x)); } public void setFloat(int parameterIndex, float x) throws SQLException { statement.setFloat(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.FLOAT, x)); } public void setDouble(int parameterIndex, double x) throws SQLException { statement.setDouble(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.DOUBLE, x)); } public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException { statement.setBigDecimal(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.BIG_DECIMAL, x)); } public void setString(int parameterIndex, String x) throws SQLException { statement.setString(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.STRING, x)); } public void setBytes(int parameterIndex, byte x[]) throws SQLException { statement.setBytes(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.BYTES, x)); } public void setDate(int parameterIndex, Date x) throws SQLException { statement.setDate(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.DATE, x)); } public void setTime(int parameterIndex, Time x) throws SQLException { statement.setTime(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.TIME, x)); } public void setTimestamp(int parameterIndex, Timestamp x) throws SQLException { statement.setTimestamp(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.TIMESTAMP, x)); } public void setAsciiStream(int parameterIndex, InputStream x, int length) throws SQLException { statement.setAsciiStream(parameterIndex, x, length); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.ASCII_STR)); } public void setUnicodeStream(int parameterIndex, InputStream x, int length) throws SQLException { statement.setUnicodeStream(parameterIndex, x, length); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.UNICODE_STR)); } public void setBinaryStream(int parameterIndex, InputStream x, int length) throws SQLException { statement.setBinaryStream(parameterIndex, x, length); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.BIN_STR)); } public void setObject(int parameterIndex, Object x, int targetSqlType) throws SQLException { statement.setObject(parameterIndex, x, targetSqlType); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.OBJECT, x)); } public void setObject(int parameterIndex, Object x) throws SQLException { statement.setObject(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.OBJECT, x)); } public void setCharacterStream(int parameterIndex, Reader reader, int length) throws SQLException { statement.setCharacterStream(parameterIndex, reader, length); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.CHAR_STR, reader)); } public void setRef(int parameterIndex, Ref x) throws SQLException { statement.setRef(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.REF, x)); } public void setBlob(int parameterIndex, Blob x) throws SQLException { statement.setBlob(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.BLOB, x)); } public void setClob(int parameterIndex, Clob x) throws SQLException { statement.setClob(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.CLOB, x)); } public void setArray(int parameterIndex, Array x) throws SQLException { statement.setArray(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.ARRAY, x)); } public void setDate(int parameterIndex, Date x, Calendar cal) throws SQLException { statement.setDate(parameterIndex, x, cal); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.DATE, x)); } public void setTime(int parameterIndex, Time x, Calendar cal) throws SQLException { statement.setTime(parameterIndex, x, cal); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.TIME, x)); } public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal) throws SQLException { statement.setTimestamp(parameterIndex, x, cal); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.TIMESTAMP, x)); } public void setNull(int parameterIndex, int sqlType, String typeName) throws SQLException { statement.setNull(parameterIndex, sqlType, typeName); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.NULL)); } public void setURL(int parameterIndex, URL x) throws SQLException { statement.setURL(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.URL, x)); } public void setRowId(int parameterIndex, RowId x) throws SQLException { statement.setRowId(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.ROW_ID, x)); } public void setNString(int parameterIndex, String value) throws SQLException { statement.setNString(parameterIndex, value); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.NSTRING, value)); } public void setNCharacterStream(int parameterIndex, Reader value, long length) throws SQLException { statement.setNCharacterStream(parameterIndex, value, length); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.NCHAR_STR, value)); } public void setNClob(int parameterIndex, NClob value) throws SQLException { statement.setNClob(parameterIndex, value); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.NCLOB, value)); } public void setClob(int parameterIndex, Reader reader, long length) throws SQLException { statement.setClob(parameterIndex, reader, length); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.CLOB, reader)); } public void setBlob(int parameterIndex, InputStream inputStream, long length) throws SQLException { statement.setBlob(parameterIndex, inputStream, length); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.BLOB)); } public void setNClob(int parameterIndex, Reader reader, long length) throws SQLException { statement.setNClob(parameterIndex, reader, length); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.NCLOB)); } public void setSQLXML(int parameterIndex, SQLXML xmlObject) throws SQLException { statement.setSQLXML(parameterIndex, xmlObject); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.SQLXML)); } public void setObject(int parameterIndex, Object x, int targetSqlType, int scaleOrLength) throws SQLException { statement.setObject(parameterIndex, x, targetSqlType, scaleOrLength); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.OBJECT, x)); } public void setAsciiStream(int parameterIndex, InputStream x, long length) throws SQLException { statement.setAsciiStream(parameterIndex, x, length); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.ASCII_STR)); } public void setBinaryStream(int parameterIndex, InputStream x, long length) throws SQLException { statement.setBinaryStream(parameterIndex, x, length); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.BIN_STR)); } public void setCharacterStream(int parameterIndex, Reader reader, long length) throws SQLException { statement.setCharacterStream(parameterIndex, reader, length); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.CHAR_STR)); } public void setAsciiStream(int parameterIndex, InputStream x) throws SQLException { statement.setAsciiStream(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.ASCII_STR)); } public void setBinaryStream(int parameterIndex, InputStream x) throws SQLException { statement.setBinaryStream(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.BIN_STR)); } public void setCharacterStream(int parameterIndex, Reader reader) throws SQLException { statement.setCharacterStream(parameterIndex, reader); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.CHAR_STR)); } public void setNCharacterStream(int parameterIndex, Reader value) throws SQLException { statement.setNCharacterStream(parameterIndex, value); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.NCHAR_STR)); } public void setClob(int parameterIndex, Reader reader) throws SQLException { statement.setClob(parameterIndex, reader); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.CLOB)); } public void setBlob(int parameterIndex, InputStream inputStream) throws SQLException { statement.setBlob(parameterIndex, inputStream); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.BLOB)); } public void setNClob(int parameterIndex, Reader reader) throws SQLException { statement.setNClob(parameterIndex, reader); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.NCLOB)); } diff --git a/src/nl/astraeus/jdbc/web/page/HeaderPage.html b/src/nl/astraeus/jdbc/web/page/HeaderPage.html index 3788989..b4b4b2d 100644 --- a/src/nl/astraeus/jdbc/web/page/HeaderPage.html +++ b/src/nl/astraeus/jdbc/web/page/HeaderPage.html @@ -4,7 +4,7 @@ - Simple JDBC Statistics + JDBC Statistics diff --git a/src/nl/astraeus/jdbc/web/page/QueryDetail.html b/src/nl/astraeus/jdbc/web/page/QueryDetail.html index 1fe0ba7..959c057 100644 --- a/src/nl/astraeus/jdbc/web/page/QueryDetail.html +++ b/src/nl/astraeus/jdbc/web/page/QueryDetail.html @@ -52,6 +52,7 @@ Timestamp Thread id Type + Parameters Time (ms) @@ -62,6 +63,7 @@ ${q.formattedTimestamp} ${q.threadId} ${q.type.description} +
${q.parameters}
${q.total} ${/each} diff --git a/.idea/checkstyle-idea.xml b/.idea/checkstyle-idea.xml new file mode 100644 index 0000000..b6e4700 --- /dev/null +++ b/.idea/checkstyle-idea.xml @@ -0,0 +1,16 @@ + + + + + + \ No newline at end of file diff --git a/.idea/hotswap_agent.xml b/.idea/hotswap_agent.xml new file mode 100644 index 0000000..8a869d9 --- /dev/null +++ b/.idea/hotswap_agent.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/libraries/lib1.xml b/.idea/libraries/lib1.xml index 8ce9ba1..7a6f4d3 100644 --- a/.idea/libraries/lib1.xml +++ b/.idea/libraries/lib1.xml @@ -2,7 +2,6 @@ - diff --git a/.idea/modules/simple-jdbc-stats.iml b/.idea/modules/simple-jdbc-stats.iml index f17a5e9..ba2f28c 100644 --- a/.idea/modules/simple-jdbc-stats.iml +++ b/.idea/modules/simple-jdbc-stats.iml @@ -1,5 +1,5 @@ - + diff --git a/.idea/modules/simple-jdbc-stats_main.iml b/.idea/modules/simple-jdbc-stats_main.iml index 573880c..c646a2e 100644 --- a/.idea/modules/simple-jdbc-stats_main.iml +++ b/.idea/modules/simple-jdbc-stats_main.iml @@ -1,7 +1,7 @@ - + - + diff --git a/.idea/modules/simple-jdbc-stats_test.iml b/.idea/modules/simple-jdbc-stats_test.iml index 2e21d25..bac5915 100644 --- a/.idea/modules/simple-jdbc-stats_test.iml +++ b/.idea/modules/simple-jdbc-stats_test.iml @@ -1,7 +1,7 @@ - + - + diff --git a/build.gradle b/build.gradle index 04938e8..69bad54 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ group 'nl.astraeus' -version '1.5.10-SNAPSHOT' +version '1.6.0' apply plugin: 'java' apply plugin: 'idea' diff --git a/src/nl/astraeus/jdbc/JdbcLogger.java b/src/nl/astraeus/jdbc/JdbcLogger.java index 737e1ec..67661df 100644 --- a/src/nl/astraeus/jdbc/JdbcLogger.java +++ b/src/nl/astraeus/jdbc/JdbcLogger.java @@ -1,15 +1,16 @@ package nl.astraeus.jdbc; +import nl.astraeus.jdbc.util.Util; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.HashSet; import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.concurrent.ConcurrentHashMap; -import nl.astraeus.jdbc.util.Util; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - /** * User: riennentjes * Date: Jul 12, 2008 @@ -44,8 +45,18 @@ private boolean autoCommit; private boolean formattedQueries; private StackTraceElement[] stackTrace = null; + private Set parameters = new HashSet(); - public LogEntry(int hash, QueryType type, String sql, long milli, long nano, boolean isAutoCommit, boolean formattedQueries) { + public LogEntry( + int hash, + QueryType type, + String sql, + long milli, + long nano, + boolean isAutoCommit, + boolean formattedQueries, + Set parameters + ) { this.threadId = Thread.currentThread().getId(); this.timeStamp = System.currentTimeMillis(); this.nanoTimeStamp = System.nanoTime(); @@ -57,6 +68,7 @@ this.autoCommit = isAutoCommit; this.count = 1; this.formattedQueries = formattedQueries; + this.parameters = parameters; } public LogEntry(LogEntry le) { @@ -64,12 +76,13 @@ this.nanoTimeStamp = System.nanoTime(); this.hash = le.hash; this.type = le.type; - this.sql = le .sql; + this.sql = le.sql; this.milli = le.milli; this.nano = le.nano; this.count = le.count; this.autoCommit = le.autoCommit; this.formattedQueries = le.formattedQueries; + this.parameters = le.parameters; } public QueryType getType() { @@ -113,11 +126,11 @@ } public String getFormattedMilli() { - return Util.formatNano(milli*1000000/count); + return Util.formatNano(milli * 1000000 / count); } public String getFormattedNano() { - return Util.formatNano(nano/count); + return Util.formatNano(nano / count); } public String getTotal() { @@ -132,6 +145,23 @@ } } + public String getParameters() { + StringBuilder result = new StringBuilder(); + + if (parameters != null && !parameters.isEmpty()) { + for (Parameter parameter : parameters) { + result.append(String.format( + "%4s, %12s, %24s\n", + parameter.getIndex(), + parameter.getType(), + parameter.getDisplayValue() + )); + } + } + + return result.toString(); + } + public boolean isEndOfTransaction() { return sql.toLowerCase().trim().equals("commit") || sql.toLowerCase().trim().equals("rollback") @@ -181,11 +211,37 @@ last100.clear(); } - public void logEntry(QueryType type, String sql, long milli, long nano, boolean isAutoCommit) { + public void logEntry( + QueryType type, + String sql, + long milli, + long nano, + boolean isAutoCommit + ) { + logEntry(type, sql, milli, nano, isAutoCommit, new HashSet()); + } + + public void logEntry( + QueryType type, + String sql, + long milli, + long nano, + boolean isAutoCommit, + Set parameters + ) { int hash = sql.hashCode(); Driver.StatsLogger logger = Driver.get(port); - LogEntry entry = new LogEntry(hash, type, sql, milli, nano, isAutoCommit, logger.getSettings().isFormattedQueries()); + LogEntry entry = new LogEntry( + hash, + type, + sql, + milli, + nano, + isAutoCommit, + logger.getSettings().isFormattedQueries(), + parameters + ); if (logger.getSettings().isRecordingStacktraces()) { try { diff --git a/src/nl/astraeus/jdbc/Parameter.java b/src/nl/astraeus/jdbc/Parameter.java new file mode 100644 index 0000000..8fed9f5 --- /dev/null +++ b/src/nl/astraeus/jdbc/Parameter.java @@ -0,0 +1,118 @@ +package nl.astraeus.jdbc; + +/** + * User: rnentjes + * Date: 26-1-18 + * Time: 11:08 + */ +public class Parameter { + + public interface DisplayFunction { + String display(Object o); + } + + private static DisplayFunction valueOf = new DisplayFunction() { + public String display(Object o) { + return String.valueOf(o); + } + }; + + private static DisplayFunction label(final String label) { + return new DisplayFunction() { + public String display(Object o) { + return label; + } + }; + } + + public enum ParameterType { + NULL(new DisplayFunction() { + public String display(Object o) { + return "NULL"; + } + }), + BOOLEAN(valueOf), + INT(valueOf), + LONG(valueOf), + STRING(new DisplayFunction() { + public String display(Object o) { + return (String)o; + } + }), + BLOB(valueOf), + CLOB(valueOf), + BYTE(valueOf), + SHORT(valueOf), + FLOAT(valueOf), + DOUBLE(valueOf), + BIG_DECIMAL(valueOf), + BYTES(new DisplayFunction() { + public String display(Object o) { + return "byte["+((byte[])o).length+"]"; + } + }), + DATE(valueOf), + TIME(valueOf), + TIMESTAMP(valueOf), + ASCII_STR(label("")), + UNICODE_STR(label("")), + BIN_STR(label("")), + OBJECT(valueOf), + CHAR_STR(label("")), + REF(valueOf), + ARRAY(valueOf), + URL(valueOf), + ROW_ID(valueOf), + NSTRING(valueOf), + NCHAR_STR(label("")), + NCLOB(label("")), + SQLXML(label("")); + + private DisplayFunction display; + + ParameterType(DisplayFunction display) { + this.display = display; + } + + public String toString(Object o) { + return display.display(o); + } + } + + private int index; + private ParameterType type; + private Object value; + + public Parameter( + int index, + ParameterType type + ) { + this(index, type, null); + } + + public Parameter( + int index, + ParameterType type, + Object value + ) { + this.index = index; + this.type = type; + this.value = value; + } + + public int getIndex() { + return index; + } + + public ParameterType getType() { + return type; + } + + public Object getValue() { + return value; + } + + public String getDisplayValue() { + return type.display.display(value); + } +} diff --git a/src/nl/astraeus/jdbc/PreparedStatementLogger.java b/src/nl/astraeus/jdbc/PreparedStatementLogger.java index b7fd226..016c384 100644 --- a/src/nl/astraeus/jdbc/PreparedStatementLogger.java +++ b/src/nl/astraeus/jdbc/PreparedStatementLogger.java @@ -1,5 +1,8 @@ package nl.astraeus.jdbc; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.io.InputStream; import java.io.Reader; import java.math.BigDecimal; @@ -22,9 +25,9 @@ import java.sql.Time; import java.sql.Timestamp; import java.util.Calendar; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import java.util.Comparator; +import java.util.Set; +import java.util.TreeSet; /** * User: riennentjes @@ -43,7 +46,17 @@ private long milli; private long nano; - //private ArrayList parameters; + private Set parameters = new TreeSet(new Comparator() { + public int compare( + Parameter o1, + Parameter o2 + ) { + int x = o1.getIndex(); + int y = o2.getIndex(); + + return (x < y) ? -1 : ((x == y) ? 0 : 1); + } + }); public PreparedStatementLogger(JdbcLogger logger, PreparedStatement statement) throws SQLException { this.logger = logger; @@ -62,7 +75,7 @@ long m = System.currentTimeMillis() - milli; long n = System.nanoTime() - nano; - logger.logEntry(type, sql, m, n, autocommit); + logger.logEntry(type, sql, m, n, autocommit, parameters); } public PreparedStatementLogger(JdbcLogger logger, Connection connection, String sql) throws SQLException { @@ -242,194 +255,242 @@ public void setNull(int parameterIndex, int sqlType) throws SQLException { statement.setNull(parameterIndex, sqlType); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.NULL)); } public void setBoolean(int parameterIndex, boolean x) throws SQLException { statement.setBoolean(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.BOOLEAN, x)); } public void setByte(int parameterIndex, byte x) throws SQLException { statement.setByte(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.BYTE, x)); } public void setShort(int parameterIndex, short x) throws SQLException { statement.setShort(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.SHORT, x)); } public void setInt(int parameterIndex, int x) throws SQLException { statement.setInt(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.INT, x)); } public void setLong(int parameterIndex, long x) throws SQLException { statement.setLong(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.LONG, x)); } public void setFloat(int parameterIndex, float x) throws SQLException { statement.setFloat(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.FLOAT, x)); } public void setDouble(int parameterIndex, double x) throws SQLException { statement.setDouble(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.DOUBLE, x)); } public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException { statement.setBigDecimal(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.BIG_DECIMAL, x)); } public void setString(int parameterIndex, String x) throws SQLException { statement.setString(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.STRING, x)); } public void setBytes(int parameterIndex, byte x[]) throws SQLException { statement.setBytes(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.BYTES, x)); } public void setDate(int parameterIndex, Date x) throws SQLException { statement.setDate(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.DATE, x)); } public void setTime(int parameterIndex, Time x) throws SQLException { statement.setTime(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.TIME, x)); } public void setTimestamp(int parameterIndex, Timestamp x) throws SQLException { statement.setTimestamp(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.TIMESTAMP, x)); } public void setAsciiStream(int parameterIndex, InputStream x, int length) throws SQLException { statement.setAsciiStream(parameterIndex, x, length); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.ASCII_STR)); } public void setUnicodeStream(int parameterIndex, InputStream x, int length) throws SQLException { statement.setUnicodeStream(parameterIndex, x, length); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.UNICODE_STR)); } public void setBinaryStream(int parameterIndex, InputStream x, int length) throws SQLException { statement.setBinaryStream(parameterIndex, x, length); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.BIN_STR)); } public void setObject(int parameterIndex, Object x, int targetSqlType) throws SQLException { statement.setObject(parameterIndex, x, targetSqlType); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.OBJECT, x)); } public void setObject(int parameterIndex, Object x) throws SQLException { statement.setObject(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.OBJECT, x)); } public void setCharacterStream(int parameterIndex, Reader reader, int length) throws SQLException { statement.setCharacterStream(parameterIndex, reader, length); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.CHAR_STR, reader)); } public void setRef(int parameterIndex, Ref x) throws SQLException { statement.setRef(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.REF, x)); } public void setBlob(int parameterIndex, Blob x) throws SQLException { statement.setBlob(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.BLOB, x)); } public void setClob(int parameterIndex, Clob x) throws SQLException { statement.setClob(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.CLOB, x)); } public void setArray(int parameterIndex, Array x) throws SQLException { statement.setArray(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.ARRAY, x)); } public void setDate(int parameterIndex, Date x, Calendar cal) throws SQLException { statement.setDate(parameterIndex, x, cal); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.DATE, x)); } public void setTime(int parameterIndex, Time x, Calendar cal) throws SQLException { statement.setTime(parameterIndex, x, cal); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.TIME, x)); } public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal) throws SQLException { statement.setTimestamp(parameterIndex, x, cal); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.TIMESTAMP, x)); } public void setNull(int parameterIndex, int sqlType, String typeName) throws SQLException { statement.setNull(parameterIndex, sqlType, typeName); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.NULL)); } public void setURL(int parameterIndex, URL x) throws SQLException { statement.setURL(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.URL, x)); } public void setRowId(int parameterIndex, RowId x) throws SQLException { statement.setRowId(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.ROW_ID, x)); } public void setNString(int parameterIndex, String value) throws SQLException { statement.setNString(parameterIndex, value); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.NSTRING, value)); } public void setNCharacterStream(int parameterIndex, Reader value, long length) throws SQLException { statement.setNCharacterStream(parameterIndex, value, length); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.NCHAR_STR, value)); } public void setNClob(int parameterIndex, NClob value) throws SQLException { statement.setNClob(parameterIndex, value); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.NCLOB, value)); } public void setClob(int parameterIndex, Reader reader, long length) throws SQLException { statement.setClob(parameterIndex, reader, length); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.CLOB, reader)); } public void setBlob(int parameterIndex, InputStream inputStream, long length) throws SQLException { statement.setBlob(parameterIndex, inputStream, length); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.BLOB)); } public void setNClob(int parameterIndex, Reader reader, long length) throws SQLException { statement.setNClob(parameterIndex, reader, length); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.NCLOB)); } public void setSQLXML(int parameterIndex, SQLXML xmlObject) throws SQLException { statement.setSQLXML(parameterIndex, xmlObject); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.SQLXML)); } public void setObject(int parameterIndex, Object x, int targetSqlType, int scaleOrLength) throws SQLException { statement.setObject(parameterIndex, x, targetSqlType, scaleOrLength); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.OBJECT, x)); } public void setAsciiStream(int parameterIndex, InputStream x, long length) throws SQLException { statement.setAsciiStream(parameterIndex, x, length); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.ASCII_STR)); } public void setBinaryStream(int parameterIndex, InputStream x, long length) throws SQLException { statement.setBinaryStream(parameterIndex, x, length); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.BIN_STR)); } public void setCharacterStream(int parameterIndex, Reader reader, long length) throws SQLException { statement.setCharacterStream(parameterIndex, reader, length); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.CHAR_STR)); } public void setAsciiStream(int parameterIndex, InputStream x) throws SQLException { statement.setAsciiStream(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.ASCII_STR)); } public void setBinaryStream(int parameterIndex, InputStream x) throws SQLException { statement.setBinaryStream(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.BIN_STR)); } public void setCharacterStream(int parameterIndex, Reader reader) throws SQLException { statement.setCharacterStream(parameterIndex, reader); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.CHAR_STR)); } public void setNCharacterStream(int parameterIndex, Reader value) throws SQLException { statement.setNCharacterStream(parameterIndex, value); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.NCHAR_STR)); } public void setClob(int parameterIndex, Reader reader) throws SQLException { statement.setClob(parameterIndex, reader); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.CLOB)); } public void setBlob(int parameterIndex, InputStream inputStream) throws SQLException { statement.setBlob(parameterIndex, inputStream); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.BLOB)); } public void setNClob(int parameterIndex, Reader reader) throws SQLException { statement.setNClob(parameterIndex, reader); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.NCLOB)); } diff --git a/src/nl/astraeus/jdbc/web/page/HeaderPage.html b/src/nl/astraeus/jdbc/web/page/HeaderPage.html index 3788989..b4b4b2d 100644 --- a/src/nl/astraeus/jdbc/web/page/HeaderPage.html +++ b/src/nl/astraeus/jdbc/web/page/HeaderPage.html @@ -4,7 +4,7 @@ - Simple JDBC Statistics + JDBC Statistics diff --git a/src/nl/astraeus/jdbc/web/page/QueryDetail.html b/src/nl/astraeus/jdbc/web/page/QueryDetail.html index 1fe0ba7..959c057 100644 --- a/src/nl/astraeus/jdbc/web/page/QueryDetail.html +++ b/src/nl/astraeus/jdbc/web/page/QueryDetail.html @@ -52,6 +52,7 @@ Timestamp Thread id Type + Parameters Time (ms) @@ -62,6 +63,7 @@ ${q.formattedTimestamp} ${q.threadId} ${q.type.description} +
${q.parameters}
${q.total} ${/each} diff --git a/src/nl/astraeus/jdbc/web/page/QueryDetail.java b/src/nl/astraeus/jdbc/web/page/QueryDetail.java index 6eb3b54..d5aa624 100644 --- a/src/nl/astraeus/jdbc/web/page/QueryDetail.java +++ b/src/nl/astraeus/jdbc/web/page/QueryDetail.java @@ -1,5 +1,10 @@ package nl.astraeus.jdbc.web.page; +import nl.astraeus.jdbc.JdbcLogger; +import nl.astraeus.jdbc.SqlFormatter; +import nl.astraeus.jdbc.util.Util; +import nl.astraeus.jdbc.web.JdbcStatsMapping; + import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Collections; @@ -9,11 +14,6 @@ import java.util.List; import java.util.TimeZone; -import nl.astraeus.jdbc.JdbcLogger; -import nl.astraeus.jdbc.SqlFormatter; -import nl.astraeus.jdbc.util.Util; -import nl.astraeus.jdbc.web.JdbcStatsMapping; - /** * User: rnentjes * Date: 4/12/12 diff --git a/.idea/checkstyle-idea.xml b/.idea/checkstyle-idea.xml new file mode 100644 index 0000000..b6e4700 --- /dev/null +++ b/.idea/checkstyle-idea.xml @@ -0,0 +1,16 @@ + + + + + + \ No newline at end of file diff --git a/.idea/hotswap_agent.xml b/.idea/hotswap_agent.xml new file mode 100644 index 0000000..8a869d9 --- /dev/null +++ b/.idea/hotswap_agent.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/libraries/lib1.xml b/.idea/libraries/lib1.xml index 8ce9ba1..7a6f4d3 100644 --- a/.idea/libraries/lib1.xml +++ b/.idea/libraries/lib1.xml @@ -2,7 +2,6 @@ - diff --git a/.idea/modules/simple-jdbc-stats.iml b/.idea/modules/simple-jdbc-stats.iml index f17a5e9..ba2f28c 100644 --- a/.idea/modules/simple-jdbc-stats.iml +++ b/.idea/modules/simple-jdbc-stats.iml @@ -1,5 +1,5 @@ - + diff --git a/.idea/modules/simple-jdbc-stats_main.iml b/.idea/modules/simple-jdbc-stats_main.iml index 573880c..c646a2e 100644 --- a/.idea/modules/simple-jdbc-stats_main.iml +++ b/.idea/modules/simple-jdbc-stats_main.iml @@ -1,7 +1,7 @@ - + - + diff --git a/.idea/modules/simple-jdbc-stats_test.iml b/.idea/modules/simple-jdbc-stats_test.iml index 2e21d25..bac5915 100644 --- a/.idea/modules/simple-jdbc-stats_test.iml +++ b/.idea/modules/simple-jdbc-stats_test.iml @@ -1,7 +1,7 @@ - + - + diff --git a/build.gradle b/build.gradle index 04938e8..69bad54 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ group 'nl.astraeus' -version '1.5.10-SNAPSHOT' +version '1.6.0' apply plugin: 'java' apply plugin: 'idea' diff --git a/src/nl/astraeus/jdbc/JdbcLogger.java b/src/nl/astraeus/jdbc/JdbcLogger.java index 737e1ec..67661df 100644 --- a/src/nl/astraeus/jdbc/JdbcLogger.java +++ b/src/nl/astraeus/jdbc/JdbcLogger.java @@ -1,15 +1,16 @@ package nl.astraeus.jdbc; +import nl.astraeus.jdbc.util.Util; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.HashSet; import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.concurrent.ConcurrentHashMap; -import nl.astraeus.jdbc.util.Util; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - /** * User: riennentjes * Date: Jul 12, 2008 @@ -44,8 +45,18 @@ private boolean autoCommit; private boolean formattedQueries; private StackTraceElement[] stackTrace = null; + private Set parameters = new HashSet(); - public LogEntry(int hash, QueryType type, String sql, long milli, long nano, boolean isAutoCommit, boolean formattedQueries) { + public LogEntry( + int hash, + QueryType type, + String sql, + long milli, + long nano, + boolean isAutoCommit, + boolean formattedQueries, + Set parameters + ) { this.threadId = Thread.currentThread().getId(); this.timeStamp = System.currentTimeMillis(); this.nanoTimeStamp = System.nanoTime(); @@ -57,6 +68,7 @@ this.autoCommit = isAutoCommit; this.count = 1; this.formattedQueries = formattedQueries; + this.parameters = parameters; } public LogEntry(LogEntry le) { @@ -64,12 +76,13 @@ this.nanoTimeStamp = System.nanoTime(); this.hash = le.hash; this.type = le.type; - this.sql = le .sql; + this.sql = le.sql; this.milli = le.milli; this.nano = le.nano; this.count = le.count; this.autoCommit = le.autoCommit; this.formattedQueries = le.formattedQueries; + this.parameters = le.parameters; } public QueryType getType() { @@ -113,11 +126,11 @@ } public String getFormattedMilli() { - return Util.formatNano(milli*1000000/count); + return Util.formatNano(milli * 1000000 / count); } public String getFormattedNano() { - return Util.formatNano(nano/count); + return Util.formatNano(nano / count); } public String getTotal() { @@ -132,6 +145,23 @@ } } + public String getParameters() { + StringBuilder result = new StringBuilder(); + + if (parameters != null && !parameters.isEmpty()) { + for (Parameter parameter : parameters) { + result.append(String.format( + "%4s, %12s, %24s\n", + parameter.getIndex(), + parameter.getType(), + parameter.getDisplayValue() + )); + } + } + + return result.toString(); + } + public boolean isEndOfTransaction() { return sql.toLowerCase().trim().equals("commit") || sql.toLowerCase().trim().equals("rollback") @@ -181,11 +211,37 @@ last100.clear(); } - public void logEntry(QueryType type, String sql, long milli, long nano, boolean isAutoCommit) { + public void logEntry( + QueryType type, + String sql, + long milli, + long nano, + boolean isAutoCommit + ) { + logEntry(type, sql, milli, nano, isAutoCommit, new HashSet()); + } + + public void logEntry( + QueryType type, + String sql, + long milli, + long nano, + boolean isAutoCommit, + Set parameters + ) { int hash = sql.hashCode(); Driver.StatsLogger logger = Driver.get(port); - LogEntry entry = new LogEntry(hash, type, sql, milli, nano, isAutoCommit, logger.getSettings().isFormattedQueries()); + LogEntry entry = new LogEntry( + hash, + type, + sql, + milli, + nano, + isAutoCommit, + logger.getSettings().isFormattedQueries(), + parameters + ); if (logger.getSettings().isRecordingStacktraces()) { try { diff --git a/src/nl/astraeus/jdbc/Parameter.java b/src/nl/astraeus/jdbc/Parameter.java new file mode 100644 index 0000000..8fed9f5 --- /dev/null +++ b/src/nl/astraeus/jdbc/Parameter.java @@ -0,0 +1,118 @@ +package nl.astraeus.jdbc; + +/** + * User: rnentjes + * Date: 26-1-18 + * Time: 11:08 + */ +public class Parameter { + + public interface DisplayFunction { + String display(Object o); + } + + private static DisplayFunction valueOf = new DisplayFunction() { + public String display(Object o) { + return String.valueOf(o); + } + }; + + private static DisplayFunction label(final String label) { + return new DisplayFunction() { + public String display(Object o) { + return label; + } + }; + } + + public enum ParameterType { + NULL(new DisplayFunction() { + public String display(Object o) { + return "NULL"; + } + }), + BOOLEAN(valueOf), + INT(valueOf), + LONG(valueOf), + STRING(new DisplayFunction() { + public String display(Object o) { + return (String)o; + } + }), + BLOB(valueOf), + CLOB(valueOf), + BYTE(valueOf), + SHORT(valueOf), + FLOAT(valueOf), + DOUBLE(valueOf), + BIG_DECIMAL(valueOf), + BYTES(new DisplayFunction() { + public String display(Object o) { + return "byte["+((byte[])o).length+"]"; + } + }), + DATE(valueOf), + TIME(valueOf), + TIMESTAMP(valueOf), + ASCII_STR(label("")), + UNICODE_STR(label("")), + BIN_STR(label("")), + OBJECT(valueOf), + CHAR_STR(label("")), + REF(valueOf), + ARRAY(valueOf), + URL(valueOf), + ROW_ID(valueOf), + NSTRING(valueOf), + NCHAR_STR(label("")), + NCLOB(label("")), + SQLXML(label("")); + + private DisplayFunction display; + + ParameterType(DisplayFunction display) { + this.display = display; + } + + public String toString(Object o) { + return display.display(o); + } + } + + private int index; + private ParameterType type; + private Object value; + + public Parameter( + int index, + ParameterType type + ) { + this(index, type, null); + } + + public Parameter( + int index, + ParameterType type, + Object value + ) { + this.index = index; + this.type = type; + this.value = value; + } + + public int getIndex() { + return index; + } + + public ParameterType getType() { + return type; + } + + public Object getValue() { + return value; + } + + public String getDisplayValue() { + return type.display.display(value); + } +} diff --git a/src/nl/astraeus/jdbc/PreparedStatementLogger.java b/src/nl/astraeus/jdbc/PreparedStatementLogger.java index b7fd226..016c384 100644 --- a/src/nl/astraeus/jdbc/PreparedStatementLogger.java +++ b/src/nl/astraeus/jdbc/PreparedStatementLogger.java @@ -1,5 +1,8 @@ package nl.astraeus.jdbc; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.io.InputStream; import java.io.Reader; import java.math.BigDecimal; @@ -22,9 +25,9 @@ import java.sql.Time; import java.sql.Timestamp; import java.util.Calendar; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import java.util.Comparator; +import java.util.Set; +import java.util.TreeSet; /** * User: riennentjes @@ -43,7 +46,17 @@ private long milli; private long nano; - //private ArrayList parameters; + private Set parameters = new TreeSet(new Comparator() { + public int compare( + Parameter o1, + Parameter o2 + ) { + int x = o1.getIndex(); + int y = o2.getIndex(); + + return (x < y) ? -1 : ((x == y) ? 0 : 1); + } + }); public PreparedStatementLogger(JdbcLogger logger, PreparedStatement statement) throws SQLException { this.logger = logger; @@ -62,7 +75,7 @@ long m = System.currentTimeMillis() - milli; long n = System.nanoTime() - nano; - logger.logEntry(type, sql, m, n, autocommit); + logger.logEntry(type, sql, m, n, autocommit, parameters); } public PreparedStatementLogger(JdbcLogger logger, Connection connection, String sql) throws SQLException { @@ -242,194 +255,242 @@ public void setNull(int parameterIndex, int sqlType) throws SQLException { statement.setNull(parameterIndex, sqlType); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.NULL)); } public void setBoolean(int parameterIndex, boolean x) throws SQLException { statement.setBoolean(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.BOOLEAN, x)); } public void setByte(int parameterIndex, byte x) throws SQLException { statement.setByte(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.BYTE, x)); } public void setShort(int parameterIndex, short x) throws SQLException { statement.setShort(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.SHORT, x)); } public void setInt(int parameterIndex, int x) throws SQLException { statement.setInt(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.INT, x)); } public void setLong(int parameterIndex, long x) throws SQLException { statement.setLong(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.LONG, x)); } public void setFloat(int parameterIndex, float x) throws SQLException { statement.setFloat(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.FLOAT, x)); } public void setDouble(int parameterIndex, double x) throws SQLException { statement.setDouble(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.DOUBLE, x)); } public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException { statement.setBigDecimal(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.BIG_DECIMAL, x)); } public void setString(int parameterIndex, String x) throws SQLException { statement.setString(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.STRING, x)); } public void setBytes(int parameterIndex, byte x[]) throws SQLException { statement.setBytes(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.BYTES, x)); } public void setDate(int parameterIndex, Date x) throws SQLException { statement.setDate(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.DATE, x)); } public void setTime(int parameterIndex, Time x) throws SQLException { statement.setTime(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.TIME, x)); } public void setTimestamp(int parameterIndex, Timestamp x) throws SQLException { statement.setTimestamp(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.TIMESTAMP, x)); } public void setAsciiStream(int parameterIndex, InputStream x, int length) throws SQLException { statement.setAsciiStream(parameterIndex, x, length); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.ASCII_STR)); } public void setUnicodeStream(int parameterIndex, InputStream x, int length) throws SQLException { statement.setUnicodeStream(parameterIndex, x, length); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.UNICODE_STR)); } public void setBinaryStream(int parameterIndex, InputStream x, int length) throws SQLException { statement.setBinaryStream(parameterIndex, x, length); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.BIN_STR)); } public void setObject(int parameterIndex, Object x, int targetSqlType) throws SQLException { statement.setObject(parameterIndex, x, targetSqlType); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.OBJECT, x)); } public void setObject(int parameterIndex, Object x) throws SQLException { statement.setObject(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.OBJECT, x)); } public void setCharacterStream(int parameterIndex, Reader reader, int length) throws SQLException { statement.setCharacterStream(parameterIndex, reader, length); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.CHAR_STR, reader)); } public void setRef(int parameterIndex, Ref x) throws SQLException { statement.setRef(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.REF, x)); } public void setBlob(int parameterIndex, Blob x) throws SQLException { statement.setBlob(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.BLOB, x)); } public void setClob(int parameterIndex, Clob x) throws SQLException { statement.setClob(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.CLOB, x)); } public void setArray(int parameterIndex, Array x) throws SQLException { statement.setArray(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.ARRAY, x)); } public void setDate(int parameterIndex, Date x, Calendar cal) throws SQLException { statement.setDate(parameterIndex, x, cal); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.DATE, x)); } public void setTime(int parameterIndex, Time x, Calendar cal) throws SQLException { statement.setTime(parameterIndex, x, cal); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.TIME, x)); } public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal) throws SQLException { statement.setTimestamp(parameterIndex, x, cal); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.TIMESTAMP, x)); } public void setNull(int parameterIndex, int sqlType, String typeName) throws SQLException { statement.setNull(parameterIndex, sqlType, typeName); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.NULL)); } public void setURL(int parameterIndex, URL x) throws SQLException { statement.setURL(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.URL, x)); } public void setRowId(int parameterIndex, RowId x) throws SQLException { statement.setRowId(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.ROW_ID, x)); } public void setNString(int parameterIndex, String value) throws SQLException { statement.setNString(parameterIndex, value); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.NSTRING, value)); } public void setNCharacterStream(int parameterIndex, Reader value, long length) throws SQLException { statement.setNCharacterStream(parameterIndex, value, length); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.NCHAR_STR, value)); } public void setNClob(int parameterIndex, NClob value) throws SQLException { statement.setNClob(parameterIndex, value); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.NCLOB, value)); } public void setClob(int parameterIndex, Reader reader, long length) throws SQLException { statement.setClob(parameterIndex, reader, length); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.CLOB, reader)); } public void setBlob(int parameterIndex, InputStream inputStream, long length) throws SQLException { statement.setBlob(parameterIndex, inputStream, length); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.BLOB)); } public void setNClob(int parameterIndex, Reader reader, long length) throws SQLException { statement.setNClob(parameterIndex, reader, length); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.NCLOB)); } public void setSQLXML(int parameterIndex, SQLXML xmlObject) throws SQLException { statement.setSQLXML(parameterIndex, xmlObject); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.SQLXML)); } public void setObject(int parameterIndex, Object x, int targetSqlType, int scaleOrLength) throws SQLException { statement.setObject(parameterIndex, x, targetSqlType, scaleOrLength); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.OBJECT, x)); } public void setAsciiStream(int parameterIndex, InputStream x, long length) throws SQLException { statement.setAsciiStream(parameterIndex, x, length); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.ASCII_STR)); } public void setBinaryStream(int parameterIndex, InputStream x, long length) throws SQLException { statement.setBinaryStream(parameterIndex, x, length); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.BIN_STR)); } public void setCharacterStream(int parameterIndex, Reader reader, long length) throws SQLException { statement.setCharacterStream(parameterIndex, reader, length); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.CHAR_STR)); } public void setAsciiStream(int parameterIndex, InputStream x) throws SQLException { statement.setAsciiStream(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.ASCII_STR)); } public void setBinaryStream(int parameterIndex, InputStream x) throws SQLException { statement.setBinaryStream(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.BIN_STR)); } public void setCharacterStream(int parameterIndex, Reader reader) throws SQLException { statement.setCharacterStream(parameterIndex, reader); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.CHAR_STR)); } public void setNCharacterStream(int parameterIndex, Reader value) throws SQLException { statement.setNCharacterStream(parameterIndex, value); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.NCHAR_STR)); } public void setClob(int parameterIndex, Reader reader) throws SQLException { statement.setClob(parameterIndex, reader); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.CLOB)); } public void setBlob(int parameterIndex, InputStream inputStream) throws SQLException { statement.setBlob(parameterIndex, inputStream); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.BLOB)); } public void setNClob(int parameterIndex, Reader reader) throws SQLException { statement.setNClob(parameterIndex, reader); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.NCLOB)); } diff --git a/src/nl/astraeus/jdbc/web/page/HeaderPage.html b/src/nl/astraeus/jdbc/web/page/HeaderPage.html index 3788989..b4b4b2d 100644 --- a/src/nl/astraeus/jdbc/web/page/HeaderPage.html +++ b/src/nl/astraeus/jdbc/web/page/HeaderPage.html @@ -4,7 +4,7 @@ - Simple JDBC Statistics + JDBC Statistics diff --git a/src/nl/astraeus/jdbc/web/page/QueryDetail.html b/src/nl/astraeus/jdbc/web/page/QueryDetail.html index 1fe0ba7..959c057 100644 --- a/src/nl/astraeus/jdbc/web/page/QueryDetail.html +++ b/src/nl/astraeus/jdbc/web/page/QueryDetail.html @@ -52,6 +52,7 @@ Timestamp Thread id Type + Parameters Time (ms) @@ -62,6 +63,7 @@ ${q.formattedTimestamp} ${q.threadId} ${q.type.description} +
${q.parameters}
${q.total} ${/each} diff --git a/src/nl/astraeus/jdbc/web/page/QueryDetail.java b/src/nl/astraeus/jdbc/web/page/QueryDetail.java index 6eb3b54..d5aa624 100644 --- a/src/nl/astraeus/jdbc/web/page/QueryDetail.java +++ b/src/nl/astraeus/jdbc/web/page/QueryDetail.java @@ -1,5 +1,10 @@ package nl.astraeus.jdbc.web.page; +import nl.astraeus.jdbc.JdbcLogger; +import nl.astraeus.jdbc.SqlFormatter; +import nl.astraeus.jdbc.util.Util; +import nl.astraeus.jdbc.web.JdbcStatsMapping; + import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Collections; @@ -9,11 +14,6 @@ import java.util.List; import java.util.TimeZone; -import nl.astraeus.jdbc.JdbcLogger; -import nl.astraeus.jdbc.SqlFormatter; -import nl.astraeus.jdbc.util.Util; -import nl.astraeus.jdbc.web.JdbcStatsMapping; - /** * User: rnentjes * Date: 4/12/12 diff --git a/src/nl/astraeus/jdbc/web/page/QueryOverview.html b/src/nl/astraeus/jdbc/web/page/QueryOverview.html index a863ff7..2c758d4 100644 --- a/src/nl/astraeus/jdbc/web/page/QueryOverview.html +++ b/src/nl/astraeus/jdbc/web/page/QueryOverview.html @@ -51,6 +51,9 @@ # Calls ${/if} Sql + ${if(sortLast100)} + Parameters + ${/if} @@ -67,6 +70,9 @@ ${q.count} ${/if}
${!q.sql}
+ ${if(sortLast100)} +
${q.parameters}
+ ${/if} ${/each} diff --git a/.idea/checkstyle-idea.xml b/.idea/checkstyle-idea.xml new file mode 100644 index 0000000..b6e4700 --- /dev/null +++ b/.idea/checkstyle-idea.xml @@ -0,0 +1,16 @@ + + + + + + \ No newline at end of file diff --git a/.idea/hotswap_agent.xml b/.idea/hotswap_agent.xml new file mode 100644 index 0000000..8a869d9 --- /dev/null +++ b/.idea/hotswap_agent.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/libraries/lib1.xml b/.idea/libraries/lib1.xml index 8ce9ba1..7a6f4d3 100644 --- a/.idea/libraries/lib1.xml +++ b/.idea/libraries/lib1.xml @@ -2,7 +2,6 @@ - diff --git a/.idea/modules/simple-jdbc-stats.iml b/.idea/modules/simple-jdbc-stats.iml index f17a5e9..ba2f28c 100644 --- a/.idea/modules/simple-jdbc-stats.iml +++ b/.idea/modules/simple-jdbc-stats.iml @@ -1,5 +1,5 @@ - + diff --git a/.idea/modules/simple-jdbc-stats_main.iml b/.idea/modules/simple-jdbc-stats_main.iml index 573880c..c646a2e 100644 --- a/.idea/modules/simple-jdbc-stats_main.iml +++ b/.idea/modules/simple-jdbc-stats_main.iml @@ -1,7 +1,7 @@ - + - + diff --git a/.idea/modules/simple-jdbc-stats_test.iml b/.idea/modules/simple-jdbc-stats_test.iml index 2e21d25..bac5915 100644 --- a/.idea/modules/simple-jdbc-stats_test.iml +++ b/.idea/modules/simple-jdbc-stats_test.iml @@ -1,7 +1,7 @@ - + - + diff --git a/build.gradle b/build.gradle index 04938e8..69bad54 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ group 'nl.astraeus' -version '1.5.10-SNAPSHOT' +version '1.6.0' apply plugin: 'java' apply plugin: 'idea' diff --git a/src/nl/astraeus/jdbc/JdbcLogger.java b/src/nl/astraeus/jdbc/JdbcLogger.java index 737e1ec..67661df 100644 --- a/src/nl/astraeus/jdbc/JdbcLogger.java +++ b/src/nl/astraeus/jdbc/JdbcLogger.java @@ -1,15 +1,16 @@ package nl.astraeus.jdbc; +import nl.astraeus.jdbc.util.Util; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.HashSet; import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.concurrent.ConcurrentHashMap; -import nl.astraeus.jdbc.util.Util; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - /** * User: riennentjes * Date: Jul 12, 2008 @@ -44,8 +45,18 @@ private boolean autoCommit; private boolean formattedQueries; private StackTraceElement[] stackTrace = null; + private Set parameters = new HashSet(); - public LogEntry(int hash, QueryType type, String sql, long milli, long nano, boolean isAutoCommit, boolean formattedQueries) { + public LogEntry( + int hash, + QueryType type, + String sql, + long milli, + long nano, + boolean isAutoCommit, + boolean formattedQueries, + Set parameters + ) { this.threadId = Thread.currentThread().getId(); this.timeStamp = System.currentTimeMillis(); this.nanoTimeStamp = System.nanoTime(); @@ -57,6 +68,7 @@ this.autoCommit = isAutoCommit; this.count = 1; this.formattedQueries = formattedQueries; + this.parameters = parameters; } public LogEntry(LogEntry le) { @@ -64,12 +76,13 @@ this.nanoTimeStamp = System.nanoTime(); this.hash = le.hash; this.type = le.type; - this.sql = le .sql; + this.sql = le.sql; this.milli = le.milli; this.nano = le.nano; this.count = le.count; this.autoCommit = le.autoCommit; this.formattedQueries = le.formattedQueries; + this.parameters = le.parameters; } public QueryType getType() { @@ -113,11 +126,11 @@ } public String getFormattedMilli() { - return Util.formatNano(milli*1000000/count); + return Util.formatNano(milli * 1000000 / count); } public String getFormattedNano() { - return Util.formatNano(nano/count); + return Util.formatNano(nano / count); } public String getTotal() { @@ -132,6 +145,23 @@ } } + public String getParameters() { + StringBuilder result = new StringBuilder(); + + if (parameters != null && !parameters.isEmpty()) { + for (Parameter parameter : parameters) { + result.append(String.format( + "%4s, %12s, %24s\n", + parameter.getIndex(), + parameter.getType(), + parameter.getDisplayValue() + )); + } + } + + return result.toString(); + } + public boolean isEndOfTransaction() { return sql.toLowerCase().trim().equals("commit") || sql.toLowerCase().trim().equals("rollback") @@ -181,11 +211,37 @@ last100.clear(); } - public void logEntry(QueryType type, String sql, long milli, long nano, boolean isAutoCommit) { + public void logEntry( + QueryType type, + String sql, + long milli, + long nano, + boolean isAutoCommit + ) { + logEntry(type, sql, milli, nano, isAutoCommit, new HashSet()); + } + + public void logEntry( + QueryType type, + String sql, + long milli, + long nano, + boolean isAutoCommit, + Set parameters + ) { int hash = sql.hashCode(); Driver.StatsLogger logger = Driver.get(port); - LogEntry entry = new LogEntry(hash, type, sql, milli, nano, isAutoCommit, logger.getSettings().isFormattedQueries()); + LogEntry entry = new LogEntry( + hash, + type, + sql, + milli, + nano, + isAutoCommit, + logger.getSettings().isFormattedQueries(), + parameters + ); if (logger.getSettings().isRecordingStacktraces()) { try { diff --git a/src/nl/astraeus/jdbc/Parameter.java b/src/nl/astraeus/jdbc/Parameter.java new file mode 100644 index 0000000..8fed9f5 --- /dev/null +++ b/src/nl/astraeus/jdbc/Parameter.java @@ -0,0 +1,118 @@ +package nl.astraeus.jdbc; + +/** + * User: rnentjes + * Date: 26-1-18 + * Time: 11:08 + */ +public class Parameter { + + public interface DisplayFunction { + String display(Object o); + } + + private static DisplayFunction valueOf = new DisplayFunction() { + public String display(Object o) { + return String.valueOf(o); + } + }; + + private static DisplayFunction label(final String label) { + return new DisplayFunction() { + public String display(Object o) { + return label; + } + }; + } + + public enum ParameterType { + NULL(new DisplayFunction() { + public String display(Object o) { + return "NULL"; + } + }), + BOOLEAN(valueOf), + INT(valueOf), + LONG(valueOf), + STRING(new DisplayFunction() { + public String display(Object o) { + return (String)o; + } + }), + BLOB(valueOf), + CLOB(valueOf), + BYTE(valueOf), + SHORT(valueOf), + FLOAT(valueOf), + DOUBLE(valueOf), + BIG_DECIMAL(valueOf), + BYTES(new DisplayFunction() { + public String display(Object o) { + return "byte["+((byte[])o).length+"]"; + } + }), + DATE(valueOf), + TIME(valueOf), + TIMESTAMP(valueOf), + ASCII_STR(label("")), + UNICODE_STR(label("")), + BIN_STR(label("")), + OBJECT(valueOf), + CHAR_STR(label("")), + REF(valueOf), + ARRAY(valueOf), + URL(valueOf), + ROW_ID(valueOf), + NSTRING(valueOf), + NCHAR_STR(label("")), + NCLOB(label("")), + SQLXML(label("")); + + private DisplayFunction display; + + ParameterType(DisplayFunction display) { + this.display = display; + } + + public String toString(Object o) { + return display.display(o); + } + } + + private int index; + private ParameterType type; + private Object value; + + public Parameter( + int index, + ParameterType type + ) { + this(index, type, null); + } + + public Parameter( + int index, + ParameterType type, + Object value + ) { + this.index = index; + this.type = type; + this.value = value; + } + + public int getIndex() { + return index; + } + + public ParameterType getType() { + return type; + } + + public Object getValue() { + return value; + } + + public String getDisplayValue() { + return type.display.display(value); + } +} diff --git a/src/nl/astraeus/jdbc/PreparedStatementLogger.java b/src/nl/astraeus/jdbc/PreparedStatementLogger.java index b7fd226..016c384 100644 --- a/src/nl/astraeus/jdbc/PreparedStatementLogger.java +++ b/src/nl/astraeus/jdbc/PreparedStatementLogger.java @@ -1,5 +1,8 @@ package nl.astraeus.jdbc; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.io.InputStream; import java.io.Reader; import java.math.BigDecimal; @@ -22,9 +25,9 @@ import java.sql.Time; import java.sql.Timestamp; import java.util.Calendar; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import java.util.Comparator; +import java.util.Set; +import java.util.TreeSet; /** * User: riennentjes @@ -43,7 +46,17 @@ private long milli; private long nano; - //private ArrayList parameters; + private Set parameters = new TreeSet(new Comparator() { + public int compare( + Parameter o1, + Parameter o2 + ) { + int x = o1.getIndex(); + int y = o2.getIndex(); + + return (x < y) ? -1 : ((x == y) ? 0 : 1); + } + }); public PreparedStatementLogger(JdbcLogger logger, PreparedStatement statement) throws SQLException { this.logger = logger; @@ -62,7 +75,7 @@ long m = System.currentTimeMillis() - milli; long n = System.nanoTime() - nano; - logger.logEntry(type, sql, m, n, autocommit); + logger.logEntry(type, sql, m, n, autocommit, parameters); } public PreparedStatementLogger(JdbcLogger logger, Connection connection, String sql) throws SQLException { @@ -242,194 +255,242 @@ public void setNull(int parameterIndex, int sqlType) throws SQLException { statement.setNull(parameterIndex, sqlType); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.NULL)); } public void setBoolean(int parameterIndex, boolean x) throws SQLException { statement.setBoolean(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.BOOLEAN, x)); } public void setByte(int parameterIndex, byte x) throws SQLException { statement.setByte(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.BYTE, x)); } public void setShort(int parameterIndex, short x) throws SQLException { statement.setShort(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.SHORT, x)); } public void setInt(int parameterIndex, int x) throws SQLException { statement.setInt(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.INT, x)); } public void setLong(int parameterIndex, long x) throws SQLException { statement.setLong(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.LONG, x)); } public void setFloat(int parameterIndex, float x) throws SQLException { statement.setFloat(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.FLOAT, x)); } public void setDouble(int parameterIndex, double x) throws SQLException { statement.setDouble(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.DOUBLE, x)); } public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException { statement.setBigDecimal(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.BIG_DECIMAL, x)); } public void setString(int parameterIndex, String x) throws SQLException { statement.setString(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.STRING, x)); } public void setBytes(int parameterIndex, byte x[]) throws SQLException { statement.setBytes(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.BYTES, x)); } public void setDate(int parameterIndex, Date x) throws SQLException { statement.setDate(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.DATE, x)); } public void setTime(int parameterIndex, Time x) throws SQLException { statement.setTime(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.TIME, x)); } public void setTimestamp(int parameterIndex, Timestamp x) throws SQLException { statement.setTimestamp(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.TIMESTAMP, x)); } public void setAsciiStream(int parameterIndex, InputStream x, int length) throws SQLException { statement.setAsciiStream(parameterIndex, x, length); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.ASCII_STR)); } public void setUnicodeStream(int parameterIndex, InputStream x, int length) throws SQLException { statement.setUnicodeStream(parameterIndex, x, length); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.UNICODE_STR)); } public void setBinaryStream(int parameterIndex, InputStream x, int length) throws SQLException { statement.setBinaryStream(parameterIndex, x, length); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.BIN_STR)); } public void setObject(int parameterIndex, Object x, int targetSqlType) throws SQLException { statement.setObject(parameterIndex, x, targetSqlType); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.OBJECT, x)); } public void setObject(int parameterIndex, Object x) throws SQLException { statement.setObject(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.OBJECT, x)); } public void setCharacterStream(int parameterIndex, Reader reader, int length) throws SQLException { statement.setCharacterStream(parameterIndex, reader, length); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.CHAR_STR, reader)); } public void setRef(int parameterIndex, Ref x) throws SQLException { statement.setRef(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.REF, x)); } public void setBlob(int parameterIndex, Blob x) throws SQLException { statement.setBlob(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.BLOB, x)); } public void setClob(int parameterIndex, Clob x) throws SQLException { statement.setClob(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.CLOB, x)); } public void setArray(int parameterIndex, Array x) throws SQLException { statement.setArray(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.ARRAY, x)); } public void setDate(int parameterIndex, Date x, Calendar cal) throws SQLException { statement.setDate(parameterIndex, x, cal); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.DATE, x)); } public void setTime(int parameterIndex, Time x, Calendar cal) throws SQLException { statement.setTime(parameterIndex, x, cal); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.TIME, x)); } public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal) throws SQLException { statement.setTimestamp(parameterIndex, x, cal); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.TIMESTAMP, x)); } public void setNull(int parameterIndex, int sqlType, String typeName) throws SQLException { statement.setNull(parameterIndex, sqlType, typeName); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.NULL)); } public void setURL(int parameterIndex, URL x) throws SQLException { statement.setURL(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.URL, x)); } public void setRowId(int parameterIndex, RowId x) throws SQLException { statement.setRowId(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.ROW_ID, x)); } public void setNString(int parameterIndex, String value) throws SQLException { statement.setNString(parameterIndex, value); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.NSTRING, value)); } public void setNCharacterStream(int parameterIndex, Reader value, long length) throws SQLException { statement.setNCharacterStream(parameterIndex, value, length); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.NCHAR_STR, value)); } public void setNClob(int parameterIndex, NClob value) throws SQLException { statement.setNClob(parameterIndex, value); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.NCLOB, value)); } public void setClob(int parameterIndex, Reader reader, long length) throws SQLException { statement.setClob(parameterIndex, reader, length); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.CLOB, reader)); } public void setBlob(int parameterIndex, InputStream inputStream, long length) throws SQLException { statement.setBlob(parameterIndex, inputStream, length); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.BLOB)); } public void setNClob(int parameterIndex, Reader reader, long length) throws SQLException { statement.setNClob(parameterIndex, reader, length); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.NCLOB)); } public void setSQLXML(int parameterIndex, SQLXML xmlObject) throws SQLException { statement.setSQLXML(parameterIndex, xmlObject); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.SQLXML)); } public void setObject(int parameterIndex, Object x, int targetSqlType, int scaleOrLength) throws SQLException { statement.setObject(parameterIndex, x, targetSqlType, scaleOrLength); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.OBJECT, x)); } public void setAsciiStream(int parameterIndex, InputStream x, long length) throws SQLException { statement.setAsciiStream(parameterIndex, x, length); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.ASCII_STR)); } public void setBinaryStream(int parameterIndex, InputStream x, long length) throws SQLException { statement.setBinaryStream(parameterIndex, x, length); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.BIN_STR)); } public void setCharacterStream(int parameterIndex, Reader reader, long length) throws SQLException { statement.setCharacterStream(parameterIndex, reader, length); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.CHAR_STR)); } public void setAsciiStream(int parameterIndex, InputStream x) throws SQLException { statement.setAsciiStream(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.ASCII_STR)); } public void setBinaryStream(int parameterIndex, InputStream x) throws SQLException { statement.setBinaryStream(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.BIN_STR)); } public void setCharacterStream(int parameterIndex, Reader reader) throws SQLException { statement.setCharacterStream(parameterIndex, reader); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.CHAR_STR)); } public void setNCharacterStream(int parameterIndex, Reader value) throws SQLException { statement.setNCharacterStream(parameterIndex, value); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.NCHAR_STR)); } public void setClob(int parameterIndex, Reader reader) throws SQLException { statement.setClob(parameterIndex, reader); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.CLOB)); } public void setBlob(int parameterIndex, InputStream inputStream) throws SQLException { statement.setBlob(parameterIndex, inputStream); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.BLOB)); } public void setNClob(int parameterIndex, Reader reader) throws SQLException { statement.setNClob(parameterIndex, reader); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.NCLOB)); } diff --git a/src/nl/astraeus/jdbc/web/page/HeaderPage.html b/src/nl/astraeus/jdbc/web/page/HeaderPage.html index 3788989..b4b4b2d 100644 --- a/src/nl/astraeus/jdbc/web/page/HeaderPage.html +++ b/src/nl/astraeus/jdbc/web/page/HeaderPage.html @@ -4,7 +4,7 @@ - Simple JDBC Statistics + JDBC Statistics diff --git a/src/nl/astraeus/jdbc/web/page/QueryDetail.html b/src/nl/astraeus/jdbc/web/page/QueryDetail.html index 1fe0ba7..959c057 100644 --- a/src/nl/astraeus/jdbc/web/page/QueryDetail.html +++ b/src/nl/astraeus/jdbc/web/page/QueryDetail.html @@ -52,6 +52,7 @@ Timestamp Thread id Type + Parameters Time (ms) @@ -62,6 +63,7 @@ ${q.formattedTimestamp} ${q.threadId} ${q.type.description} +
${q.parameters}
${q.total} ${/each} diff --git a/src/nl/astraeus/jdbc/web/page/QueryDetail.java b/src/nl/astraeus/jdbc/web/page/QueryDetail.java index 6eb3b54..d5aa624 100644 --- a/src/nl/astraeus/jdbc/web/page/QueryDetail.java +++ b/src/nl/astraeus/jdbc/web/page/QueryDetail.java @@ -1,5 +1,10 @@ package nl.astraeus.jdbc.web.page; +import nl.astraeus.jdbc.JdbcLogger; +import nl.astraeus.jdbc.SqlFormatter; +import nl.astraeus.jdbc.util.Util; +import nl.astraeus.jdbc.web.JdbcStatsMapping; + import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Collections; @@ -9,11 +14,6 @@ import java.util.List; import java.util.TimeZone; -import nl.astraeus.jdbc.JdbcLogger; -import nl.astraeus.jdbc.SqlFormatter; -import nl.astraeus.jdbc.util.Util; -import nl.astraeus.jdbc.web.JdbcStatsMapping; - /** * User: rnentjes * Date: 4/12/12 diff --git a/src/nl/astraeus/jdbc/web/page/QueryOverview.html b/src/nl/astraeus/jdbc/web/page/QueryOverview.html index a863ff7..2c758d4 100644 --- a/src/nl/astraeus/jdbc/web/page/QueryOverview.html +++ b/src/nl/astraeus/jdbc/web/page/QueryOverview.html @@ -51,6 +51,9 @@ # Calls ${/if} Sql + ${if(sortLast100)} + Parameters + ${/if} @@ -67,6 +70,9 @@ ${q.count} ${/if}
${!q.sql}
+ ${if(sortLast100)} +
${q.parameters}
+ ${/if} ${/each} diff --git a/src/nl/astraeus/jdbc/web/page/QueryOverview.java b/src/nl/astraeus/jdbc/web/page/QueryOverview.java index bd74604..fad6731 100644 --- a/src/nl/astraeus/jdbc/web/page/QueryOverview.java +++ b/src/nl/astraeus/jdbc/web/page/QueryOverview.java @@ -1,5 +1,10 @@ package nl.astraeus.jdbc.web.page; +import nl.astraeus.jdbc.JdbcLogger; +import nl.astraeus.jdbc.util.Util; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Collections; @@ -11,12 +16,6 @@ import java.util.Map; import java.util.TimeZone; -import nl.astraeus.jdbc.JdbcLogger; -import nl.astraeus.jdbc.util.Util; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - /** * User: rnentjes * Date: 4/12/12 diff --git a/.idea/checkstyle-idea.xml b/.idea/checkstyle-idea.xml new file mode 100644 index 0000000..b6e4700 --- /dev/null +++ b/.idea/checkstyle-idea.xml @@ -0,0 +1,16 @@ + + + + + + \ No newline at end of file diff --git a/.idea/hotswap_agent.xml b/.idea/hotswap_agent.xml new file mode 100644 index 0000000..8a869d9 --- /dev/null +++ b/.idea/hotswap_agent.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/libraries/lib1.xml b/.idea/libraries/lib1.xml index 8ce9ba1..7a6f4d3 100644 --- a/.idea/libraries/lib1.xml +++ b/.idea/libraries/lib1.xml @@ -2,7 +2,6 @@ - diff --git a/.idea/modules/simple-jdbc-stats.iml b/.idea/modules/simple-jdbc-stats.iml index f17a5e9..ba2f28c 100644 --- a/.idea/modules/simple-jdbc-stats.iml +++ b/.idea/modules/simple-jdbc-stats.iml @@ -1,5 +1,5 @@ - + diff --git a/.idea/modules/simple-jdbc-stats_main.iml b/.idea/modules/simple-jdbc-stats_main.iml index 573880c..c646a2e 100644 --- a/.idea/modules/simple-jdbc-stats_main.iml +++ b/.idea/modules/simple-jdbc-stats_main.iml @@ -1,7 +1,7 @@ - + - + diff --git a/.idea/modules/simple-jdbc-stats_test.iml b/.idea/modules/simple-jdbc-stats_test.iml index 2e21d25..bac5915 100644 --- a/.idea/modules/simple-jdbc-stats_test.iml +++ b/.idea/modules/simple-jdbc-stats_test.iml @@ -1,7 +1,7 @@ - + - + diff --git a/build.gradle b/build.gradle index 04938e8..69bad54 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ group 'nl.astraeus' -version '1.5.10-SNAPSHOT' +version '1.6.0' apply plugin: 'java' apply plugin: 'idea' diff --git a/src/nl/astraeus/jdbc/JdbcLogger.java b/src/nl/astraeus/jdbc/JdbcLogger.java index 737e1ec..67661df 100644 --- a/src/nl/astraeus/jdbc/JdbcLogger.java +++ b/src/nl/astraeus/jdbc/JdbcLogger.java @@ -1,15 +1,16 @@ package nl.astraeus.jdbc; +import nl.astraeus.jdbc.util.Util; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.HashSet; import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.concurrent.ConcurrentHashMap; -import nl.astraeus.jdbc.util.Util; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - /** * User: riennentjes * Date: Jul 12, 2008 @@ -44,8 +45,18 @@ private boolean autoCommit; private boolean formattedQueries; private StackTraceElement[] stackTrace = null; + private Set parameters = new HashSet(); - public LogEntry(int hash, QueryType type, String sql, long milli, long nano, boolean isAutoCommit, boolean formattedQueries) { + public LogEntry( + int hash, + QueryType type, + String sql, + long milli, + long nano, + boolean isAutoCommit, + boolean formattedQueries, + Set parameters + ) { this.threadId = Thread.currentThread().getId(); this.timeStamp = System.currentTimeMillis(); this.nanoTimeStamp = System.nanoTime(); @@ -57,6 +68,7 @@ this.autoCommit = isAutoCommit; this.count = 1; this.formattedQueries = formattedQueries; + this.parameters = parameters; } public LogEntry(LogEntry le) { @@ -64,12 +76,13 @@ this.nanoTimeStamp = System.nanoTime(); this.hash = le.hash; this.type = le.type; - this.sql = le .sql; + this.sql = le.sql; this.milli = le.milli; this.nano = le.nano; this.count = le.count; this.autoCommit = le.autoCommit; this.formattedQueries = le.formattedQueries; + this.parameters = le.parameters; } public QueryType getType() { @@ -113,11 +126,11 @@ } public String getFormattedMilli() { - return Util.formatNano(milli*1000000/count); + return Util.formatNano(milli * 1000000 / count); } public String getFormattedNano() { - return Util.formatNano(nano/count); + return Util.formatNano(nano / count); } public String getTotal() { @@ -132,6 +145,23 @@ } } + public String getParameters() { + StringBuilder result = new StringBuilder(); + + if (parameters != null && !parameters.isEmpty()) { + for (Parameter parameter : parameters) { + result.append(String.format( + "%4s, %12s, %24s\n", + parameter.getIndex(), + parameter.getType(), + parameter.getDisplayValue() + )); + } + } + + return result.toString(); + } + public boolean isEndOfTransaction() { return sql.toLowerCase().trim().equals("commit") || sql.toLowerCase().trim().equals("rollback") @@ -181,11 +211,37 @@ last100.clear(); } - public void logEntry(QueryType type, String sql, long milli, long nano, boolean isAutoCommit) { + public void logEntry( + QueryType type, + String sql, + long milli, + long nano, + boolean isAutoCommit + ) { + logEntry(type, sql, milli, nano, isAutoCommit, new HashSet()); + } + + public void logEntry( + QueryType type, + String sql, + long milli, + long nano, + boolean isAutoCommit, + Set parameters + ) { int hash = sql.hashCode(); Driver.StatsLogger logger = Driver.get(port); - LogEntry entry = new LogEntry(hash, type, sql, milli, nano, isAutoCommit, logger.getSettings().isFormattedQueries()); + LogEntry entry = new LogEntry( + hash, + type, + sql, + milli, + nano, + isAutoCommit, + logger.getSettings().isFormattedQueries(), + parameters + ); if (logger.getSettings().isRecordingStacktraces()) { try { diff --git a/src/nl/astraeus/jdbc/Parameter.java b/src/nl/astraeus/jdbc/Parameter.java new file mode 100644 index 0000000..8fed9f5 --- /dev/null +++ b/src/nl/astraeus/jdbc/Parameter.java @@ -0,0 +1,118 @@ +package nl.astraeus.jdbc; + +/** + * User: rnentjes + * Date: 26-1-18 + * Time: 11:08 + */ +public class Parameter { + + public interface DisplayFunction { + String display(Object o); + } + + private static DisplayFunction valueOf = new DisplayFunction() { + public String display(Object o) { + return String.valueOf(o); + } + }; + + private static DisplayFunction label(final String label) { + return new DisplayFunction() { + public String display(Object o) { + return label; + } + }; + } + + public enum ParameterType { + NULL(new DisplayFunction() { + public String display(Object o) { + return "NULL"; + } + }), + BOOLEAN(valueOf), + INT(valueOf), + LONG(valueOf), + STRING(new DisplayFunction() { + public String display(Object o) { + return (String)o; + } + }), + BLOB(valueOf), + CLOB(valueOf), + BYTE(valueOf), + SHORT(valueOf), + FLOAT(valueOf), + DOUBLE(valueOf), + BIG_DECIMAL(valueOf), + BYTES(new DisplayFunction() { + public String display(Object o) { + return "byte["+((byte[])o).length+"]"; + } + }), + DATE(valueOf), + TIME(valueOf), + TIMESTAMP(valueOf), + ASCII_STR(label("")), + UNICODE_STR(label("")), + BIN_STR(label("")), + OBJECT(valueOf), + CHAR_STR(label("")), + REF(valueOf), + ARRAY(valueOf), + URL(valueOf), + ROW_ID(valueOf), + NSTRING(valueOf), + NCHAR_STR(label("")), + NCLOB(label("")), + SQLXML(label("")); + + private DisplayFunction display; + + ParameterType(DisplayFunction display) { + this.display = display; + } + + public String toString(Object o) { + return display.display(o); + } + } + + private int index; + private ParameterType type; + private Object value; + + public Parameter( + int index, + ParameterType type + ) { + this(index, type, null); + } + + public Parameter( + int index, + ParameterType type, + Object value + ) { + this.index = index; + this.type = type; + this.value = value; + } + + public int getIndex() { + return index; + } + + public ParameterType getType() { + return type; + } + + public Object getValue() { + return value; + } + + public String getDisplayValue() { + return type.display.display(value); + } +} diff --git a/src/nl/astraeus/jdbc/PreparedStatementLogger.java b/src/nl/astraeus/jdbc/PreparedStatementLogger.java index b7fd226..016c384 100644 --- a/src/nl/astraeus/jdbc/PreparedStatementLogger.java +++ b/src/nl/astraeus/jdbc/PreparedStatementLogger.java @@ -1,5 +1,8 @@ package nl.astraeus.jdbc; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.io.InputStream; import java.io.Reader; import java.math.BigDecimal; @@ -22,9 +25,9 @@ import java.sql.Time; import java.sql.Timestamp; import java.util.Calendar; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import java.util.Comparator; +import java.util.Set; +import java.util.TreeSet; /** * User: riennentjes @@ -43,7 +46,17 @@ private long milli; private long nano; - //private ArrayList parameters; + private Set parameters = new TreeSet(new Comparator() { + public int compare( + Parameter o1, + Parameter o2 + ) { + int x = o1.getIndex(); + int y = o2.getIndex(); + + return (x < y) ? -1 : ((x == y) ? 0 : 1); + } + }); public PreparedStatementLogger(JdbcLogger logger, PreparedStatement statement) throws SQLException { this.logger = logger; @@ -62,7 +75,7 @@ long m = System.currentTimeMillis() - milli; long n = System.nanoTime() - nano; - logger.logEntry(type, sql, m, n, autocommit); + logger.logEntry(type, sql, m, n, autocommit, parameters); } public PreparedStatementLogger(JdbcLogger logger, Connection connection, String sql) throws SQLException { @@ -242,194 +255,242 @@ public void setNull(int parameterIndex, int sqlType) throws SQLException { statement.setNull(parameterIndex, sqlType); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.NULL)); } public void setBoolean(int parameterIndex, boolean x) throws SQLException { statement.setBoolean(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.BOOLEAN, x)); } public void setByte(int parameterIndex, byte x) throws SQLException { statement.setByte(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.BYTE, x)); } public void setShort(int parameterIndex, short x) throws SQLException { statement.setShort(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.SHORT, x)); } public void setInt(int parameterIndex, int x) throws SQLException { statement.setInt(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.INT, x)); } public void setLong(int parameterIndex, long x) throws SQLException { statement.setLong(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.LONG, x)); } public void setFloat(int parameterIndex, float x) throws SQLException { statement.setFloat(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.FLOAT, x)); } public void setDouble(int parameterIndex, double x) throws SQLException { statement.setDouble(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.DOUBLE, x)); } public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException { statement.setBigDecimal(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.BIG_DECIMAL, x)); } public void setString(int parameterIndex, String x) throws SQLException { statement.setString(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.STRING, x)); } public void setBytes(int parameterIndex, byte x[]) throws SQLException { statement.setBytes(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.BYTES, x)); } public void setDate(int parameterIndex, Date x) throws SQLException { statement.setDate(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.DATE, x)); } public void setTime(int parameterIndex, Time x) throws SQLException { statement.setTime(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.TIME, x)); } public void setTimestamp(int parameterIndex, Timestamp x) throws SQLException { statement.setTimestamp(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.TIMESTAMP, x)); } public void setAsciiStream(int parameterIndex, InputStream x, int length) throws SQLException { statement.setAsciiStream(parameterIndex, x, length); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.ASCII_STR)); } public void setUnicodeStream(int parameterIndex, InputStream x, int length) throws SQLException { statement.setUnicodeStream(parameterIndex, x, length); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.UNICODE_STR)); } public void setBinaryStream(int parameterIndex, InputStream x, int length) throws SQLException { statement.setBinaryStream(parameterIndex, x, length); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.BIN_STR)); } public void setObject(int parameterIndex, Object x, int targetSqlType) throws SQLException { statement.setObject(parameterIndex, x, targetSqlType); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.OBJECT, x)); } public void setObject(int parameterIndex, Object x) throws SQLException { statement.setObject(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.OBJECT, x)); } public void setCharacterStream(int parameterIndex, Reader reader, int length) throws SQLException { statement.setCharacterStream(parameterIndex, reader, length); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.CHAR_STR, reader)); } public void setRef(int parameterIndex, Ref x) throws SQLException { statement.setRef(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.REF, x)); } public void setBlob(int parameterIndex, Blob x) throws SQLException { statement.setBlob(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.BLOB, x)); } public void setClob(int parameterIndex, Clob x) throws SQLException { statement.setClob(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.CLOB, x)); } public void setArray(int parameterIndex, Array x) throws SQLException { statement.setArray(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.ARRAY, x)); } public void setDate(int parameterIndex, Date x, Calendar cal) throws SQLException { statement.setDate(parameterIndex, x, cal); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.DATE, x)); } public void setTime(int parameterIndex, Time x, Calendar cal) throws SQLException { statement.setTime(parameterIndex, x, cal); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.TIME, x)); } public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal) throws SQLException { statement.setTimestamp(parameterIndex, x, cal); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.TIMESTAMP, x)); } public void setNull(int parameterIndex, int sqlType, String typeName) throws SQLException { statement.setNull(parameterIndex, sqlType, typeName); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.NULL)); } public void setURL(int parameterIndex, URL x) throws SQLException { statement.setURL(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.URL, x)); } public void setRowId(int parameterIndex, RowId x) throws SQLException { statement.setRowId(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.ROW_ID, x)); } public void setNString(int parameterIndex, String value) throws SQLException { statement.setNString(parameterIndex, value); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.NSTRING, value)); } public void setNCharacterStream(int parameterIndex, Reader value, long length) throws SQLException { statement.setNCharacterStream(parameterIndex, value, length); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.NCHAR_STR, value)); } public void setNClob(int parameterIndex, NClob value) throws SQLException { statement.setNClob(parameterIndex, value); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.NCLOB, value)); } public void setClob(int parameterIndex, Reader reader, long length) throws SQLException { statement.setClob(parameterIndex, reader, length); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.CLOB, reader)); } public void setBlob(int parameterIndex, InputStream inputStream, long length) throws SQLException { statement.setBlob(parameterIndex, inputStream, length); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.BLOB)); } public void setNClob(int parameterIndex, Reader reader, long length) throws SQLException { statement.setNClob(parameterIndex, reader, length); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.NCLOB)); } public void setSQLXML(int parameterIndex, SQLXML xmlObject) throws SQLException { statement.setSQLXML(parameterIndex, xmlObject); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.SQLXML)); } public void setObject(int parameterIndex, Object x, int targetSqlType, int scaleOrLength) throws SQLException { statement.setObject(parameterIndex, x, targetSqlType, scaleOrLength); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.OBJECT, x)); } public void setAsciiStream(int parameterIndex, InputStream x, long length) throws SQLException { statement.setAsciiStream(parameterIndex, x, length); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.ASCII_STR)); } public void setBinaryStream(int parameterIndex, InputStream x, long length) throws SQLException { statement.setBinaryStream(parameterIndex, x, length); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.BIN_STR)); } public void setCharacterStream(int parameterIndex, Reader reader, long length) throws SQLException { statement.setCharacterStream(parameterIndex, reader, length); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.CHAR_STR)); } public void setAsciiStream(int parameterIndex, InputStream x) throws SQLException { statement.setAsciiStream(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.ASCII_STR)); } public void setBinaryStream(int parameterIndex, InputStream x) throws SQLException { statement.setBinaryStream(parameterIndex, x); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.BIN_STR)); } public void setCharacterStream(int parameterIndex, Reader reader) throws SQLException { statement.setCharacterStream(parameterIndex, reader); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.CHAR_STR)); } public void setNCharacterStream(int parameterIndex, Reader value) throws SQLException { statement.setNCharacterStream(parameterIndex, value); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.NCHAR_STR)); } public void setClob(int parameterIndex, Reader reader) throws SQLException { statement.setClob(parameterIndex, reader); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.CLOB)); } public void setBlob(int parameterIndex, InputStream inputStream) throws SQLException { statement.setBlob(parameterIndex, inputStream); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.BLOB)); } public void setNClob(int parameterIndex, Reader reader) throws SQLException { statement.setNClob(parameterIndex, reader); + parameters.add(new Parameter(parameterIndex, Parameter.ParameterType.NCLOB)); } diff --git a/src/nl/astraeus/jdbc/web/page/HeaderPage.html b/src/nl/astraeus/jdbc/web/page/HeaderPage.html index 3788989..b4b4b2d 100644 --- a/src/nl/astraeus/jdbc/web/page/HeaderPage.html +++ b/src/nl/astraeus/jdbc/web/page/HeaderPage.html @@ -4,7 +4,7 @@ - Simple JDBC Statistics + JDBC Statistics diff --git a/src/nl/astraeus/jdbc/web/page/QueryDetail.html b/src/nl/astraeus/jdbc/web/page/QueryDetail.html index 1fe0ba7..959c057 100644 --- a/src/nl/astraeus/jdbc/web/page/QueryDetail.html +++ b/src/nl/astraeus/jdbc/web/page/QueryDetail.html @@ -52,6 +52,7 @@ Timestamp Thread id Type + Parameters Time (ms) @@ -62,6 +63,7 @@ ${q.formattedTimestamp} ${q.threadId} ${q.type.description} +
${q.parameters}
${q.total} ${/each} diff --git a/src/nl/astraeus/jdbc/web/page/QueryDetail.java b/src/nl/astraeus/jdbc/web/page/QueryDetail.java index 6eb3b54..d5aa624 100644 --- a/src/nl/astraeus/jdbc/web/page/QueryDetail.java +++ b/src/nl/astraeus/jdbc/web/page/QueryDetail.java @@ -1,5 +1,10 @@ package nl.astraeus.jdbc.web.page; +import nl.astraeus.jdbc.JdbcLogger; +import nl.astraeus.jdbc.SqlFormatter; +import nl.astraeus.jdbc.util.Util; +import nl.astraeus.jdbc.web.JdbcStatsMapping; + import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Collections; @@ -9,11 +14,6 @@ import java.util.List; import java.util.TimeZone; -import nl.astraeus.jdbc.JdbcLogger; -import nl.astraeus.jdbc.SqlFormatter; -import nl.astraeus.jdbc.util.Util; -import nl.astraeus.jdbc.web.JdbcStatsMapping; - /** * User: rnentjes * Date: 4/12/12 diff --git a/src/nl/astraeus/jdbc/web/page/QueryOverview.html b/src/nl/astraeus/jdbc/web/page/QueryOverview.html index a863ff7..2c758d4 100644 --- a/src/nl/astraeus/jdbc/web/page/QueryOverview.html +++ b/src/nl/astraeus/jdbc/web/page/QueryOverview.html @@ -51,6 +51,9 @@ # Calls ${/if} Sql + ${if(sortLast100)} + Parameters + ${/if} @@ -67,6 +70,9 @@ ${q.count} ${/if}
${!q.sql}
+ ${if(sortLast100)} +
${q.parameters}
+ ${/if} ${/each} diff --git a/src/nl/astraeus/jdbc/web/page/QueryOverview.java b/src/nl/astraeus/jdbc/web/page/QueryOverview.java index bd74604..fad6731 100644 --- a/src/nl/astraeus/jdbc/web/page/QueryOverview.java +++ b/src/nl/astraeus/jdbc/web/page/QueryOverview.java @@ -1,5 +1,10 @@ package nl.astraeus.jdbc.web.page; +import nl.astraeus.jdbc.JdbcLogger; +import nl.astraeus.jdbc.util.Util; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Collections; @@ -11,12 +16,6 @@ import java.util.Map; import java.util.TimeZone; -import nl.astraeus.jdbc.JdbcLogger; -import nl.astraeus.jdbc.util.Util; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - /** * User: rnentjes * Date: 4/12/12 diff --git a/src/nl/astraeus/jdbc/web/page/ShowStacktrace.java b/src/nl/astraeus/jdbc/web/page/ShowStacktrace.java index be73d4b..5d34818 100644 --- a/src/nl/astraeus/jdbc/web/page/ShowStacktrace.java +++ b/src/nl/astraeus/jdbc/web/page/ShowStacktrace.java @@ -1,13 +1,15 @@ package nl.astraeus.jdbc.web.page; -import java.util.LinkedList; -import java.util.List; - import nl.astraeus.jdbc.JdbcLogger; +import nl.astraeus.jdbc.Parameter; import nl.astraeus.jdbc.QueryType; import nl.astraeus.jdbc.SqlFormatter; import nl.astraeus.web.page.Message; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; + /** * User: rnentjes * Date: 4/12/12 @@ -21,7 +23,10 @@ boolean sortAvgTime = false; boolean sortTime = false; - public ShowStacktrace(String hashStr, String timestamp) { + public ShowStacktrace( + String hashStr, + String timestamp + ) { List entries = JdbcLogger.get(getServerInfo().port).getEntries(); hash = Integer.parseInt(hashStr); @@ -36,7 +41,16 @@ if (logEntry == null) { addMessage(Message.Type.ERROR, "Error", "Stacktrace not found!"); - logEntry = new JdbcLogger.LogEntry(-1, QueryType.UNKNOWN, "", 0, 0, false, true); + logEntry = new JdbcLogger.LogEntry( + -1, + QueryType.UNKNOWN, + "", + 0, + 0, + false, + true, + new HashSet() + ); logEntry.setStackTrace(new StackTraceElement[0]); } } @@ -61,7 +75,10 @@ private StackTraceElement element; private boolean highlight; - public TraceElement(StackTraceElement element, boolean highlight) { + public TraceElement( + StackTraceElement element, + boolean highlight + ) { this.element = element; this.highlight = highlight; }