Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.io.Serializable;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLType;
Expand Down Expand Up @@ -101,9 +102,10 @@ public Object invoke(final @Nullable Object proxy, final Method method, final Ob

protected ResultSet internalExecutePreparedQuery(final Method method) throws Throwable {
final UUID logId = UUID.randomUUID();
final Connection connection = wrappedStatement.getConnection();
PerfLogger.logBeforePreparedStatement(connectionId, logId, rawSql, paramValues,
StatementType.PREPARED_QUERY_STMT, databaseType, wrappedStatement.getQueryTimeout(),
wrappedStatement.getConnection().getAutoCommit());
connection.getAutoCommit(), connection.getTransactionIsolation());
final long start = System.nanoTime();
Throwable exc = null;
try {
Expand All @@ -127,9 +129,10 @@ protected ResultSet internalExecutePreparedQuery(final Method method) throws Thr
protected Object internalExecutePrepared(final Method method, final Object @Nullable [] args) throws Throwable {
final UUID logId = UUID.randomUUID();
final long start = System.nanoTime();
final Connection connection = wrappedStatement.getConnection();
PerfLogger.logBeforePreparedStatement(connectionId, logId, rawSql, paramValues,
StatementType.BASE_PREPARED_STMT, databaseType, wrappedStatement.getQueryTimeout(),
wrappedStatement.getConnection().getAutoCommit());
connection.getAutoCommit(), connection.getTransactionIsolation());
Throwable exc = null;
Long updateCount = null;
try {
Expand All @@ -152,8 +155,9 @@ protected Object internalExecutePrepared(final Method method, final Object @Null
@Nullable
protected Object internalExecuteBatch(final Method method, final Object @Nullable [] args) throws Throwable {
final UUID logId = UUID.randomUUID();
final Connection connection = wrappedStatement.getConnection();
PerfLogger.logPreparedBatchedStatements(connectionId, logId, rawSql, batchedPreparedOrNonPreparedStmtExecutions,
databaseType, wrappedStatement.getQueryTimeout(), wrappedStatement.getConnection().getAutoCommit());
databaseType, wrappedStatement.getQueryTimeout(), connection.getAutoCommit(), connection.getTransactionIsolation());
try {
return internalExecuteBatchInternal(method, args, logId);
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
Expand Down Expand Up @@ -86,8 +87,9 @@ public Object invoke(final @Nullable Object _proxy, final Method method, final O
protected final ResultSet internalExecuteQuery(final Method method, final Object[] args) throws Throwable {
final UUID logId = UUID.randomUUID();
final long start = System.nanoTime();
final Connection connection = wrappedStatement.getConnection();
PerfLogger.logBeforeStatement(connectionId, logId, (String) args[0], StatementType.NON_PREPARED_QUERY_STMT,
wrappedStatement.getQueryTimeout(), wrappedStatement.getConnection().getAutoCommit());
wrappedStatement.getQueryTimeout(), connection.getAutoCommit(), connection.getTransactionIsolation());
Throwable exc = null;
try {
return getAndWrapResultSet(method, args, logId);
Expand All @@ -114,8 +116,9 @@ private ResultSet getAndWrapResultSet(final Method method, final Object @Nullabl
@Nullable
protected final Object internalExecute(final Method method, final Object[] args) throws Throwable {
final UUID logId = UUID.randomUUID();
final Connection connection = wrappedStatement.getConnection();
PerfLogger.logBeforeStatement(connectionId, logId, (String) args[0], StatementType.BASE_NON_PREPARED_STMT,
wrappedStatement.getQueryTimeout(), wrappedStatement.getConnection().getAutoCommit());
wrappedStatement.getQueryTimeout(), connection.getAutoCommit(), connection.getTransactionIsolation());
Throwable exc = null;
Long updateCount = null;
final long start = System.nanoTime();
Expand All @@ -138,8 +141,9 @@ protected final Object internalExecute(final Method method, final Object[] args)
@Nullable
protected Object internalExecuteBatch(final Method method, final Object @Nullable [] args) throws Throwable {
final UUID logId = UUID.randomUUID();
final Connection connection = wrappedStatement.getConnection();
PerfLogger.logNonPreparedBatchedStatements(connectionId, logId, batchedNonPreparedStmtExecutions, databaseType,
wrappedStatement.getQueryTimeout(), wrappedStatement.getConnection().getAutoCommit());
wrappedStatement.getQueryTimeout(), connection.getAutoCommit(), connection.getTransactionIsolation());
try {
return internalExecuteBatchInternal(method, args, logId);
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,18 @@ public class PerfLogger {
}

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

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

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

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

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

public static void logStatementExecuted(final UUID logId, final long durationNanos,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,18 @@ public class AbstractBeforeStatementExecutionLog implements LogMessage {
private final String threadName;
private final int timeout;
private final boolean autoCommit;
private final int transactionIsolation;

public AbstractBeforeStatementExecutionLog(final UUID connectionId, final UUID logId, final long timestamp,
final StatementType statementType, final String threadName, final int timeout, final boolean autoCommit) {
final StatementType statementType, final String threadName, final int timeout, final boolean autoCommit, int transactionIsolation) {
connectionUuid = connectionId;
this.logId = logId;
this.timestamp = timestamp;
this.statementType = statementType;
this.threadName = threadName;
this.timeout = timeout;
this.autoCommit = autoCommit;
this.transactionIsolation = transactionIsolation;
}

public UUID getConnectionUuid() {
Expand Down Expand Up @@ -70,4 +72,7 @@ public boolean isAutoCommit() {
return autoCommit;
}

public int getTransactionIsolation() {
return transactionIsolation;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ public class BatchedNonPreparedStatementsLog extends AbstractBeforeStatementExec
private final List<String> sqlList;

public BatchedNonPreparedStatementsLog(final UUID connectionId, final UUID logId, final long timestamp,
final List<String> sqlList, final String threadName, final int timeout, final boolean autoCommit) {
final List<String> sqlList, final String threadName, final int timeout, final boolean autoCommit,
final int transactionIsolation) {
super(connectionId, logId, timestamp, StatementType.NON_PREPARED_BATCH_EXECUTION, threadName, timeout,
autoCommit);
autoCommit, transactionIsolation);
this.sqlList = Collections.unmodifiableList(new ArrayList<String>(sqlList));
}

Expand All @@ -48,6 +49,7 @@ public String toString() {
+ ", threadName=" + getThreadName()//
+ ", timeout=" + getTimeout()//
+ ", autocommit=" + isAutoCommit()//
+ ", getTransactionIsolation=" + getTransactionIsolation()//
+ ", sqlList=" + sqlList//
+ "]";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public class BatchedPreparedStatementsLog extends AbstractBeforeStatementExecuti

public BatchedPreparedStatementsLog(final UUID connectionId, final UUID logId, final long timestamp,
final String rawSql, final List<String> sqlList, final String threadName, final int timeout,
final boolean autoCommit) {
super(connectionId, logId, timestamp, StatementType.PREPARED_BATCH_EXECUTION, threadName, timeout, autoCommit);
final boolean autoCommit, final int transactionIsolation) {
super(connectionId, logId, timestamp, StatementType.PREPARED_BATCH_EXECUTION, threadName, timeout, autoCommit, transactionIsolation);
this.rawSql = rawSql;
this.sqlList = Collections.unmodifiableList(new ArrayList<String>(sqlList));
}
Expand All @@ -55,6 +55,7 @@ public String toString() {
+ ", threadName=" + getThreadName()//
+ ", timeout=" + getTimeout()//
+ ", autocommit=" + isAutoCommit()//
+ ", transactionIsolation=" + getTransactionIsolation()//
+ "]";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ public class StatementLog extends AbstractBeforeStatementExecutionLog {

public StatementLog(final UUID connectionId, final UUID logId, final long timestamp,
final StatementType statementType, final String sql, final String threadName, final int timeout,
final boolean autoCommit) {
super(connectionId, logId, timestamp, statementType, threadName, timeout, autoCommit);
final boolean autoCommit, final int transactionIsolation) {
super(connectionId, logId, timestamp, statementType, threadName, timeout, autoCommit, transactionIsolation);
rawSql = sql;
filledSql = sql;
preparedStatement = false;
}

public StatementLog(final UUID connectionId, final UUID logId, final long timestamp,
final StatementType statementType, final String rawSql, final String filledSql, final String threadName,
final int timeout, final boolean autoCommit) {
super(connectionId, logId, timestamp, statementType, threadName, timeout, autoCommit);
final int timeout, final boolean autoCommit, int transactionIsolation) {
super(connectionId, logId, timestamp, statementType, threadName, timeout, autoCommit, transactionIsolation);
this.rawSql = rawSql;
this.filledSql = filledSql;
preparedStatement = true;
Expand All @@ -66,6 +66,7 @@ public String toString() {
+ ", threadName=" + getThreadName()//
+ ", timeout=" + getTimeout()//
+ ", autocommit=" + isAutoCommit()//
+ ", getTransactionIsolation=" + getTransactionIsolation()//
+ ", rawSql=" + rawSql//
+ ", filledSql=" + filledSql//
+ ", preparedStatement=" + preparedStatement//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,18 @@ public class LogRepositoryConstants {
public static final String EXEC_PLUS_RSET_USAGE_TIME = "EXEC_PLUS_RSET_USAGE_TIME";
public static final String EXEC_TIME_COLUMN = "execution_time";
public static final String FETCH_TIME_COLUMN = "fetch_time";
public static final String RSET_USAGE_TIME = "RSET_USAGE_TIME";
public static final String FILLED_SQL_COLUMN = "FILLEDSQL";
public static final String ID_COLUMN = "ID";
public static final String MAX_EXEC_PLUS_RSET_USAGE_TIME_COLUMN = "MAX_EXEC_PLUS_RSET_USAGE_TIME";
public static final String MIN_EXEC_PLUS_RSET_USAGE_TIME_COLUMN = "MIN_EXEC_PLUS_RSET_USAGE_TIME";
public static final String NB_ROWS_COLUMN = "NBROWS";
public static final String RAW_SQL_COLUMN = "RAWSQL";
public static final String RSET_USAGE_TIME = "RSET_USAGE_TIME";
public static final String STMT_TYPE_COLUMN = "STATEMENTTYPE";
public static final String THREAD_NAME_COLUMN = "threadName";
public static final String TIMEOUT_COLUMN = "TIMEOUT";
public static final String TOTAL_EXEC_PLUS_RSET_USAGE_TIME_COLUMN = "TOTAL_EXEC_PLUS_RSET_USAGE_TIME";
public static final String TRANSACTION_ISOLATION_COLUMN = "TRANSACTION_ISOLATION";
public static final String TSTAMP_COLUMN = "TSTAMP";

}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void getStatements(final LogSearchCriteria searchCriteria, final ResultSe
final boolean withFilledSql) {
final StringBuilder sql = new StringBuilder("select id, tstamp, statementType, rawSql, " //
+ "exec_plus_rset_usage_time, execution_time, rset_usage_time, fetch_time, "//
+ "nbRows, threadName, connectionNumber, timeout, autoCommit, error ");
+ "nbRows, threadName, connectionNumber, timeout, autoCommit, transaction_Isolation, error ");
if (withFilledSql) {
sql.append(", " + LogRepositoryConstants.FILLED_SQL_COLUMN);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ public LogRepositoryUpdateJdbc(final String name) {

addStatementLog = connectionUpdate
.prepareStatement("insert into statement_log (logId, tstamp, statementType, rawSql, filledSql, " //
+ "threadName, connectionId, timeout, autoCommit)"//
+ " values(?, ?, ?, ?, ?, ?, ?, ?, ?)");
+ "threadName, connectionId, timeout, autoCommit, transaction_Isolation)"//
+ " values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
addStatementLogWithAfterExecutionInfo = connectionUpdate
.prepareStatement("insert into statement_log (logId, tstamp, statementType, rawSql, filledSql, " //
+ "threadName, connectionId, timeout, autoCommit, executionDurationNanos, nbRows, " //
+ "threadName, connectionId, timeout, autoCommit, transaction_Isolation, executionDurationNanos, nbRows, " //
+ "fetchDurationNanos, rsetUsageDurationNanos, exception)"//
+ " values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
+ " values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
updateStatementLogWithResultSet = connectionUpdate.prepareStatement(
"update statement_log set fetchDurationNanos=?, rsetUsageDurationNanos=?, nbRows=? where logId=?");
updateStatementLogAfterExecution = connectionUpdate.prepareStatement(
Expand Down Expand Up @@ -183,6 +183,7 @@ public synchronized void addStatementLog(final StatementLog log) {
addStatementLog.setObject(i++, log.getConnectionUuid());
addStatementLog.setInt(i++, log.getTimeout());
addStatementLog.setBoolean(i++, log.isAutoCommit());
addStatementLog.setInt(i++, log.getTransactionIsolation());
final int insertCount = addStatementLog.executeUpdate();
assert insertCount == 1;
} catch (final SQLException e) {
Expand All @@ -206,6 +207,7 @@ public synchronized void addStatementFullyExecutedLog(final Collection<Statement
addStatementLogWithAfterExecutionInfo.setObject(i++, log.getConnectionUuid());
addStatementLogWithAfterExecutionInfo.setInt(i++, log.getTimeout());
addStatementLogWithAfterExecutionInfo.setBoolean(i++, log.isAutoCommit());
addStatementLogWithAfterExecutionInfo.setInt(i++, log.getTransactionIsolation());
addStatementLogWithAfterExecutionInfo.setLong(i++, log.getExecutionTimeNanos());
addStatementLogWithAfterExecutionInfo.setObject(i++, log.getNbRowsIterated(), Types.INTEGER);
addStatementLogWithAfterExecutionInfo.setObject(i++, log.getFetchDurationNanos(), Types.BIGINT);
Expand Down Expand Up @@ -273,6 +275,7 @@ public synchronized void addBatchedPreparedStatementsLog(final BatchedPreparedSt
addStatementLog.setObject(i++, log.getConnectionUuid());
addStatementLog.setInt(i++, log.getTimeout());
addStatementLog.setBoolean(i++, log.isAutoCommit());
addStatementLog.setInt(i++, log.getTransactionIsolation());
addStatementLog.executeUpdate();

addBatchedStatementLog.setObject(1, log.getLogId());
Expand Down Expand Up @@ -302,6 +305,7 @@ public synchronized void addBatchedNonPreparedStatementsLog(final BatchedNonPrep
addStatementLog.setObject(i++, log.getConnectionUuid());
addStatementLog.setInt(i++, log.getTimeout());
addStatementLog.setBoolean(i++, log.isAutoCommit());
addStatementLog.setInt(i++, log.getTransactionIsolation());
addStatementLog.executeUpdate();

addBatchedStatementLog.setObject(1, log.getLogId());
Expand Down
Loading