@Test public void replaceParametersWithBlockCommentsMultiLine(){ final PreparedStatementValuesHolder valHolder = new PreparedStatementValuesHolder(); valHolder.put(1, new SqlTypedValue("toto$", Types.VARCHAR)); valHolder.put(2, new SqlTypedValue("toto2$", Types.VARCHAR)); valHolder.put(3, new SqlTypedValue("dummy", Types.VARCHAR)); String sqlStatement ="insert into emp (?,?)--??ending comment"; String filledSql = PerfLogger.fillParameters(sqlStatement, valHolder, DatabaseType.ORACLE); Assert.assertEquals("insert into emp ('toto$' ,'toto2$' )--??ending comment", filledSql); Assert.assertFalse(filledSql.contains("dummy")); }
static String fillParameters(final String preparedStatementSql, final PreparedStatementValuesHolder pstmtValues, final DatabaseType databaseType) { Matcher matcherOnPstmtParameters = PSTMT_PARAMETER_PATTERN.matcher(preparedStatementSql); StringBuilder newSQLWithValues = new StringBuilder(); int lastReplacementIndex = 0; int i = 0; while (matcherOnPstmtParameters.find()) { if (matcherOnPstmtParameters.group(1) != null) { i++; final SqlTypedValue sqlTypedValue = pstmtValues.get(i); if (sqlTypedValue != null) { final String valueAsString = getValueAsString(sqlTypedValue, databaseType); newSQLWithValues.append(preparedStatementSql.substring(lastReplacementIndex, matcherOnPstmtParameters.start(1))); newSQLWithValues.append(valueAsString); lastReplacementIndex = matcherOnPstmtParameters.end(1); } } } newSQLWithValues.append(preparedStatementSql.substring(lastReplacementIndex)); return newSQLWithValues.toString(); }
PerfLogger { static String fillParameters(final String preparedStatementSql, final PreparedStatementValuesHolder pstmtValues, final DatabaseType databaseType) { Matcher matcherOnPstmtParameters = PSTMT_PARAMETER_PATTERN.matcher(preparedStatementSql); StringBuilder newSQLWithValues = new StringBuilder(); int lastReplacementIndex = 0; int i = 0; while (matcherOnPstmtParameters.find()) { if (matcherOnPstmtParameters.group(1) != null) { i++; final SqlTypedValue sqlTypedValue = pstmtValues.get(i); if (sqlTypedValue != null) { final String valueAsString = getValueAsString(sqlTypedValue, databaseType); newSQLWithValues.append(preparedStatementSql.substring(lastReplacementIndex, matcherOnPstmtParameters.start(1))); newSQLWithValues.append(valueAsString); lastReplacementIndex = matcherOnPstmtParameters.end(1); } } } newSQLWithValues.append(preparedStatementSql.substring(lastReplacementIndex)); return newSQLWithValues.toString(); } }
PerfLogger { static String fillParameters(final String preparedStatementSql, final PreparedStatementValuesHolder pstmtValues, final DatabaseType databaseType) { Matcher matcherOnPstmtParameters = PSTMT_PARAMETER_PATTERN.matcher(preparedStatementSql); StringBuilder newSQLWithValues = new StringBuilder(); int lastReplacementIndex = 0; int i = 0; while (matcherOnPstmtParameters.find()) { if (matcherOnPstmtParameters.group(1) != null) { i++; final SqlTypedValue sqlTypedValue = pstmtValues.get(i); if (sqlTypedValue != null) { final String valueAsString = getValueAsString(sqlTypedValue, databaseType); newSQLWithValues.append(preparedStatementSql.substring(lastReplacementIndex, matcherOnPstmtParameters.start(1))); newSQLWithValues.append(valueAsString); lastReplacementIndex = matcherOnPstmtParameters.end(1); } } } newSQLWithValues.append(preparedStatementSql.substring(lastReplacementIndex)); return newSQLWithValues.toString(); }  }
PerfLogger { static String fillParameters(final String preparedStatementSql, final PreparedStatementValuesHolder pstmtValues, final DatabaseType databaseType) { Matcher matcherOnPstmtParameters = PSTMT_PARAMETER_PATTERN.matcher(preparedStatementSql); StringBuilder newSQLWithValues = new StringBuilder(); int lastReplacementIndex = 0; int i = 0; while (matcherOnPstmtParameters.find()) { if (matcherOnPstmtParameters.group(1) != null) { i++; final SqlTypedValue sqlTypedValue = pstmtValues.get(i); if (sqlTypedValue != null) { final String valueAsString = getValueAsString(sqlTypedValue, databaseType); newSQLWithValues.append(preparedStatementSql.substring(lastReplacementIndex, matcherOnPstmtParameters.start(1))); newSQLWithValues.append(valueAsString); lastReplacementIndex = matcherOnPstmtParameters.end(1); } } } newSQLWithValues.append(preparedStatementSql.substring(lastReplacementIndex)); return newSQLWithValues.toString(); }  static void logBeforeStatement(final UUID connectionId, final UUID logId, final String sql,
            final StatementType statementType, final int timeout, final boolean autoCommit, final int transactionIsolation); 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 int transactionIsolation); static void logNonPreparedBatchedStatements(final UUID connectionId, final UUID logId,
            final List<String> batchedExecutions, final DatabaseType databaseType, final int timeout,
            final boolean autoCommit, final int transactionIsolation); 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 int transactionIsolation); static void logStatementExecuted(final UUID logId, final long durationNanos,
            @Nullable final Long updateCount, @Nullable final Throwable sqlException); static void logClosedResultSet(final UUID logId, final long resultSetIterationTimeNanos,
            final long fetchDurationNanos, final int nbRowsIterated); static void logTransactionComplete(final UUID connectionUuid, final long startTimeStamp,
            final TxCompletionType txCompletionType, final long durationNanos,
            @Nullable final String savePointDescription); }
PerfLogger { static String fillParameters(final String preparedStatementSql, final PreparedStatementValuesHolder pstmtValues, final DatabaseType databaseType) { Matcher matcherOnPstmtParameters = PSTMT_PARAMETER_PATTERN.matcher(preparedStatementSql); StringBuilder newSQLWithValues = new StringBuilder(); int lastReplacementIndex = 0; int i = 0; while (matcherOnPstmtParameters.find()) { if (matcherOnPstmtParameters.group(1) != null) { i++; final SqlTypedValue sqlTypedValue = pstmtValues.get(i); if (sqlTypedValue != null) { final String valueAsString = getValueAsString(sqlTypedValue, databaseType); newSQLWithValues.append(preparedStatementSql.substring(lastReplacementIndex, matcherOnPstmtParameters.start(1))); newSQLWithValues.append(valueAsString); lastReplacementIndex = matcherOnPstmtParameters.end(1); } } } newSQLWithValues.append(preparedStatementSql.substring(lastReplacementIndex)); return newSQLWithValues.toString(); }  static void logBeforeStatement(final UUID connectionId, final UUID logId, final String sql,
            final StatementType statementType, final int timeout, final boolean autoCommit, final int transactionIsolation); 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 int transactionIsolation); static void logNonPreparedBatchedStatements(final UUID connectionId, final UUID logId,
            final List<String> batchedExecutions, final DatabaseType databaseType, final int timeout,
            final boolean autoCommit, final int transactionIsolation); 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 int transactionIsolation); static void logStatementExecuted(final UUID logId, final long durationNanos,
            @Nullable final Long updateCount, @Nullable final Throwable sqlException); static void logClosedResultSet(final UUID logId, final long resultSetIterationTimeNanos,
            final long fetchDurationNanos, final int nbRowsIterated); static void logTransactionComplete(final UUID connectionUuid, final long startTimeStamp,
            final TxCompletionType txCompletionType, final long durationNanos,
            @Nullable final String savePointDescription);  }