@Test public void testgetValueAsString_string() { String val; val = PerfLogger.getValueAsString(new SqlTypedValue("toto", Types.VARCHAR), DatabaseType.ORACLE); Assert.assertEquals("'toto' ", val); val = PerfLogger.getValueAsString(new SqlTypedValue("hel'lo", Types.VARCHAR), DatabaseType.ORACLE); Assert.assertEquals("'hel''lo' ", val); val = PerfLogger.getValueAsString(new SqlTypedValue("java's cool, it''s", Types.VARCHAR), DatabaseType.ORACLE); Assert.assertEquals("'java''s cool, it''''s' ", val); }
static String getValueAsString(final SqlTypedValue sqlTypedValue, final DatabaseType databaseType) { final Object value = sqlTypedValue.value; final String setter = sqlTypedValue.setter; String sqlTypeStr = setter; final int sqlType = sqlTypedValue.sqlType != null ? sqlTypedValue.sqlType : 0; if (sqlTypeStr == null) { sqlTypeStr = typesMap.get(sqlType); if (sqlTypeStr == null) { sqlTypeStr = "TYPE=" + sqlType; } } String additionalComment = null; final StringBuilder strBuilder = new StringBuilder(20); if (value == null) { strBuilder.append("NULL"); } else if (sqlType == Types.CHAR || sqlType == Types.VARCHAR || sqlType == -15 || sqlType == -9 || "setString".equals(setter) || "setNString".equals(setter)) { strBuilder.append("'" + value.toString().replace("'", "''") + "'"); } else if (sqlType == Types.DATE || "setDate".equals(setter) || value instanceof java.sql.Date) { java.sql.Date sqlDate; if (value instanceof java.sql.Date) { sqlDate = (java.sql.Date) value; } else { sqlDate = new java.sql.Date(((java.util.Date) value).getTime()); } final java.sql.Date pureSqlDate = java.sql.Date.valueOf(sqlDate.toString()); if (sqlDate.getTime() == pureSqlDate.getTime()) { strBuilder.append("date'" + sqlDate.toString() + "'"); } else { strBuilder.append("cast(timestamp'" + new Timestamp(sqlDate.getTime()) + "' as DATE)"); additionalComment = " (non pure)"; } } else if (sqlType == Types.TIMESTAMP || "setTimestamp".equals(setter) || value instanceof java.sql.Timestamp) { Timestamp tstamp; if (value instanceof Timestamp) { tstamp = (Timestamp) value; } else { tstamp = new Timestamp(((java.util.Date) value).getTime()); } strBuilder.append("timestamp'" + tstamp.toString() + "'"); } else if (sqlType == Types.TIME || "setTime".equals(setter) || value instanceof java.sql.Time) { java.sql.Time sqlTime; if (value instanceof java.sql.Time) { sqlTime = (java.sql.Time) value; } else { sqlTime = new java.sql.Time(((java.util.Date) value).getTime()); } strBuilder.append("time'" + sqlTime.toString() + "'"); } else if (value instanceof Number) { strBuilder.append(value); } else if (value instanceof Boolean) { if (databaseType == DatabaseType.ORACLE) { strBuilder.append(((Boolean) value).booleanValue() ? 1 : 0); } else { strBuilder.append(value); } } else { strBuilder.append("?"); } strBuilder.append(" "); return strBuilder.toString(); }
PerfLogger { static String getValueAsString(final SqlTypedValue sqlTypedValue, final DatabaseType databaseType) { final Object value = sqlTypedValue.value; final String setter = sqlTypedValue.setter; String sqlTypeStr = setter; final int sqlType = sqlTypedValue.sqlType != null ? sqlTypedValue.sqlType : 0; if (sqlTypeStr == null) { sqlTypeStr = typesMap.get(sqlType); if (sqlTypeStr == null) { sqlTypeStr = "TYPE=" + sqlType; } } String additionalComment = null; final StringBuilder strBuilder = new StringBuilder(20); if (value == null) { strBuilder.append("NULL"); } else if (sqlType == Types.CHAR || sqlType == Types.VARCHAR || sqlType == -15 || sqlType == -9 || "setString".equals(setter) || "setNString".equals(setter)) { strBuilder.append("'" + value.toString().replace("'", "''") + "'"); } else if (sqlType == Types.DATE || "setDate".equals(setter) || value instanceof java.sql.Date) { java.sql.Date sqlDate; if (value instanceof java.sql.Date) { sqlDate = (java.sql.Date) value; } else { sqlDate = new java.sql.Date(((java.util.Date) value).getTime()); } final java.sql.Date pureSqlDate = java.sql.Date.valueOf(sqlDate.toString()); if (sqlDate.getTime() == pureSqlDate.getTime()) { strBuilder.append("date'" + sqlDate.toString() + "'"); } else { strBuilder.append("cast(timestamp'" + new Timestamp(sqlDate.getTime()) + "' as DATE)"); additionalComment = " (non pure)"; } } else if (sqlType == Types.TIMESTAMP || "setTimestamp".equals(setter) || value instanceof java.sql.Timestamp) { Timestamp tstamp; if (value instanceof Timestamp) { tstamp = (Timestamp) value; } else { tstamp = new Timestamp(((java.util.Date) value).getTime()); } strBuilder.append("timestamp'" + tstamp.toString() + "'"); } else if (sqlType == Types.TIME || "setTime".equals(setter) || value instanceof java.sql.Time) { java.sql.Time sqlTime; if (value instanceof java.sql.Time) { sqlTime = (java.sql.Time) value; } else { sqlTime = new java.sql.Time(((java.util.Date) value).getTime()); } strBuilder.append("time'" + sqlTime.toString() + "'"); } else if (value instanceof Number) { strBuilder.append(value); } else if (value instanceof Boolean) { if (databaseType == DatabaseType.ORACLE) { strBuilder.append(((Boolean) value).booleanValue() ? 1 : 0); } else { strBuilder.append(value); } } else { strBuilder.append("?"); } strBuilder.append(" "); return strBuilder.toString(); } }
PerfLogger { static String getValueAsString(final SqlTypedValue sqlTypedValue, final DatabaseType databaseType) { final Object value = sqlTypedValue.value; final String setter = sqlTypedValue.setter; String sqlTypeStr = setter; final int sqlType = sqlTypedValue.sqlType != null ? sqlTypedValue.sqlType : 0; if (sqlTypeStr == null) { sqlTypeStr = typesMap.get(sqlType); if (sqlTypeStr == null) { sqlTypeStr = "TYPE=" + sqlType; } } String additionalComment = null; final StringBuilder strBuilder = new StringBuilder(20); if (value == null) { strBuilder.append("NULL"); } else if (sqlType == Types.CHAR || sqlType == Types.VARCHAR || sqlType == -15 || sqlType == -9 || "setString".equals(setter) || "setNString".equals(setter)) { strBuilder.append("'" + value.toString().replace("'", "''") + "'"); } else if (sqlType == Types.DATE || "setDate".equals(setter) || value instanceof java.sql.Date) { java.sql.Date sqlDate; if (value instanceof java.sql.Date) { sqlDate = (java.sql.Date) value; } else { sqlDate = new java.sql.Date(((java.util.Date) value).getTime()); } final java.sql.Date pureSqlDate = java.sql.Date.valueOf(sqlDate.toString()); if (sqlDate.getTime() == pureSqlDate.getTime()) { strBuilder.append("date'" + sqlDate.toString() + "'"); } else { strBuilder.append("cast(timestamp'" + new Timestamp(sqlDate.getTime()) + "' as DATE)"); additionalComment = " (non pure)"; } } else if (sqlType == Types.TIMESTAMP || "setTimestamp".equals(setter) || value instanceof java.sql.Timestamp) { Timestamp tstamp; if (value instanceof Timestamp) { tstamp = (Timestamp) value; } else { tstamp = new Timestamp(((java.util.Date) value).getTime()); } strBuilder.append("timestamp'" + tstamp.toString() + "'"); } else if (sqlType == Types.TIME || "setTime".equals(setter) || value instanceof java.sql.Time) { java.sql.Time sqlTime; if (value instanceof java.sql.Time) { sqlTime = (java.sql.Time) value; } else { sqlTime = new java.sql.Time(((java.util.Date) value).getTime()); } strBuilder.append("time'" + sqlTime.toString() + "'"); } else if (value instanceof Number) { strBuilder.append(value); } else if (value instanceof Boolean) { if (databaseType == DatabaseType.ORACLE) { strBuilder.append(((Boolean) value).booleanValue() ? 1 : 0); } else { strBuilder.append(value); } } else { strBuilder.append("?"); } strBuilder.append(" "); return strBuilder.toString(); }  }
PerfLogger { static String getValueAsString(final SqlTypedValue sqlTypedValue, final DatabaseType databaseType) { final Object value = sqlTypedValue.value; final String setter = sqlTypedValue.setter; String sqlTypeStr = setter; final int sqlType = sqlTypedValue.sqlType != null ? sqlTypedValue.sqlType : 0; if (sqlTypeStr == null) { sqlTypeStr = typesMap.get(sqlType); if (sqlTypeStr == null) { sqlTypeStr = "TYPE=" + sqlType; } } String additionalComment = null; final StringBuilder strBuilder = new StringBuilder(20); if (value == null) { strBuilder.append("NULL"); } else if (sqlType == Types.CHAR || sqlType == Types.VARCHAR || sqlType == -15 || sqlType == -9 || "setString".equals(setter) || "setNString".equals(setter)) { strBuilder.append("'" + value.toString().replace("'", "''") + "'"); } else if (sqlType == Types.DATE || "setDate".equals(setter) || value instanceof java.sql.Date) { java.sql.Date sqlDate; if (value instanceof java.sql.Date) { sqlDate = (java.sql.Date) value; } else { sqlDate = new java.sql.Date(((java.util.Date) value).getTime()); } final java.sql.Date pureSqlDate = java.sql.Date.valueOf(sqlDate.toString()); if (sqlDate.getTime() == pureSqlDate.getTime()) { strBuilder.append("date'" + sqlDate.toString() + "'"); } else { strBuilder.append("cast(timestamp'" + new Timestamp(sqlDate.getTime()) + "' as DATE)"); additionalComment = " (non pure)"; } } else if (sqlType == Types.TIMESTAMP || "setTimestamp".equals(setter) || value instanceof java.sql.Timestamp) { Timestamp tstamp; if (value instanceof Timestamp) { tstamp = (Timestamp) value; } else { tstamp = new Timestamp(((java.util.Date) value).getTime()); } strBuilder.append("timestamp'" + tstamp.toString() + "'"); } else if (sqlType == Types.TIME || "setTime".equals(setter) || value instanceof java.sql.Time) { java.sql.Time sqlTime; if (value instanceof java.sql.Time) { sqlTime = (java.sql.Time) value; } else { sqlTime = new java.sql.Time(((java.util.Date) value).getTime()); } strBuilder.append("time'" + sqlTime.toString() + "'"); } else if (value instanceof Number) { strBuilder.append(value); } else if (value instanceof Boolean) { if (databaseType == DatabaseType.ORACLE) { strBuilder.append(((Boolean) value).booleanValue() ? 1 : 0); } else { strBuilder.append(value); } } else { strBuilder.append("?"); } strBuilder.append(" "); return strBuilder.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 getValueAsString(final SqlTypedValue sqlTypedValue, final DatabaseType databaseType) { final Object value = sqlTypedValue.value; final String setter = sqlTypedValue.setter; String sqlTypeStr = setter; final int sqlType = sqlTypedValue.sqlType != null ? sqlTypedValue.sqlType : 0; if (sqlTypeStr == null) { sqlTypeStr = typesMap.get(sqlType); if (sqlTypeStr == null) { sqlTypeStr = "TYPE=" + sqlType; } } String additionalComment = null; final StringBuilder strBuilder = new StringBuilder(20); if (value == null) { strBuilder.append("NULL"); } else if (sqlType == Types.CHAR || sqlType == Types.VARCHAR || sqlType == -15 || sqlType == -9 || "setString".equals(setter) || "setNString".equals(setter)) { strBuilder.append("'" + value.toString().replace("'", "''") + "'"); } else if (sqlType == Types.DATE || "setDate".equals(setter) || value instanceof java.sql.Date) { java.sql.Date sqlDate; if (value instanceof java.sql.Date) { sqlDate = (java.sql.Date) value; } else { sqlDate = new java.sql.Date(((java.util.Date) value).getTime()); } final java.sql.Date pureSqlDate = java.sql.Date.valueOf(sqlDate.toString()); if (sqlDate.getTime() == pureSqlDate.getTime()) { strBuilder.append("date'" + sqlDate.toString() + "'"); } else { strBuilder.append("cast(timestamp'" + new Timestamp(sqlDate.getTime()) + "' as DATE)"); additionalComment = " (non pure)"; } } else if (sqlType == Types.TIMESTAMP || "setTimestamp".equals(setter) || value instanceof java.sql.Timestamp) { Timestamp tstamp; if (value instanceof Timestamp) { tstamp = (Timestamp) value; } else { tstamp = new Timestamp(((java.util.Date) value).getTime()); } strBuilder.append("timestamp'" + tstamp.toString() + "'"); } else if (sqlType == Types.TIME || "setTime".equals(setter) || value instanceof java.sql.Time) { java.sql.Time sqlTime; if (value instanceof java.sql.Time) { sqlTime = (java.sql.Time) value; } else { sqlTime = new java.sql.Time(((java.util.Date) value).getTime()); } strBuilder.append("time'" + sqlTime.toString() + "'"); } else if (value instanceof Number) { strBuilder.append(value); } else if (value instanceof Boolean) { if (databaseType == DatabaseType.ORACLE) { strBuilder.append(((Boolean) value).booleanValue() ? 1 : 0); } else { strBuilder.append(value); } } else { strBuilder.append("?"); } strBuilder.append(" "); return strBuilder.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);  }