@Test public void testfillParameters() throws Exception { final PreparedStatementValuesHolder valHolder = new PreparedStatementValuesHolder(); String filledSql; valHolder.put(1, new SqlTypedValue("toto$", Types.VARCHAR)); filledSql = PerfLogger.fillParameters("select * from toto where name = ?", valHolder, DatabaseType.ORACLE); Assert.assertEquals("select * from toto where name = 'toto$' ", filledSql); valHolder.put(2, new SqlTypedValue(36, Types.INTEGER)); filledSql = PerfLogger.fillParameters("select * from toto where name = ? and age < ?", valHolder, DatabaseType.ORACLE); Assert.assertEquals("select * from toto where name = 'toto$' and age < 36 ", filledSql); valHolder.put(1, new SqlTypedValue(null, Types.VARCHAR)); filledSql = PerfLogger.fillParameters("select * from toto where name = ?", valHolder, DatabaseType.ORACLE); Assert.assertEquals("select * from toto where name = NULL ", filledSql); valHolder.put(1, new SqlTypedValue(null, Types.DATE)); filledSql = PerfLogger.fillParameters("select * from toto where param = ?", valHolder, DatabaseType.ORACLE); Assert.assertEquals("select * from toto where param = NULL ", filledSql); valHolder.put(1, new SqlTypedValue(java.sql.Date.valueOf("2013-03-04"), Types.DATE)); filledSql = PerfLogger.fillParameters("select * from toto where param = ?", valHolder, DatabaseType.ORACLE); Assert.assertEquals("select * from toto where param = date'2013-03-04' ", filledSql); final String dateStr = "2011-07-15T13:45:56.123"; final Date utilDate = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS").parse(dateStr); valHolder.put(1, new SqlTypedValue(utilDate, Types.DATE)); filledSql = PerfLogger.fillParameters("select * from toto where param = ?", valHolder, DatabaseType.ORACLE); Assert.assertEquals( "select * from toto where param = cast(timestamp'2011-07-15 13:45:56.123' as DATE) ", filledSql); final Timestamp tstamp = Timestamp.valueOf("2011-07-15 13:45:56.123"); valHolder.put(1, new SqlTypedValue(tstamp, Types.TIMESTAMP)); filledSql = PerfLogger.fillParameters("select * from toto where param = ?", valHolder, DatabaseType.ORACLE); Assert.assertEquals("select * from toto where param = timestamp'" + tstamp + "' ", filledSql); valHolder.put(1, new SqlTypedValue(new Object(), Types.CLOB)); filledSql = PerfLogger.fillParameters("select * from toto where param = ?", valHolder, DatabaseType.ORACLE); Assert.assertEquals("select * from toto where param = ? ", filledSql); }
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);  }