@Test public void testaddStatementFullyExecutedLog() { final Properties connProps = new Properties(); connProps.setProperty("myprop", "myval"); final ConnectionInfo connectionInfo = new ConnectionInfo(randomUUID(), 12, "jdbc:toto", new Date(), 12, connProps); repositoryUpdate.addConnection(connectionInfo); final List<StatementFullyExecutedLog> fullLogs = new ArrayList<>(); { final StatementLog log = new StatementLog(connectionInfo.getUuid(), randomUUID(), System.currentTimeMillis(), StatementType.BASE_NON_PREPARED_STMT, "myrawsql", Thread.currentThread().getName(), 123, true, 1); final StatementExecutedLog statementExecutedLog = new StatementExecutedLog(log.getLogId(), 234L, 456L, "myexception"); fullLogs.add(new StatementFullyExecutedLog(log, statementExecutedLog, null)); } { final StatementLog log = new StatementLog(connectionInfo.getUuid(), randomUUID(), System.currentTimeMillis(), StatementType.BASE_NON_PREPARED_STMT, "myrawsql", Thread.currentThread().getName(), 123, true, 1); final StatementExecutedLog statementExecutedLog = new StatementExecutedLog(log.getLogId(), 234L, 456L, "myexception"); final ResultSetLog resultSetLog = new ResultSetLog(log.getLogId(), 789L, 700L, 21); fullLogs.add(new StatementFullyExecutedLog(log, statementExecutedLog, resultSetLog)); } repositoryUpdate.addStatementFullyExecutedLog(fullLogs); assertEquals(2, countRowsInTable("statement_log")); repositoryRead.getStatements(new LogSearchCriteria(), resultSet -> { { resultSet.next(); final StatementFullyExecutedLog stmtLog = fullLogs.get(0); assertEquals(1, resultSet.getLong(ID_COLUMN)); assertEquals(stmtLog.getRawSql(), resultSet.getString(LogRepositoryConstants.RAW_SQL_COLUMN)); assertEquals(stmtLog.isAutoCommit(), resultSet.getBoolean(LogRepositoryConstants.AUTOCOMMIT_COLUMN)); assertEquals(stmtLog.getTransactionIsolation(), resultSet.getInt(TRANSACTION_ISOLATION_COLUMN)); assertEquals(12, resultSet.getInt(LogRepositoryConstants.CONNECTION_NUMBER_COLUMN)); resultSet.getLong(LogRepositoryConstants.RSET_USAGE_TIME); assertTrue(resultSet.wasNull()); resultSet.getLong(LogRepositoryConstants.FETCH_TIME_COLUMN); assertTrue(resultSet.wasNull()); assertEquals(stmtLog.getExecutionTimeNanos(), resultSet.getLong(LogRepositoryConstants.EXEC_TIME_COLUMN)); assertEquals(stmtLog.getExecutionTimeNanos(), resultSet.getLong(LogRepositoryConstants.EXEC_PLUS_RSET_USAGE_TIME)); resultSet.getInt(LogRepositoryConstants.NB_ROWS_COLUMN); assertTrue(resultSet.wasNull()); assertEquals(stmtLog.getThreadName(), resultSet.getString(LogRepositoryConstants.THREAD_NAME_COLUMN)); assertEquals(stmtLog.getTimeout(), resultSet.getInt(LogRepositoryConstants.TIMEOUT_COLUMN)); assertEquals(stmtLog.getTimestamp(), resultSet.getTimestamp(LogRepositoryConstants.TSTAMP_COLUMN).getTime()); assertEquals(stmtLog.getStatementType().getId(), resultSet.getInt(LogRepositoryConstants.STMT_TYPE_COLUMN)); assertTrue(resultSet.getBoolean(LogRepositoryConstants.ERROR_COLUMN)); } { resultSet.next(); final StatementFullyExecutedLog stmtLog = fullLogs.get(1); assertEquals(2, resultSet.getLong(ID_COLUMN)); assertEquals(stmtLog.getRawSql(), resultSet.getString(LogRepositoryConstants.RAW_SQL_COLUMN)); assertEquals(stmtLog.isAutoCommit(), resultSet.getBoolean(LogRepositoryConstants.AUTOCOMMIT_COLUMN)); assertEquals(stmtLog.getTransactionIsolation(), resultSet.getInt(TRANSACTION_ISOLATION_COLUMN)); assertEquals(12, resultSet.getInt(LogRepositoryConstants.CONNECTION_NUMBER_COLUMN)); assertEquals(stmtLog.getResultSetUsageDurationNanos().longValue(), resultSet.getLong(LogRepositoryConstants.RSET_USAGE_TIME)); assertEquals(stmtLog.getFetchDurationNanos().longValue(), resultSet.getLong(LogRepositoryConstants.FETCH_TIME_COLUMN)); assertEquals(stmtLog.getExecutionTimeNanos(), resultSet.getLong(LogRepositoryConstants.EXEC_TIME_COLUMN)); assertEquals(stmtLog.getExecutionTimeNanos() + stmtLog.getResultSetUsageDurationNanos(), resultSet.getLong(LogRepositoryConstants.EXEC_PLUS_RSET_USAGE_TIME)); assertEquals(stmtLog.getNbRowsIterated().intValue(), resultSet.getInt(LogRepositoryConstants.NB_ROWS_COLUMN)); assertEquals(stmtLog.getThreadName(), resultSet.getString(LogRepositoryConstants.THREAD_NAME_COLUMN)); assertEquals(stmtLog.getTimeout(), resultSet.getInt(LogRepositoryConstants.TIMEOUT_COLUMN)); assertEquals(stmtLog.getTimestamp(), resultSet.getTimestamp(LogRepositoryConstants.TSTAMP_COLUMN).getTime()); assertEquals(stmtLog.getStatementType().getId(), resultSet.getInt(LogRepositoryConstants.STMT_TYPE_COLUMN)); assertTrue(resultSet.getBoolean(LogRepositoryConstants.ERROR_COLUMN)); } }, false); }
@Override public synchronized void addStatementFullyExecutedLog(final Collection<StatementFullyExecutedLog> logs) { LOGGER.debug("addStatementLogWithAfterExecutionInfo"); try { for (final StatementFullyExecutedLog log : logs) { int i = 1; addStatementLogWithAfterExecutionInfo.setObject(i++, log.getLogId()); addStatementLogWithAfterExecutionInfo.setTimestamp(i++, new Timestamp(log.getTimestamp())); addStatementLogWithAfterExecutionInfo.setInt(i++, log.getStatementType().getId()); addStatementLogWithAfterExecutionInfo.setString(i++, log.getRawSql()); addStatementLogWithAfterExecutionInfo.setString(i++, log.getFilledSql()); addStatementLogWithAfterExecutionInfo.setString(i++, log.getThreadName()); 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); addStatementLogWithAfterExecutionInfo.setObject(i++, log.getResultSetUsageDurationNanos(), Types.BIGINT); addStatementLogWithAfterExecutionInfo.setString(i++, log.getSqlException()); addStatementLogWithAfterExecutionInfo.addBatch(); } addStatementLogWithAfterExecutionInfo.executeBatch(); } catch (final SQLException e) { throw new RuntimeException(e); } lastModificationTime = System.currentTimeMillis(); }
LogRepositoryUpdateJdbc implements LogRepositoryUpdate { @Override public synchronized void addStatementFullyExecutedLog(final Collection<StatementFullyExecutedLog> logs) { LOGGER.debug("addStatementLogWithAfterExecutionInfo"); try { for (final StatementFullyExecutedLog log : logs) { int i = 1; addStatementLogWithAfterExecutionInfo.setObject(i++, log.getLogId()); addStatementLogWithAfterExecutionInfo.setTimestamp(i++, new Timestamp(log.getTimestamp())); addStatementLogWithAfterExecutionInfo.setInt(i++, log.getStatementType().getId()); addStatementLogWithAfterExecutionInfo.setString(i++, log.getRawSql()); addStatementLogWithAfterExecutionInfo.setString(i++, log.getFilledSql()); addStatementLogWithAfterExecutionInfo.setString(i++, log.getThreadName()); 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); addStatementLogWithAfterExecutionInfo.setObject(i++, log.getResultSetUsageDurationNanos(), Types.BIGINT); addStatementLogWithAfterExecutionInfo.setString(i++, log.getSqlException()); addStatementLogWithAfterExecutionInfo.addBatch(); } addStatementLogWithAfterExecutionInfo.executeBatch(); } catch (final SQLException e) { throw new RuntimeException(e); } lastModificationTime = System.currentTimeMillis(); } }
LogRepositoryUpdateJdbc implements LogRepositoryUpdate { @Override public synchronized void addStatementFullyExecutedLog(final Collection<StatementFullyExecutedLog> logs) { LOGGER.debug("addStatementLogWithAfterExecutionInfo"); try { for (final StatementFullyExecutedLog log : logs) { int i = 1; addStatementLogWithAfterExecutionInfo.setObject(i++, log.getLogId()); addStatementLogWithAfterExecutionInfo.setTimestamp(i++, new Timestamp(log.getTimestamp())); addStatementLogWithAfterExecutionInfo.setInt(i++, log.getStatementType().getId()); addStatementLogWithAfterExecutionInfo.setString(i++, log.getRawSql()); addStatementLogWithAfterExecutionInfo.setString(i++, log.getFilledSql()); addStatementLogWithAfterExecutionInfo.setString(i++, log.getThreadName()); 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); addStatementLogWithAfterExecutionInfo.setObject(i++, log.getResultSetUsageDurationNanos(), Types.BIGINT); addStatementLogWithAfterExecutionInfo.setString(i++, log.getSqlException()); addStatementLogWithAfterExecutionInfo.addBatch(); } addStatementLogWithAfterExecutionInfo.executeBatch(); } catch (final SQLException e) { throw new RuntimeException(e); } lastModificationTime = System.currentTimeMillis(); } LogRepositoryUpdateJdbc(final String name); }
LogRepositoryUpdateJdbc implements LogRepositoryUpdate { @Override public synchronized void addStatementFullyExecutedLog(final Collection<StatementFullyExecutedLog> logs) { LOGGER.debug("addStatementLogWithAfterExecutionInfo"); try { for (final StatementFullyExecutedLog log : logs) { int i = 1; addStatementLogWithAfterExecutionInfo.setObject(i++, log.getLogId()); addStatementLogWithAfterExecutionInfo.setTimestamp(i++, new Timestamp(log.getTimestamp())); addStatementLogWithAfterExecutionInfo.setInt(i++, log.getStatementType().getId()); addStatementLogWithAfterExecutionInfo.setString(i++, log.getRawSql()); addStatementLogWithAfterExecutionInfo.setString(i++, log.getFilledSql()); addStatementLogWithAfterExecutionInfo.setString(i++, log.getThreadName()); 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); addStatementLogWithAfterExecutionInfo.setObject(i++, log.getResultSetUsageDurationNanos(), Types.BIGINT); addStatementLogWithAfterExecutionInfo.setString(i++, log.getSqlException()); addStatementLogWithAfterExecutionInfo.addBatch(); } addStatementLogWithAfterExecutionInfo.executeBatch(); } catch (final SQLException e) { throw new RuntimeException(e); } lastModificationTime = System.currentTimeMillis(); } LogRepositoryUpdateJdbc(final String name); @Override void dispose(); @Override synchronized void addStatementLog(final StatementLog log); @Override synchronized void addStatementFullyExecutedLog(final Collection<StatementFullyExecutedLog> logs); @Override synchronized void updateLogAfterExecution(final StatementExecutedLog log); @Override synchronized void updateLogWithResultSetLog(final ResultSetLog log); @Override synchronized void addBatchedPreparedStatementsLog(final BatchedPreparedStatementsLog log); @Override synchronized void addBatchedNonPreparedStatementsLog(final BatchedNonPreparedStatementsLog log); @Override synchronized void addConnection(final ConnectionInfo connectionInfo); @Override synchronized void addTxCompletionLog(final TxCompleteLog log); @Override void clear(); @Override void deleteStatementLog(final long... logIds); void deleteOldRowsIfTooMany(); @Override synchronized long getLastModificationTime(); @Override void setLastLostMessageTime(@Nullable final Long timestamp); @Override @Nullable Long getLastLostMessageTime(); }
LogRepositoryUpdateJdbc implements LogRepositoryUpdate { @Override public synchronized void addStatementFullyExecutedLog(final Collection<StatementFullyExecutedLog> logs) { LOGGER.debug("addStatementLogWithAfterExecutionInfo"); try { for (final StatementFullyExecutedLog log : logs) { int i = 1; addStatementLogWithAfterExecutionInfo.setObject(i++, log.getLogId()); addStatementLogWithAfterExecutionInfo.setTimestamp(i++, new Timestamp(log.getTimestamp())); addStatementLogWithAfterExecutionInfo.setInt(i++, log.getStatementType().getId()); addStatementLogWithAfterExecutionInfo.setString(i++, log.getRawSql()); addStatementLogWithAfterExecutionInfo.setString(i++, log.getFilledSql()); addStatementLogWithAfterExecutionInfo.setString(i++, log.getThreadName()); 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); addStatementLogWithAfterExecutionInfo.setObject(i++, log.getResultSetUsageDurationNanos(), Types.BIGINT); addStatementLogWithAfterExecutionInfo.setString(i++, log.getSqlException()); addStatementLogWithAfterExecutionInfo.addBatch(); } addStatementLogWithAfterExecutionInfo.executeBatch(); } catch (final SQLException e) { throw new RuntimeException(e); } lastModificationTime = System.currentTimeMillis(); } LogRepositoryUpdateJdbc(final String name); @Override void dispose(); @Override synchronized void addStatementLog(final StatementLog log); @Override synchronized void addStatementFullyExecutedLog(final Collection<StatementFullyExecutedLog> logs); @Override synchronized void updateLogAfterExecution(final StatementExecutedLog log); @Override synchronized void updateLogWithResultSetLog(final ResultSetLog log); @Override synchronized void addBatchedPreparedStatementsLog(final BatchedPreparedStatementsLog log); @Override synchronized void addBatchedNonPreparedStatementsLog(final BatchedNonPreparedStatementsLog log); @Override synchronized void addConnection(final ConnectionInfo connectionInfo); @Override synchronized void addTxCompletionLog(final TxCompleteLog log); @Override void clear(); @Override void deleteStatementLog(final long... logIds); void deleteOldRowsIfTooMany(); @Override synchronized long getLastModificationTime(); @Override void setLastLostMessageTime(@Nullable final Long timestamp); @Override @Nullable Long getLastLostMessageTime(); static final int SCHEMA_VERSION; }