Skip to content

Commit b5e131b

Browse files
author
Gilles Milleret
committed
Add transaction isolation.
1 parent 4a029ec commit b5e131b

18 files changed

+137
-77
lines changed

jdbc-perf-logger-driver/src/main/java/ch/sla/jdbcperflogger/driver/LoggingPreparedStatementInvocationHandler.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.io.Serializable;
1919
import java.lang.reflect.Method;
2020
import java.lang.reflect.Proxy;
21+
import java.sql.Connection;
2122
import java.sql.PreparedStatement;
2223
import java.sql.ResultSet;
2324
import java.sql.SQLType;
@@ -101,9 +102,10 @@ public Object invoke(final @Nullable Object proxy, final Method method, final Ob
101102

102103
protected ResultSet internalExecutePreparedQuery(final Method method) throws Throwable {
103104
final UUID logId = UUID.randomUUID();
105+
final Connection connection = wrappedStatement.getConnection();
104106
PerfLogger.logBeforePreparedStatement(connectionId, logId, rawSql, paramValues,
105107
StatementType.PREPARED_QUERY_STMT, databaseType, wrappedStatement.getQueryTimeout(),
106-
wrappedStatement.getConnection().getAutoCommit());
108+
connection.getAutoCommit(), connection.getTransactionIsolation());
107109
final long start = System.nanoTime();
108110
Throwable exc = null;
109111
try {
@@ -127,9 +129,10 @@ protected ResultSet internalExecutePreparedQuery(final Method method) throws Thr
127129
protected Object internalExecutePrepared(final Method method, final Object @Nullable [] args) throws Throwable {
128130
final UUID logId = UUID.randomUUID();
129131
final long start = System.nanoTime();
132+
final Connection connection = wrappedStatement.getConnection();
130133
PerfLogger.logBeforePreparedStatement(connectionId, logId, rawSql, paramValues,
131134
StatementType.BASE_PREPARED_STMT, databaseType, wrappedStatement.getQueryTimeout(),
132-
wrappedStatement.getConnection().getAutoCommit());
135+
connection.getAutoCommit(), connection.getTransactionIsolation());
133136
Throwable exc = null;
134137
Long updateCount = null;
135138
try {
@@ -152,8 +155,9 @@ protected Object internalExecutePrepared(final Method method, final Object @Null
152155
@Nullable
153156
protected Object internalExecuteBatch(final Method method, final Object @Nullable [] args) throws Throwable {
154157
final UUID logId = UUID.randomUUID();
158+
final Connection connection = wrappedStatement.getConnection();
155159
PerfLogger.logPreparedBatchedStatements(connectionId, logId, rawSql, batchedPreparedOrNonPreparedStmtExecutions,
156-
databaseType, wrappedStatement.getQueryTimeout(), wrappedStatement.getConnection().getAutoCommit());
160+
databaseType, wrappedStatement.getQueryTimeout(), connection.getAutoCommit(), connection.getTransactionIsolation());
157161
try {
158162
return internalExecuteBatchInternal(method, args, logId);
159163
} finally {

jdbc-perf-logger-driver/src/main/java/ch/sla/jdbcperflogger/driver/LoggingStatementInvocationHandler.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.lang.reflect.InvocationHandler;
1919
import java.lang.reflect.Method;
2020
import java.lang.reflect.Proxy;
21+
import java.sql.Connection;
2122
import java.sql.ResultSet;
2223
import java.sql.Statement;
2324
import java.util.ArrayList;
@@ -86,8 +87,9 @@ public Object invoke(final @Nullable Object _proxy, final Method method, final O
8687
protected final ResultSet internalExecuteQuery(final Method method, final Object[] args) throws Throwable {
8788
final UUID logId = UUID.randomUUID();
8889
final long start = System.nanoTime();
90+
final Connection connection = wrappedStatement.getConnection();
8991
PerfLogger.logBeforeStatement(connectionId, logId, (String) args[0], StatementType.NON_PREPARED_QUERY_STMT,
90-
wrappedStatement.getQueryTimeout(), wrappedStatement.getConnection().getAutoCommit());
92+
wrappedStatement.getQueryTimeout(), connection.getAutoCommit(), connection.getTransactionIsolation());
9193
Throwable exc = null;
9294
try {
9395
return getAndWrapResultSet(method, args, logId);
@@ -114,8 +116,9 @@ private ResultSet getAndWrapResultSet(final Method method, final Object @Nullabl
114116
@Nullable
115117
protected final Object internalExecute(final Method method, final Object[] args) throws Throwable {
116118
final UUID logId = UUID.randomUUID();
119+
final Connection connection = wrappedStatement.getConnection();
117120
PerfLogger.logBeforeStatement(connectionId, logId, (String) args[0], StatementType.BASE_NON_PREPARED_STMT,
118-
wrappedStatement.getQueryTimeout(), wrappedStatement.getConnection().getAutoCommit());
121+
wrappedStatement.getQueryTimeout(), connection.getAutoCommit(), connection.getTransactionIsolation());
119122
Throwable exc = null;
120123
Long updateCount = null;
121124
final long start = System.nanoTime();
@@ -138,8 +141,9 @@ protected final Object internalExecute(final Method method, final Object[] args)
138141
@Nullable
139142
protected Object internalExecuteBatch(final Method method, final Object @Nullable [] args) throws Throwable {
140143
final UUID logId = UUID.randomUUID();
144+
final Connection connection = wrappedStatement.getConnection();
141145
PerfLogger.logNonPreparedBatchedStatements(connectionId, logId, batchedNonPreparedStmtExecutions, databaseType,
142-
wrappedStatement.getQueryTimeout(), wrappedStatement.getConnection().getAutoCommit());
146+
wrappedStatement.getQueryTimeout(), connection.getAutoCommit(), connection.getTransactionIsolation());
143147
try {
144148
return internalExecuteBatchInternal(method, args, logId);
145149
} finally {

jdbc-perf-logger-driver/src/main/java/ch/sla/jdbcperflogger/logger/PerfLogger.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,18 +74,18 @@ public class PerfLogger {
7474
}
7575

7676
public static void logBeforeStatement(final UUID connectionId, final UUID logId, final String sql,
77-
final StatementType statementType, final int timeout, final boolean autoCommit) {
77+
final StatementType statementType, final int timeout, final boolean autoCommit, final int transactionIsolation) {
7878
if (LOGGER_ORIGINAL_SQL.isDebugEnabled()) {
7979
LOGGER_ORIGINAL_SQL.debug("Before execution of non-prepared stmt " + logId + ": " + sql);
8080
}
8181
final long now = System.currentTimeMillis();
8282
PerfLoggerRemoting.postLog(new StatementLog(connectionId, logId, now, statementType, sql,
83-
Thread.currentThread().getName(), timeout, autoCommit));
83+
Thread.currentThread().getName(), timeout, autoCommit, transactionIsolation));
8484
}
8585

8686
public static void logBeforePreparedStatement(final UUID connectionId, final UUID logId, final String rawSql,
8787
final PreparedStatementValuesHolder pstmtValues, final StatementType statementType,
88-
final DatabaseType databaseType, final int timeout, final boolean autoCommit) {
88+
final DatabaseType databaseType, final int timeout, final boolean autoCommit, final int transactionIsolation) {
8989
if (LOGGER_ORIGINAL_SQL.isDebugEnabled()) {
9090
LOGGER_ORIGINAL_SQL.debug("Before execution of prepared stmt " + logId + ": " + rawSql);
9191
}
@@ -95,12 +95,12 @@ public static void logBeforePreparedStatement(final UUID connectionId, final UUI
9595
}
9696
final long now = System.currentTimeMillis();
9797
PerfLoggerRemoting.postLog(new StatementLog(connectionId, logId, now, statementType, rawSql, filledSql,
98-
Thread.currentThread().getName(), timeout, autoCommit));
98+
Thread.currentThread().getName(), timeout, autoCommit, transactionIsolation));
9999
}
100100

101101
public static void logNonPreparedBatchedStatements(final UUID connectionId, final UUID logId,
102102
final List<String> batchedExecutions, final DatabaseType databaseType, final int timeout,
103-
final boolean autoCommit) {
103+
final boolean autoCommit, final int transactionIsolation) {
104104

105105
final long now = System.currentTimeMillis();
106106
if (LOGGER_ORIGINAL_SQL.isDebugEnabled()) {
@@ -114,12 +114,12 @@ public static void logNonPreparedBatchedStatements(final UUID connectionId, fina
114114
}
115115
}
116116
PerfLoggerRemoting.postLog(new BatchedNonPreparedStatementsLog(connectionId, logId, now, batchedExecutions,
117-
Thread.currentThread().getName(), timeout, autoCommit));
117+
Thread.currentThread().getName(), timeout, autoCommit, transactionIsolation));
118118
}
119119

120120
public static void logPreparedBatchedStatements(final UUID connectionId, final UUID logId, final String rawSql,
121121
final List<Object> batchedExecutions, final DatabaseType databaseType, final int timeout,
122-
final boolean autoCommit) {
122+
final boolean autoCommit, final int transactionIsolation) {
123123
final long now = System.currentTimeMillis();
124124
if (LOGGER_ORIGINAL_SQL.isDebugEnabled()) {
125125
LOGGER_ORIGINAL_SQL.debug("Before execution of " + batchedExecutions.size()
@@ -141,7 +141,7 @@ public static void logPreparedBatchedStatements(final UUID connectionId, final U
141141
}
142142
}
143143
PerfLoggerRemoting.postLog(new BatchedPreparedStatementsLog(connectionId, logId, now, rawSql, filledSqlList,
144-
Thread.currentThread().getName(), timeout, autoCommit));
144+
Thread.currentThread().getName(), timeout, autoCommit, transactionIsolation));
145145
}
146146

147147
public static void logStatementExecuted(final UUID logId, final long durationNanos,

jdbc-perf-logger-driver/src/main/java/ch/sla/jdbcperflogger/model/AbstractBeforeStatementExecutionLog.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,18 @@ public class AbstractBeforeStatementExecutionLog implements LogMessage {
3030
private final String threadName;
3131
private final int timeout;
3232
private final boolean autoCommit;
33+
private final int transactionIsolation;
3334

3435
public AbstractBeforeStatementExecutionLog(final UUID connectionId, final UUID logId, final long timestamp,
35-
final StatementType statementType, final String threadName, final int timeout, final boolean autoCommit) {
36+
final StatementType statementType, final String threadName, final int timeout, final boolean autoCommit, int transactionIsolation) {
3637
connectionUuid = connectionId;
3738
this.logId = logId;
3839
this.timestamp = timestamp;
3940
this.statementType = statementType;
4041
this.threadName = threadName;
4142
this.timeout = timeout;
4243
this.autoCommit = autoCommit;
44+
this.transactionIsolation = transactionIsolation;
4345
}
4446

4547
public UUID getConnectionUuid() {
@@ -70,4 +72,7 @@ public boolean isAutoCommit() {
7072
return autoCommit;
7173
}
7274

75+
public int getTransactionIsolation() {
76+
return transactionIsolation;
77+
}
7378
}

jdbc-perf-logger-driver/src/main/java/ch/sla/jdbcperflogger/model/BatchedNonPreparedStatementsLog.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ public class BatchedNonPreparedStatementsLog extends AbstractBeforeStatementExec
2929
private final List<String> sqlList;
3030

3131
public BatchedNonPreparedStatementsLog(final UUID connectionId, final UUID logId, final long timestamp,
32-
final List<String> sqlList, final String threadName, final int timeout, final boolean autoCommit) {
32+
final List<String> sqlList, final String threadName, final int timeout, final boolean autoCommit,
33+
final int transactionIsolation) {
3334
super(connectionId, logId, timestamp, StatementType.NON_PREPARED_BATCH_EXECUTION, threadName, timeout,
34-
autoCommit);
35+
autoCommit, transactionIsolation);
3536
this.sqlList = Collections.unmodifiableList(new ArrayList<String>(sqlList));
3637
}
3738

@@ -48,6 +49,7 @@ public String toString() {
4849
+ ", threadName=" + getThreadName()//
4950
+ ", timeout=" + getTimeout()//
5051
+ ", autocommit=" + isAutoCommit()//
52+
+ ", getTransactionIsolation=" + getTransactionIsolation()//
5153
+ ", sqlList=" + sqlList//
5254
+ "]";
5355
}

jdbc-perf-logger-driver/src/main/java/ch/sla/jdbcperflogger/model/BatchedPreparedStatementsLog.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ public class BatchedPreparedStatementsLog extends AbstractBeforeStatementExecuti
3131

3232
public BatchedPreparedStatementsLog(final UUID connectionId, final UUID logId, final long timestamp,
3333
final String rawSql, final List<String> sqlList, final String threadName, final int timeout,
34-
final boolean autoCommit) {
35-
super(connectionId, logId, timestamp, StatementType.PREPARED_BATCH_EXECUTION, threadName, timeout, autoCommit);
34+
final boolean autoCommit, final int transactionIsolation) {
35+
super(connectionId, logId, timestamp, StatementType.PREPARED_BATCH_EXECUTION, threadName, timeout, autoCommit, transactionIsolation);
3636
this.rawSql = rawSql;
3737
this.sqlList = Collections.unmodifiableList(new ArrayList<String>(sqlList));
3838
}
@@ -55,6 +55,7 @@ public String toString() {
5555
+ ", threadName=" + getThreadName()//
5656
+ ", timeout=" + getTimeout()//
5757
+ ", autocommit=" + isAutoCommit()//
58+
+ ", transactionIsolation=" + getTransactionIsolation()//
5859
+ "]";
5960
}
6061

jdbc-perf-logger-driver/src/main/java/ch/sla/jdbcperflogger/model/StatementLog.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,17 @@ public class StatementLog extends AbstractBeforeStatementExecutionLog {
2929

3030
public StatementLog(final UUID connectionId, final UUID logId, final long timestamp,
3131
final StatementType statementType, final String sql, final String threadName, final int timeout,
32-
final boolean autoCommit) {
33-
super(connectionId, logId, timestamp, statementType, threadName, timeout, autoCommit);
32+
final boolean autoCommit, final int transactionIsolation) {
33+
super(connectionId, logId, timestamp, statementType, threadName, timeout, autoCommit, transactionIsolation);
3434
rawSql = sql;
3535
filledSql = sql;
3636
preparedStatement = false;
3737
}
3838

3939
public StatementLog(final UUID connectionId, final UUID logId, final long timestamp,
4040
final StatementType statementType, final String rawSql, final String filledSql, final String threadName,
41-
final int timeout, final boolean autoCommit) {
42-
super(connectionId, logId, timestamp, statementType, threadName, timeout, autoCommit);
41+
final int timeout, final boolean autoCommit, int transactionIsolation) {
42+
super(connectionId, logId, timestamp, statementType, threadName, timeout, autoCommit, transactionIsolation);
4343
this.rawSql = rawSql;
4444
this.filledSql = filledSql;
4545
preparedStatement = true;
@@ -66,6 +66,7 @@ public String toString() {
6666
+ ", threadName=" + getThreadName()//
6767
+ ", timeout=" + getTimeout()//
6868
+ ", autocommit=" + isAutoCommit()//
69+
+ ", getTransactionIsolation=" + getTransactionIsolation()//
6970
+ ", rawSql=" + rawSql//
7071
+ ", filledSql=" + filledSql//
7172
+ ", preparedStatement=" + preparedStatement//

jdbc-perf-logger-gui/src/main/java/ch/sla/jdbcperflogger/console/db/LogRepositoryConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
public class LogRepositoryConstants {
44

5+
public static final String TRANSACTION_ISOLATION_COLUMN = "TRANSACTION_ISOLATION";
56
public static final String AUTOCOMMIT_COLUMN = "AUTOCOMMIT";
67
public static final String AVG_EXEC_PLUS_RSET_USAGE_TIME_COLUMN = "AVG_EXEC_PLUS_RSET_USAGE_TIME";
78
public static final String BATCHED_STMT_ORDER = "BATCHED_STMT_ORDER";

jdbc-perf-logger-gui/src/main/java/ch/sla/jdbcperflogger/console/db/LogRepositoryReadJdbc.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public void getStatements(final LogSearchCriteria searchCriteria, final ResultSe
6565
final boolean withFilledSql) {
6666
final StringBuilder sql = new StringBuilder("select id, tstamp, statementType, rawSql, " //
6767
+ "exec_plus_rset_usage_time, execution_time, rset_usage_time, fetch_time, "//
68-
+ "nbRows, threadName, connectionNumber, timeout, autoCommit, error ");
68+
+ "nbRows, threadName, connectionNumber, timeout, autoCommit, transaction_Isolation, error ");
6969
if (withFilledSql) {
7070
sql.append(", " + LogRepositoryConstants.FILLED_SQL_COLUMN);
7171
}

jdbc-perf-logger-gui/src/main/java/ch/sla/jdbcperflogger/console/db/LogRepositoryUpdateJdbc.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,13 @@ public LogRepositoryUpdateJdbc(final String name) {
7878

7979
addStatementLog = connectionUpdate
8080
.prepareStatement("insert into statement_log (logId, tstamp, statementType, rawSql, filledSql, " //
81-
+ "threadName, connectionId, timeout, autoCommit)"//
82-
+ " values(?, ?, ?, ?, ?, ?, ?, ?, ?)");
81+
+ "threadName, connectionId, timeout, autoCommit, transaction_Isolation)"//
82+
+ " values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
8383
addStatementLogWithAfterExecutionInfo = connectionUpdate
8484
.prepareStatement("insert into statement_log (logId, tstamp, statementType, rawSql, filledSql, " //
85-
+ "threadName, connectionId, timeout, autoCommit, executionDurationNanos, nbRows, " //
85+
+ "threadName, connectionId, timeout, autoCommit, transaction_Isolation, executionDurationNanos, nbRows, " //
8686
+ "fetchDurationNanos, rsetUsageDurationNanos, exception)"//
87-
+ " values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
87+
+ " values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
8888
updateStatementLogWithResultSet = connectionUpdate.prepareStatement(
8989
"update statement_log set fetchDurationNanos=?, rsetUsageDurationNanos=?, nbRows=? where logId=?");
9090
updateStatementLogAfterExecution = connectionUpdate.prepareStatement(
@@ -183,6 +183,7 @@ public synchronized void addStatementLog(final StatementLog log) {
183183
addStatementLog.setObject(i++, log.getConnectionUuid());
184184
addStatementLog.setInt(i++, log.getTimeout());
185185
addStatementLog.setBoolean(i++, log.isAutoCommit());
186+
addStatementLog.setInt(i++, log.getTransactionIsolation());
186187
final int insertCount = addStatementLog.executeUpdate();
187188
assert insertCount == 1;
188189
} catch (final SQLException e) {
@@ -206,6 +207,7 @@ public synchronized void addStatementFullyExecutedLog(final Collection<Statement
206207
addStatementLogWithAfterExecutionInfo.setObject(i++, log.getConnectionUuid());
207208
addStatementLogWithAfterExecutionInfo.setInt(i++, log.getTimeout());
208209
addStatementLogWithAfterExecutionInfo.setBoolean(i++, log.isAutoCommit());
210+
addStatementLogWithAfterExecutionInfo.setInt(i++, log.getTransactionIsolation());
209211
addStatementLogWithAfterExecutionInfo.setLong(i++, log.getExecutionTimeNanos());
210212
addStatementLogWithAfterExecutionInfo.setObject(i++, log.getNbRowsIterated(), Types.INTEGER);
211213
addStatementLogWithAfterExecutionInfo.setObject(i++, log.getFetchDurationNanos(), Types.BIGINT);
@@ -273,6 +275,7 @@ public synchronized void addBatchedPreparedStatementsLog(final BatchedPreparedSt
273275
addStatementLog.setObject(i++, log.getConnectionUuid());
274276
addStatementLog.setInt(i++, log.getTimeout());
275277
addStatementLog.setBoolean(i++, log.isAutoCommit());
278+
addStatementLog.setInt(i++, log.getTransactionIsolation());
276279
addStatementLog.executeUpdate();
277280

278281
addBatchedStatementLog.setObject(1, log.getLogId());
@@ -302,6 +305,7 @@ public synchronized void addBatchedNonPreparedStatementsLog(final BatchedNonPrep
302305
addStatementLog.setObject(i++, log.getConnectionUuid());
303306
addStatementLog.setInt(i++, log.getTimeout());
304307
addStatementLog.setBoolean(i++, log.isAutoCommit());
308+
addStatementLog.setInt(i++, log.getTransactionIsolation());
305309
addStatementLog.executeUpdate();
306310

307311
addBatchedStatementLog.setObject(1, log.getLogId());

0 commit comments

Comments
 (0)