@SuppressWarnings("null") @Test public void testgetStatementsGroupByFilledSQL_filterCommits() { final List<StatementFullyExecutedLog> logs = insert3Logs(); final StatementFullyExecutedLog log1 = logs.get(0); repositoryUpdate.addTxCompletionLog(new TxCompleteLog(log1.getConnectionUuid(), System.currentTimeMillis(), TxCompletionType.COMMIT, 321, "mythread", null)); final LogSearchCriteria searchCriteria = new LogSearchCriteria(); searchCriteria.setRemoveTransactionCompletions(false); repositoryRead.getStatementsGroupByFilledSQL(searchCriteria, resultSet -> { assertTrue(resultSet.next()); assertTrue(resultSet.next()); assertTrue(resultSet.next()); assertFalse(resultSet.next()); }); searchCriteria.setRemoveTransactionCompletions(true); repositoryRead.getStatementsGroupByFilledSQL(searchCriteria, resultSet -> { assertTrue(resultSet.next()); assertTrue(resultSet.next()); assertFalse(resultSet.next()); }); }
@Override public void getStatementsGroupByFilledSQL(final LogSearchCriteria searchCriteria, final ResultSetAnalyzer analyzer) { final StringBuilder sql = new StringBuilder( "select * from (select min(id) as ID, statementType, rawSql, filledSql, count(1) as exec_count, " + "sum(executionDurationNanos+coalesce(rsetUsageDurationNanos,0)) as " + TOTAL_EXEC_PLUS_RSET_USAGE_TIME_COLUMN + ", " + "max(executionDurationNanos+coalesce(rsetUsageDurationNanos,0)) as " + MAX_EXEC_PLUS_RSET_USAGE_TIME_COLUMN + ", " + "min(executionDurationNanos+coalesce(rsetUsageDurationNanos,0)) as " + MIN_EXEC_PLUS_RSET_USAGE_TIME_COLUMN + ", " + "avg(executionDurationNanos+coalesce(rsetUsageDurationNanos,0)) as " + AVG_EXEC_PLUS_RSET_USAGE_TIME_COLUMN + " " + "from statement_log "); if (searchCriteria.getFilter() != null) { sql.append("where (UPPER(rawSql) like ? or UPPER(filledSql) like ?)"); } sql.append("group by statementType, rawSql, filledSql "); if (searchCriteria.getMinDurationNanos() != null) { sql.append("having sum(executionDurationNanos++coalesce(rsetUsageDurationNanos,0))>=?"); } sql.append(") "); if (searchCriteria.getSqlPassThroughFilter() != null) { addWhereClause(sql, false, searchCriteria.getSqlPassThroughFilter()); } if (searchCriteria.isRemoveTransactionCompletions()) { addWhereClause(sql, false, "statementType<>" + StatementType.TRANSACTION.getId()); } sql.append(" order by " + TOTAL_EXEC_PLUS_RSET_USAGE_TIME_COLUMN + " desc"); try (PreparedStatement statement = connectionRead.prepareStatement(sql.toString())) { applyParametersForWhereClause(searchCriteria, statement); try (ResultSet resultSet = statement.executeQuery()) { analyzer.analyze(resultSet); } } catch (final SQLException e) { throw new RuntimeException(e); } }
LogRepositoryReadJdbc implements LogRepositoryRead { @Override public void getStatementsGroupByFilledSQL(final LogSearchCriteria searchCriteria, final ResultSetAnalyzer analyzer) { final StringBuilder sql = new StringBuilder( "select * from (select min(id) as ID, statementType, rawSql, filledSql, count(1) as exec_count, " + "sum(executionDurationNanos+coalesce(rsetUsageDurationNanos,0)) as " + TOTAL_EXEC_PLUS_RSET_USAGE_TIME_COLUMN + ", " + "max(executionDurationNanos+coalesce(rsetUsageDurationNanos,0)) as " + MAX_EXEC_PLUS_RSET_USAGE_TIME_COLUMN + ", " + "min(executionDurationNanos+coalesce(rsetUsageDurationNanos,0)) as " + MIN_EXEC_PLUS_RSET_USAGE_TIME_COLUMN + ", " + "avg(executionDurationNanos+coalesce(rsetUsageDurationNanos,0)) as " + AVG_EXEC_PLUS_RSET_USAGE_TIME_COLUMN + " " + "from statement_log "); if (searchCriteria.getFilter() != null) { sql.append("where (UPPER(rawSql) like ? or UPPER(filledSql) like ?)"); } sql.append("group by statementType, rawSql, filledSql "); if (searchCriteria.getMinDurationNanos() != null) { sql.append("having sum(executionDurationNanos++coalesce(rsetUsageDurationNanos,0))>=?"); } sql.append(") "); if (searchCriteria.getSqlPassThroughFilter() != null) { addWhereClause(sql, false, searchCriteria.getSqlPassThroughFilter()); } if (searchCriteria.isRemoveTransactionCompletions()) { addWhereClause(sql, false, "statementType<>" + StatementType.TRANSACTION.getId()); } sql.append(" order by " + TOTAL_EXEC_PLUS_RSET_USAGE_TIME_COLUMN + " desc"); try (PreparedStatement statement = connectionRead.prepareStatement(sql.toString())) { applyParametersForWhereClause(searchCriteria, statement); try (ResultSet resultSet = statement.executeQuery()) { analyzer.analyze(resultSet); } } catch (final SQLException e) { throw new RuntimeException(e); } } }
LogRepositoryReadJdbc implements LogRepositoryRead { @Override public void getStatementsGroupByFilledSQL(final LogSearchCriteria searchCriteria, final ResultSetAnalyzer analyzer) { final StringBuilder sql = new StringBuilder( "select * from (select min(id) as ID, statementType, rawSql, filledSql, count(1) as exec_count, " + "sum(executionDurationNanos+coalesce(rsetUsageDurationNanos,0)) as " + TOTAL_EXEC_PLUS_RSET_USAGE_TIME_COLUMN + ", " + "max(executionDurationNanos+coalesce(rsetUsageDurationNanos,0)) as " + MAX_EXEC_PLUS_RSET_USAGE_TIME_COLUMN + ", " + "min(executionDurationNanos+coalesce(rsetUsageDurationNanos,0)) as " + MIN_EXEC_PLUS_RSET_USAGE_TIME_COLUMN + ", " + "avg(executionDurationNanos+coalesce(rsetUsageDurationNanos,0)) as " + AVG_EXEC_PLUS_RSET_USAGE_TIME_COLUMN + " " + "from statement_log "); if (searchCriteria.getFilter() != null) { sql.append("where (UPPER(rawSql) like ? or UPPER(filledSql) like ?)"); } sql.append("group by statementType, rawSql, filledSql "); if (searchCriteria.getMinDurationNanos() != null) { sql.append("having sum(executionDurationNanos++coalesce(rsetUsageDurationNanos,0))>=?"); } sql.append(") "); if (searchCriteria.getSqlPassThroughFilter() != null) { addWhereClause(sql, false, searchCriteria.getSqlPassThroughFilter()); } if (searchCriteria.isRemoveTransactionCompletions()) { addWhereClause(sql, false, "statementType<>" + StatementType.TRANSACTION.getId()); } sql.append(" order by " + TOTAL_EXEC_PLUS_RSET_USAGE_TIME_COLUMN + " desc"); try (PreparedStatement statement = connectionRead.prepareStatement(sql.toString())) { applyParametersForWhereClause(searchCriteria, statement); try (ResultSet resultSet = statement.executeQuery()) { analyzer.analyze(resultSet); } } catch (final SQLException e) { throw new RuntimeException(e); } } LogRepositoryReadJdbc(final String dbName); }
LogRepositoryReadJdbc implements LogRepositoryRead { @Override public void getStatementsGroupByFilledSQL(final LogSearchCriteria searchCriteria, final ResultSetAnalyzer analyzer) { final StringBuilder sql = new StringBuilder( "select * from (select min(id) as ID, statementType, rawSql, filledSql, count(1) as exec_count, " + "sum(executionDurationNanos+coalesce(rsetUsageDurationNanos,0)) as " + TOTAL_EXEC_PLUS_RSET_USAGE_TIME_COLUMN + ", " + "max(executionDurationNanos+coalesce(rsetUsageDurationNanos,0)) as " + MAX_EXEC_PLUS_RSET_USAGE_TIME_COLUMN + ", " + "min(executionDurationNanos+coalesce(rsetUsageDurationNanos,0)) as " + MIN_EXEC_PLUS_RSET_USAGE_TIME_COLUMN + ", " + "avg(executionDurationNanos+coalesce(rsetUsageDurationNanos,0)) as " + AVG_EXEC_PLUS_RSET_USAGE_TIME_COLUMN + " " + "from statement_log "); if (searchCriteria.getFilter() != null) { sql.append("where (UPPER(rawSql) like ? or UPPER(filledSql) like ?)"); } sql.append("group by statementType, rawSql, filledSql "); if (searchCriteria.getMinDurationNanos() != null) { sql.append("having sum(executionDurationNanos++coalesce(rsetUsageDurationNanos,0))>=?"); } sql.append(") "); if (searchCriteria.getSqlPassThroughFilter() != null) { addWhereClause(sql, false, searchCriteria.getSqlPassThroughFilter()); } if (searchCriteria.isRemoveTransactionCompletions()) { addWhereClause(sql, false, "statementType<>" + StatementType.TRANSACTION.getId()); } sql.append(" order by " + TOTAL_EXEC_PLUS_RSET_USAGE_TIME_COLUMN + " desc"); try (PreparedStatement statement = connectionRead.prepareStatement(sql.toString())) { applyParametersForWhereClause(searchCriteria, statement); try (ResultSet resultSet = statement.executeQuery()) { analyzer.analyze(resultSet); } } catch (final SQLException e) { throw new RuntimeException(e); } } LogRepositoryReadJdbc(final String dbName); @Override void dispose(); @Override void getStatements(final LogSearchCriteria searchCriteria, final ResultSetAnalyzer analyzer,
            final boolean withFilledSql); @Override void getStatementsGroupByRawSQL(final LogSearchCriteria searchCriteria, final ResultSetAnalyzer analyzer); @Override void getStatementsGroupByFilledSQL(final LogSearchCriteria searchCriteria,
            final ResultSetAnalyzer analyzer); @Nullable @Override DetailedViewStatementLog getStatementLog(final long id); @Override int countStatements(); @Override long getTotalExecAndFetchTimeNanos(); @Override long getTotalExecAndFetchTimeNanos(final LogSearchCriteria searchCriteria); @Override void getBatchStatementExecutions(final UUID logId, final ResultSetAnalyzer analyzer); }
LogRepositoryReadJdbc implements LogRepositoryRead { @Override public void getStatementsGroupByFilledSQL(final LogSearchCriteria searchCriteria, final ResultSetAnalyzer analyzer) { final StringBuilder sql = new StringBuilder( "select * from (select min(id) as ID, statementType, rawSql, filledSql, count(1) as exec_count, " + "sum(executionDurationNanos+coalesce(rsetUsageDurationNanos,0)) as " + TOTAL_EXEC_PLUS_RSET_USAGE_TIME_COLUMN + ", " + "max(executionDurationNanos+coalesce(rsetUsageDurationNanos,0)) as " + MAX_EXEC_PLUS_RSET_USAGE_TIME_COLUMN + ", " + "min(executionDurationNanos+coalesce(rsetUsageDurationNanos,0)) as " + MIN_EXEC_PLUS_RSET_USAGE_TIME_COLUMN + ", " + "avg(executionDurationNanos+coalesce(rsetUsageDurationNanos,0)) as " + AVG_EXEC_PLUS_RSET_USAGE_TIME_COLUMN + " " + "from statement_log "); if (searchCriteria.getFilter() != null) { sql.append("where (UPPER(rawSql) like ? or UPPER(filledSql) like ?)"); } sql.append("group by statementType, rawSql, filledSql "); if (searchCriteria.getMinDurationNanos() != null) { sql.append("having sum(executionDurationNanos++coalesce(rsetUsageDurationNanos,0))>=?"); } sql.append(") "); if (searchCriteria.getSqlPassThroughFilter() != null) { addWhereClause(sql, false, searchCriteria.getSqlPassThroughFilter()); } if (searchCriteria.isRemoveTransactionCompletions()) { addWhereClause(sql, false, "statementType<>" + StatementType.TRANSACTION.getId()); } sql.append(" order by " + TOTAL_EXEC_PLUS_RSET_USAGE_TIME_COLUMN + " desc"); try (PreparedStatement statement = connectionRead.prepareStatement(sql.toString())) { applyParametersForWhereClause(searchCriteria, statement); try (ResultSet resultSet = statement.executeQuery()) { analyzer.analyze(resultSet); } } catch (final SQLException e) { throw new RuntimeException(e); } } LogRepositoryReadJdbc(final String dbName); @Override void dispose(); @Override void getStatements(final LogSearchCriteria searchCriteria, final ResultSetAnalyzer analyzer,
            final boolean withFilledSql); @Override void getStatementsGroupByRawSQL(final LogSearchCriteria searchCriteria, final ResultSetAnalyzer analyzer); @Override void getStatementsGroupByFilledSQL(final LogSearchCriteria searchCriteria,
            final ResultSetAnalyzer analyzer); @Nullable @Override DetailedViewStatementLog getStatementLog(final long id); @Override int countStatements(); @Override long getTotalExecAndFetchTimeNanos(); @Override long getTotalExecAndFetchTimeNanos(final LogSearchCriteria searchCriteria); @Override void getBatchStatementExecutions(final UUID logId, final ResultSetAnalyzer analyzer);  }