@Test public void testaddBatchedPreparedStatementsLog() { final StatementLog log = insert1Log(); final List<String> sqlList = Arrays.asList("st1", "st2", "st3"); final BatchedPreparedStatementsLog batchedLogs = new BatchedPreparedStatementsLog(log.getConnectionUuid(), randomUUID(), System.currentTimeMillis(), "myRaw stmt", sqlList, "myThread", 13, true, 1); repositoryUpdate.addBatchedPreparedStatementsLog(batchedLogs); assertEquals(2, countRowsInTable("statement_log")); assertEquals(3, countRowsInTable("batched_statement_log")); final StatementExecutedLog statementExecutedLog = new StatementExecutedLog(batchedLogs.getLogId(), 123, null, "myexception"); repositoryUpdate.updateLogAfterExecution(statementExecutedLog); repositoryRead.getStatements(new LogSearchCriteria(), resultSet -> { resultSet.next(); resultSet.next(); assertEquals(2, resultSet.getLong(ID_COLUMN)); assertEquals(batchedLogs.getRawSql(), resultSet.getString(LogRepositoryConstants.RAW_SQL_COLUMN)); assertEquals(batchedLogs.isAutoCommit(), resultSet.getBoolean(LogRepositoryConstants.AUTOCOMMIT_COLUMN)); assertEquals(batchedLogs.getTransactionIsolation(), resultSet.getInt(TRANSACTION_ISOLATION_COLUMN)); assertEquals(0, resultSet.getInt(LogRepositoryConstants.FETCH_TIME_COLUMN)); assertEquals(0, resultSet.getInt(LogRepositoryConstants.RSET_USAGE_TIME)); assertEquals(statementExecutedLog.getExecutionTimeNanos(), resultSet.getInt(LogRepositoryConstants.EXEC_TIME_COLUMN)); assertEquals(statementExecutedLog.getExecutionTimeNanos(), resultSet.getInt(LogRepositoryConstants.EXEC_PLUS_RSET_USAGE_TIME)); assertEquals(0, resultSet.getInt(LogRepositoryConstants.NB_ROWS_COLUMN)); assertEquals(batchedLogs.getThreadName(), resultSet.getString(LogRepositoryConstants.THREAD_NAME_COLUMN)); assertEquals(batchedLogs.getTimeout(), resultSet.getInt(LogRepositoryConstants.TIMEOUT_COLUMN)); assertEquals(batchedLogs.getTimestamp(), resultSet.getTimestamp(LogRepositoryConstants.TSTAMP_COLUMN).getTime()); assertEquals(batchedLogs.getStatementType().getId(), resultSet.getInt(LogRepositoryConstants.STMT_TYPE_COLUMN)); assertTrue(resultSet.getBoolean(LogRepositoryConstants.ERROR_COLUMN)); }, false); }
@Override public synchronized void addBatchedPreparedStatementsLog(final BatchedPreparedStatementsLog log) { LOGGER.debug("addBatchedPreparedStatementsLog:{}", log); try { int i = 1; addStatementLog.setObject(i++, log.getLogId()); addStatementLog.setTimestamp(i++, new Timestamp(log.getTimestamp())); addStatementLog.setInt(i++, log.getStatementType().getId()); addStatementLog.setString(i++, log.getRawSql()); addStatementLog.setString(i++, "(" + log.getSqlList().size() + " batched statements, click for details)"); addStatementLog.setString(i++, log.getThreadName()); 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()); for (int j = 0; j < log.getSqlList().size(); j++) { addBatchedStatementLog.setInt(2, j); addBatchedStatementLog.setString(3, log.getSqlList().get(j)); addBatchedStatementLog.addBatch(); } addBatchedStatementLog.executeBatch(); } catch (final SQLException e) { throw new RuntimeException(e); } lastModificationTime = System.currentTimeMillis(); }
LogRepositoryUpdateJdbc implements LogRepositoryUpdate { @Override public synchronized void addBatchedPreparedStatementsLog(final BatchedPreparedStatementsLog log) { LOGGER.debug("addBatchedPreparedStatementsLog:{}", log); try { int i = 1; addStatementLog.setObject(i++, log.getLogId()); addStatementLog.setTimestamp(i++, new Timestamp(log.getTimestamp())); addStatementLog.setInt(i++, log.getStatementType().getId()); addStatementLog.setString(i++, log.getRawSql()); addStatementLog.setString(i++, "(" + log.getSqlList().size() + " batched statements, click for details)"); addStatementLog.setString(i++, log.getThreadName()); 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()); for (int j = 0; j < log.getSqlList().size(); j++) { addBatchedStatementLog.setInt(2, j); addBatchedStatementLog.setString(3, log.getSqlList().get(j)); addBatchedStatementLog.addBatch(); } addBatchedStatementLog.executeBatch(); } catch (final SQLException e) { throw new RuntimeException(e); } lastModificationTime = System.currentTimeMillis(); } }
LogRepositoryUpdateJdbc implements LogRepositoryUpdate { @Override public synchronized void addBatchedPreparedStatementsLog(final BatchedPreparedStatementsLog log) { LOGGER.debug("addBatchedPreparedStatementsLog:{}", log); try { int i = 1; addStatementLog.setObject(i++, log.getLogId()); addStatementLog.setTimestamp(i++, new Timestamp(log.getTimestamp())); addStatementLog.setInt(i++, log.getStatementType().getId()); addStatementLog.setString(i++, log.getRawSql()); addStatementLog.setString(i++, "(" + log.getSqlList().size() + " batched statements, click for details)"); addStatementLog.setString(i++, log.getThreadName()); 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()); for (int j = 0; j < log.getSqlList().size(); j++) { addBatchedStatementLog.setInt(2, j); addBatchedStatementLog.setString(3, log.getSqlList().get(j)); addBatchedStatementLog.addBatch(); } addBatchedStatementLog.executeBatch(); } catch (final SQLException e) { throw new RuntimeException(e); } lastModificationTime = System.currentTimeMillis(); } LogRepositoryUpdateJdbc(final String name); }
LogRepositoryUpdateJdbc implements LogRepositoryUpdate { @Override public synchronized void addBatchedPreparedStatementsLog(final BatchedPreparedStatementsLog log) { LOGGER.debug("addBatchedPreparedStatementsLog:{}", log); try { int i = 1; addStatementLog.setObject(i++, log.getLogId()); addStatementLog.setTimestamp(i++, new Timestamp(log.getTimestamp())); addStatementLog.setInt(i++, log.getStatementType().getId()); addStatementLog.setString(i++, log.getRawSql()); addStatementLog.setString(i++, "(" + log.getSqlList().size() + " batched statements, click for details)"); addStatementLog.setString(i++, log.getThreadName()); 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()); for (int j = 0; j < log.getSqlList().size(); j++) { addBatchedStatementLog.setInt(2, j); addBatchedStatementLog.setString(3, log.getSqlList().get(j)); addBatchedStatementLog.addBatch(); } addBatchedStatementLog.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 addBatchedPreparedStatementsLog(final BatchedPreparedStatementsLog log) { LOGGER.debug("addBatchedPreparedStatementsLog:{}", log); try { int i = 1; addStatementLog.setObject(i++, log.getLogId()); addStatementLog.setTimestamp(i++, new Timestamp(log.getTimestamp())); addStatementLog.setInt(i++, log.getStatementType().getId()); addStatementLog.setString(i++, log.getRawSql()); addStatementLog.setString(i++, "(" + log.getSqlList().size() + " batched statements, click for details)"); addStatementLog.setString(i++, log.getThreadName()); 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()); for (int j = 0; j < log.getSqlList().size(); j++) { addBatchedStatementLog.setInt(2, j); addBatchedStatementLog.setString(3, log.getSqlList().get(j)); addBatchedStatementLog.addBatch(); } addBatchedStatementLog.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; }