diff --git a/src/main/java/org/libj/sql/Audit.java b/src/main/java/org/libj/sql/Audit.java index a059fad..cd0b8ee 100644 --- a/src/main/java/org/libj/sql/Audit.java +++ b/src/main/java/org/libj/sql/Audit.java @@ -62,7 +62,7 @@ protected boolean isDebugEnabled() { * @param sql The SQL log entry to log. * @param detail The detail log entry to log, which contains the {@code sql} string. */ - protected void trace(final StatementType statementType, final String sql, final String detail) { + protected void trace(final StatementType statementType, final CharSequence sql, final String detail) { final Logger logger; if (detail != null && (logger = logger()) != null) logger.trace(detail); @@ -76,7 +76,7 @@ protected void trace(final StatementType statementType, final String sql, final * @param detail The detail log entry to log, which contains the {@code sql} string. * @param exception If an exception has occurred during the invocation of the associated method. */ - protected void debug(final StatementType statementType, final String sql, final String detail, final Throwable exception) { + protected void debug(final StatementType statementType, final CharSequence sql, final String detail, final Throwable exception) { final Logger logger; if (detail != null && (logger = logger()) != null) logger.debug(detail); diff --git a/src/main/java/org/libj/sql/AuditConnection.java b/src/main/java/org/libj/sql/AuditConnection.java index 7bf8a1c..0abcf84 100644 --- a/src/main/java/org/libj/sql/AuditConnection.java +++ b/src/main/java/org/libj/sql/AuditConnection.java @@ -165,8 +165,6 @@ public AuditConnection(final Connection target) { /** * Returns a log entry for the provided parameters. * - * @param enabled If {@code true}, this method will return a log entry for the provided parameters. Otherwise if {@code false}, this - * method will return {@code null}. * @param method The name of the method for which the log entry is being created. * @param newLine If {@code true}, a newline character {@code '\n'} will be appended before the {@code sql} string. If * {@code false}, no newline character will be appended before the {@code sql} string. @@ -187,10 +185,7 @@ public AuditConnection(final Connection target) { * {@link ResultSet#CLOSE_CURSORS_AT_COMMIT}, or {@code Integer.MIN_VALUE} for the parameter to be omitted. * @return A log entry for the provided parameters. */ - protected String log(final boolean enabled, final String method, final boolean newLine, final String sql, final int autoGeneratedKeys, final int[] columnIndexes, final String[] columnNames, final int resultSetType, final int resultSetConcurrency, final int resultSetHoldability) { - if (!enabled) - return null; - + protected String log(final String method, final boolean newLine, final String sql, final int autoGeneratedKeys, final int[] columnIndexes, final String[] columnNames, final int resultSetType, final int resultSetConcurrency, final int resultSetHoldability) { final StringBuilder b = AuditUtil.log(this, method, this, newLine, new StringBuilder(sql)); if (autoGeneratedKeys != Integer.MIN_VALUE) { b.append(", ").append(autoGeneratedKeys); @@ -308,7 +303,9 @@ public PreparedStatement prepareStatement(final String sql) throws SQLException if (traceOpenConnections) openConnections.put(this, new Trace()); - trace(null, log(isTraceEnabled(), "executeQuery", true, sql, Integer.MIN_VALUE, null, null, Integer.MIN_VALUE, Integer.MIN_VALUE, Integer.MIN_VALUE), sql); + if (isTraceEnabled()) + trace(null, sql, log("executeQuery", true, sql, Integer.MIN_VALUE, null, null, Integer.MIN_VALUE, Integer.MIN_VALUE, Integer.MIN_VALUE)); + return wrap(target.prepareStatement(sql), sql); } @@ -335,7 +332,9 @@ public PreparedStatement prepareStatement(final String sql, final int resultSetT if (traceOpenConnections) openConnections.put(this, new Trace()); - trace(null, log(isTraceEnabled(), "prepareStatement", true, sql, Integer.MIN_VALUE, null, null, resultSetType, resultSetConcurrency, Integer.MIN_VALUE), sql); + if (isTraceEnabled()) + trace(null, sql, log("prepareStatement", true, sql, Integer.MIN_VALUE, null, null, resultSetType, resultSetConcurrency, Integer.MIN_VALUE)); + return wrap(target.prepareStatement(sql, resultSetType, resultSetConcurrency), sql); } @@ -349,7 +348,9 @@ public CallableStatement prepareCall(final String sql, final int resultSetType, if (traceOpenConnections) openConnections.put(this, new Trace()); - trace(null, log(isTraceEnabled(), "prepareCall", true, sql, Integer.MIN_VALUE, null, null, resultSetType, resultSetConcurrency, Integer.MIN_VALUE), sql); + if (isTraceEnabled()) + trace(null, sql, log("prepareCall", true, sql, Integer.MIN_VALUE, null, null, resultSetType, resultSetConcurrency, Integer.MIN_VALUE)); + return wrap(target.prepareCall(sql, resultSetType, resultSetConcurrency), sql); } @@ -376,7 +377,9 @@ public PreparedStatement prepareStatement(final String sql, final int resultSetT if (traceOpenConnections) openConnections.put(this, new Trace()); - trace(null, log(isTraceEnabled(), "prepareStatement", true, sql, Integer.MIN_VALUE, null, null, resultSetType, resultSetConcurrency, resultSetHoldability), sql); + if (isTraceEnabled()) + trace(null, sql, log("prepareStatement", true, sql, Integer.MIN_VALUE, null, null, resultSetType, resultSetConcurrency, resultSetHoldability)); + return wrap(target.prepareStatement(sql, resultSetType, resultSetConcurrency, resultSetHoldability), sql); } @@ -390,7 +393,9 @@ public CallableStatement prepareCall(final String sql, final int resultSetType, if (traceOpenConnections) openConnections.put(this, new Trace()); - trace(null, log(isTraceEnabled(), "prepareCall", true, sql, Integer.MIN_VALUE, null, null, resultSetType, resultSetConcurrency, resultSetHoldability), sql); + if (isTraceEnabled()) + trace(null, sql, log("prepareCall", true, sql, Integer.MIN_VALUE, null, null, resultSetType, resultSetConcurrency, resultSetHoldability)); + return wrap(target.prepareCall(sql, resultSetType, resultSetConcurrency, resultSetHoldability), sql); } @@ -404,7 +409,9 @@ public PreparedStatement prepareStatement(final String sql, final int autoGenera if (traceOpenConnections) openConnections.put(this, new Trace()); - trace(null, log(isTraceEnabled(), "prepareStatement", true, sql, autoGeneratedKeys, null, null, Integer.MIN_VALUE, Integer.MIN_VALUE, Integer.MIN_VALUE), sql); + if (isTraceEnabled()) + trace(null, sql, log("prepareStatement", true, sql, autoGeneratedKeys, null, null, Integer.MIN_VALUE, Integer.MIN_VALUE, Integer.MIN_VALUE)); + return wrap(target.prepareStatement(sql, autoGeneratedKeys), sql); } @@ -418,7 +425,9 @@ public PreparedStatement prepareStatement(final String sql, final int[] columnIn if (traceOpenConnections) openConnections.put(this, new Trace()); - trace(null, log(isTraceEnabled(), "prepareStatement", true, sql, Integer.MIN_VALUE, columnIndexes, null, Integer.MIN_VALUE, Integer.MIN_VALUE, Integer.MIN_VALUE), sql); + if (isTraceEnabled()) + trace(null, sql, log("prepareStatement", true, sql, Integer.MIN_VALUE, columnIndexes, null, Integer.MIN_VALUE, Integer.MIN_VALUE, Integer.MIN_VALUE)); + return wrap(target.prepareStatement(sql, columnIndexes), sql); } @@ -432,7 +441,9 @@ public PreparedStatement prepareStatement(final String sql, final String[] colum if (traceOpenConnections) openConnections.put(this, new Trace()); - trace(null, log(isTraceEnabled(), "prepareStatement", true, sql, Integer.MIN_VALUE, null, columnNames, Integer.MIN_VALUE, Integer.MIN_VALUE, Integer.MIN_VALUE), sql); + if (isTraceEnabled()) + trace(null, sql, log("prepareStatement", true, sql, Integer.MIN_VALUE, null, columnNames, Integer.MIN_VALUE, Integer.MIN_VALUE, Integer.MIN_VALUE)); + return wrap(target.prepareStatement(sql, columnNames), sql); } diff --git a/src/main/java/org/libj/sql/AuditPreparedStatement.java b/src/main/java/org/libj/sql/AuditPreparedStatement.java index 254afa7..c6b06a9 100644 --- a/src/main/java/org/libj/sql/AuditPreparedStatement.java +++ b/src/main/java/org/libj/sql/AuditPreparedStatement.java @@ -237,7 +237,7 @@ public static PreparedStatement wrapIfDebugEnabled(final PreparedStatement targe } private static final DateTimeFormatter dateFormat = DateTimeFormatter.ISO_LOCAL_DATE; - private static final DateTimeFormatter timeFormat = new DateTimeFormatterBuilder().appendPattern("HH:mm:ss").appendFraction(ChronoField.MILLI_OF_SECOND, 0, 6, true).toFormatter(); + private static final DateTimeFormatter timeFormat = new DateTimeFormatterBuilder().appendPattern("HH:mm:ss").appendFraction(ChronoField.MILLI_OF_SECOND, 0, 3, true).toFormatter(); private static final DateTimeFormatter timestampFormat = new DateTimeFormatterBuilder().append(dateFormat).appendLiteral(' ').append(timeFormat).toFormatter(); private static final ThreadLocal numberFormat = DecimalFormatter.createDecimalFormat("###############.###############;-###############.###############"); @@ -266,18 +266,6 @@ protected boolean isDebugEnabled() { return logger.isDebugEnabled(); } - @Override - protected void trace(final StatementType statementType, final String sql, final String detail) { - if (detail != null) - logger.trace(detail); - } - - @Override - protected void debug(final StatementType statementType, final String sql, final String detail, final Throwable exception) { - if (detail != null) - logger.debug(detail); - } - /** * Adds a parameter with the provided {@code key} and {@code value} to the parameter map maintained in this instance for the purpose * of audit logging. @@ -320,16 +308,22 @@ public PreparedStatement getTarget() { return (PreparedStatement)super.getTarget(); } + @Override + protected Logger logger() { + return logger; + } + @Override public ResultSet executeQuery() throws SQLException { final PreparedStatement statement = getTarget(); int size = -1; long time = -1; Throwable exception = null; + final StringBuilder sql = toStringBuilder(); final boolean isDebugEnabled = isDebugEnabled(); try { - final StringBuilder sql = toStringBuilder(); - trace(StatementType.QUERY, sql.toString(), log(isTraceEnabled(), "executeQuery", true, toStringBuilder(), Integer.MIN_VALUE, null, null, null, -1)); + if (isTraceEnabled()) + trace(StatementType.QUERY, sql, log("executeQuery", true, sql, Integer.MIN_VALUE, null, null, null, -1)); if (isDebugEnabled) time = System.currentTimeMillis(); @@ -345,8 +339,8 @@ public ResultSet executeQuery() throws SQLException { throw t; } finally { - final StringBuilder sql = toStringBuilder(); - debug(StatementType.QUERY, sql.toString(), log(isDebugEnabled, "executeQuery", true, toStringBuilder(), Integer.MIN_VALUE, null, null, size, time), exception); + if (isDebugEnabled) + debug(StatementType.QUERY, sql, log("executeQuery", true, sql, Integer.MIN_VALUE, null, null, size, time), exception); } } @@ -355,10 +349,11 @@ public int executeUpdate() throws SQLException { long time = -1; int count = -1; Throwable exception = null; + final StringBuilder sql = toStringBuilder(); final boolean isDebugEnabled = isDebugEnabled(); try { - final StringBuilder sql = toStringBuilder(); - trace(StatementType.UPDATE, sql.toString(), log(isTraceEnabled(), "executeUpdate", true, toStringBuilder(), Integer.MIN_VALUE, null, null, null, -1)); + if (isTraceEnabled()) + trace(StatementType.UPDATE, sql, log("executeUpdate", true, sql, Integer.MIN_VALUE, null, null, null, -1)); if (isDebugEnabled) time = System.currentTimeMillis(); @@ -370,8 +365,8 @@ public int executeUpdate() throws SQLException { throw t; } finally { - final StringBuilder sql = toStringBuilder(); - debug(StatementType.UPDATE, sql.toString(), log(isDebugEnabled, "executeUpdate", true, toStringBuilder(), Integer.MIN_VALUE, null, null, count, time), exception); + if (isDebugEnabled) + debug(StatementType.UPDATE, sql, log("executeUpdate", true, sql, Integer.MIN_VALUE, null, null, count, time), exception); } } @@ -508,10 +503,11 @@ public boolean execute() throws SQLException { long time = -1; boolean result = false; Throwable exception = null; + final StringBuilder sql = toStringBuilder(); final boolean isDebugEnabled = isDebugEnabled(); try { - final StringBuilder sql = toStringBuilder(); - trace(StatementType.MULTIPLE, sql.toString(), log(isTraceEnabled(), "execute", true, toStringBuilder(), Integer.MIN_VALUE, null, null, null, -1)); + if (isTraceEnabled()) + trace(StatementType.MULTIPLE, sql, log("execute", true, sql, Integer.MIN_VALUE, null, null, null, -1)); if (isDebugEnabled) time = System.currentTimeMillis(); @@ -523,8 +519,8 @@ public boolean execute() throws SQLException { throw t; } finally { - final StringBuilder sql = toStringBuilder(); - debug(StatementType.MULTIPLE, sql.toString(), log(isDebugEnabled, "execute", true, toStringBuilder(), Integer.MIN_VALUE, null, null, result, time), exception); + if (isDebugEnabled) + debug(StatementType.MULTIPLE, sql, log("execute", true, sql, Integer.MIN_VALUE, null, null, result, time), exception); } } diff --git a/src/main/java/org/libj/sql/AuditStatement.java b/src/main/java/org/libj/sql/AuditStatement.java index 2740719..e74ea7e 100644 --- a/src/main/java/org/libj/sql/AuditStatement.java +++ b/src/main/java/org/libj/sql/AuditStatement.java @@ -100,8 +100,6 @@ protected int getLogResultSetSize(final boolean enabled, final ResultSet resultS /** * Returns a log entry for the provided parameters. * - * @param enabled If {@code true}, this method will return a log entry for the provided parameters. Otherwise if {@code false}, this - * method will return {@code null}. * @param method The name of the method for which the log entry is being created. * @param newLine If {@code true}, a newline character {@code '\n'} will be appended before the {@code sql} string. If * {@code false}, no newline character will be appended before the {@code sql} string. @@ -118,10 +116,7 @@ protected int getLogResultSetSize(final boolean enabled, final ResultSet resultS * @return A log entry for the provided parameters. * @throws SQLException If a SQL error has occurred. */ - protected String log(final boolean enabled, final String method, final boolean newLine, final StringBuilder sql, final int autoGeneratedKeys, final int[] columnIndexes, final String[] columnNames, final Object result, final long time) throws SQLException { - if (!enabled) - return null; - + protected String log(final String method, final boolean newLine, final CharSequence sql, final int autoGeneratedKeys, final int[] columnIndexes, final String[] columnNames, final Object result, final long time) throws SQLException { final StringBuilder b = AuditUtil.log(this, method, getConnection(), newLine, sql); if (autoGeneratedKeys != Integer.MIN_VALUE) { b.append(", ").append(autoGeneratedKeys); @@ -155,7 +150,9 @@ public ResultSet executeQuery(final String sql) throws SQLException { Throwable exception = null; final boolean isDebugEnabled = isDebugEnabled(); try { - trace(StatementType.QUERY, sql, log(isTraceEnabled(), "executeQuery", true, new StringBuilder(sql), Integer.MIN_VALUE, null, null, null, -1)); + if (isTraceEnabled()) + trace(StatementType.QUERY, sql, log("executeQuery", true, sql, Integer.MIN_VALUE, null, null, null, -1)); + time = getLogTimestamp(isDebugEnabled); final ResultSet resultSet = getTarget().executeQuery(sql); size = getLogResultSetSize(isDebugEnabled, resultSet); @@ -166,7 +163,8 @@ public ResultSet executeQuery(final String sql) throws SQLException { throw t; } finally { - debug(StatementType.QUERY, sql, log(isDebugEnabled, "executeQuery", true, new StringBuilder(sql), Integer.MIN_VALUE, null, null, size, time), exception); + if (isDebugEnabled) + debug(StatementType.QUERY, sql, log("executeQuery", true, sql, Integer.MIN_VALUE, null, null, size, time), exception); } } @@ -177,7 +175,9 @@ public int executeUpdate(final String sql) throws SQLException { Throwable exception = null; final boolean isDebugEnabled = isDebugEnabled(); try { - trace(StatementType.UPDATE, sql, log(isTraceEnabled(), "executeUpdate", true, new StringBuilder(sql), Integer.MIN_VALUE, null, null, null, -1)); + if (isTraceEnabled()) + trace(StatementType.UPDATE, sql, log("executeUpdate", true, sql, Integer.MIN_VALUE, null, null, null, -1)); + time = getLogTimestamp(isDebugEnabled); return count = getTarget().executeUpdate(sql); } @@ -186,7 +186,8 @@ public int executeUpdate(final String sql) throws SQLException { throw t; } finally { - debug(StatementType.UPDATE, sql, log(isDebugEnabled, "executeUpdate", true, new StringBuilder(sql), Integer.MIN_VALUE, null, null, count, time), exception); + if (isDebugEnabled) + debug(StatementType.UPDATE, sql, log("executeUpdate", true, sql, Integer.MIN_VALUE, null, null, count, time), exception); } } @@ -215,7 +216,9 @@ public boolean execute(final String sql) throws SQLException { Throwable exception = null; final boolean isDebugEnabled = isDebugEnabled(); try { - trace(StatementType.MULTIPLE, sql, log(isTraceEnabled(), "execute", true, new StringBuilder(sql), Integer.MIN_VALUE, null, null, null, -1)); + if (isTraceEnabled()) + trace(StatementType.MULTIPLE, sql, log("execute", true, sql, Integer.MIN_VALUE, null, null, null, -1)); + time = getLogTimestamp(isDebugEnabled); return result = getTarget().execute(sql); } @@ -224,7 +227,8 @@ public boolean execute(final String sql) throws SQLException { throw t; } finally { - debug(StatementType.MULTIPLE, sql, log(isDebugEnabled, "execute", true, new StringBuilder(sql), Integer.MIN_VALUE, null, null, result, time), exception); + if (isDebugEnabled) + debug(StatementType.MULTIPLE, sql, log("execute", true, sql, Integer.MIN_VALUE, null, null, result, time), exception); } } @@ -265,7 +269,9 @@ public int[] executeBatch() throws SQLException { final boolean isDebugEnabled = isDebugEnabled(); try { final StringBuilder sql = logExecuteBatch(null, -1); - trace(StatementType.MULTIPLE, sql.toString(), log(isTraceEnabled(), "executeBatch", false, sql, Integer.MIN_VALUE, null, null, null, -1)); + if (isTraceEnabled()) + trace(StatementType.MULTIPLE, sql.toString(), log("executeBatch", false, sql, Integer.MIN_VALUE, null, null, null, -1)); + time = getLogTimestamp(isDebugEnabled); return count = getTarget().executeBatch(); } @@ -277,7 +283,10 @@ public int[] executeBatch() throws SQLException { final StringBuilder sql = logExecuteBatch(count, time); if ("[])".equals(sql.toString())) logExecuteBatch(count, time); - debug(StatementType.MULTIPLE, sql.toString(), log(isDebugEnabled, "executeBatch", false, sql, Integer.MIN_VALUE, null, null, null, -1), exception); + + if (isDebugEnabled) + debug(StatementType.MULTIPLE, sql.toString(), log("executeBatch", false, sql, Integer.MIN_VALUE, null, null, null, -1), exception); + logExecuteBatch(count, time); } } @@ -289,7 +298,9 @@ public int executeUpdate(final String sql, final int autoGeneratedKeys) throws S Throwable exception = null; final boolean isDebugEnabled = isDebugEnabled(); try { - trace(StatementType.UPDATE, sql, log(isTraceEnabled(), "executeUpdate", true, new StringBuilder(sql), autoGeneratedKeys, null, null, null, -1)); + if (isTraceEnabled()) + trace(StatementType.UPDATE, sql, log("executeUpdate", true, sql, autoGeneratedKeys, null, null, null, -1)); + time = getLogTimestamp(isDebugEnabled); return count = getTarget().executeUpdate(sql, autoGeneratedKeys); } @@ -298,7 +309,8 @@ public int executeUpdate(final String sql, final int autoGeneratedKeys) throws S throw t; } finally { - debug(StatementType.UPDATE, sql, log(isDebugEnabled, "executeUpdate", true, new StringBuilder(sql), autoGeneratedKeys, null, null, count, time), exception); + if (isDebugEnabled) + debug(StatementType.UPDATE, sql, log("executeUpdate", true, sql, autoGeneratedKeys, null, null, count, time), exception); } } @@ -309,7 +321,9 @@ public int executeUpdate(final String sql, final int[] columnIndexes) throws SQL Throwable exception = null; final boolean isDebugEnabled = isDebugEnabled(); try { - trace(StatementType.UPDATE, sql, log(isTraceEnabled(), "executeUpdate", true, new StringBuilder(sql), Integer.MIN_VALUE, columnIndexes, null, null, -1)); + if (isTraceEnabled()) + trace(StatementType.UPDATE, sql, log("executeUpdate", true, sql, Integer.MIN_VALUE, columnIndexes, null, null, -1)); + time = getLogTimestamp(isDebugEnabled); return count = getTarget().executeUpdate(sql, columnIndexes); } @@ -318,7 +332,8 @@ public int executeUpdate(final String sql, final int[] columnIndexes) throws SQL throw t; } finally { - debug(StatementType.UPDATE, sql, log(isDebugEnabled, "executeUpdate", true, new StringBuilder(sql), Integer.MIN_VALUE, columnIndexes, null, count, time), exception); + if (isDebugEnabled) + debug(StatementType.UPDATE, sql, log("executeUpdate", true, sql, Integer.MIN_VALUE, columnIndexes, null, count, time), exception); } } @@ -329,7 +344,9 @@ public int executeUpdate(final String sql, final String[] columnNames) throws SQ Throwable exception = null; final boolean isDebugEnabled = isDebugEnabled(); try { - trace(StatementType.UPDATE, sql, log(isTraceEnabled(), "executeUpdate", true, new StringBuilder(sql), Integer.MIN_VALUE, null, columnNames, null, -1)); + if (isTraceEnabled()) + trace(StatementType.UPDATE, sql, log("executeUpdate", true, sql, Integer.MIN_VALUE, null, columnNames, null, -1)); + time = getLogTimestamp(isDebugEnabled); return count = getTarget().executeUpdate(sql, columnNames); } @@ -338,7 +355,8 @@ public int executeUpdate(final String sql, final String[] columnNames) throws SQ throw t; } finally { - debug(StatementType.UPDATE, sql, log(isDebugEnabled, "executeUpdate", true, new StringBuilder(sql), Integer.MIN_VALUE, null, columnNames, count, time), exception); + if (isDebugEnabled) + debug(StatementType.UPDATE, sql, log("executeUpdate", true, sql, Integer.MIN_VALUE, null, columnNames, count, time), exception); } } @@ -349,7 +367,9 @@ public boolean execute(final String sql, final int autoGeneratedKeys) throws SQL Throwable exception = null; final boolean isDebugEnabled = isDebugEnabled(); try { - trace(StatementType.MULTIPLE, sql, log(isTraceEnabled(), "execute", true, new StringBuilder(sql), autoGeneratedKeys, null, null, null, -1)); + if (isTraceEnabled()) + trace(StatementType.MULTIPLE, sql, log("execute", true, sql, autoGeneratedKeys, null, null, null, -1)); + time = getLogTimestamp(isDebugEnabled); return result = getTarget().execute(sql, autoGeneratedKeys); } @@ -358,7 +378,8 @@ public boolean execute(final String sql, final int autoGeneratedKeys) throws SQL throw t; } finally { - debug(StatementType.MULTIPLE, sql, log(isDebugEnabled, "execute", true, new StringBuilder(sql), autoGeneratedKeys, null, null, result, time), exception); + if (isDebugEnabled) + debug(StatementType.MULTIPLE, sql, log("execute", true, sql, autoGeneratedKeys, null, null, result, time), exception); } } @@ -369,7 +390,9 @@ public boolean execute(final String sql, final int[] columnIndexes) throws SQLEx Throwable exception = null; final boolean isDebugEnabled = isDebugEnabled(); try { - trace(StatementType.MULTIPLE, sql, log(isTraceEnabled(), "execute", true, new StringBuilder(sql), Integer.MIN_VALUE, columnIndexes, null, null, -1)); + if (isTraceEnabled()) + trace(StatementType.MULTIPLE, sql, log("execute", true, sql, Integer.MIN_VALUE, columnIndexes, null, null, -1)); + time = getLogTimestamp(isDebugEnabled); return result = getTarget().execute(sql, columnIndexes); } @@ -378,7 +401,8 @@ public boolean execute(final String sql, final int[] columnIndexes) throws SQLEx throw t; } finally { - debug(StatementType.MULTIPLE, sql, log(isDebugEnabled, "execute", true, new StringBuilder(sql), Integer.MIN_VALUE, columnIndexes, null, result, time), exception); + if (isDebugEnabled) + debug(StatementType.MULTIPLE, sql, log("execute", true, sql, Integer.MIN_VALUE, columnIndexes, null, result, time), exception); } } @@ -389,7 +413,9 @@ public boolean execute(final String sql, final String[] columnNames) throws SQLE Throwable exception = null; final boolean isDebugEnabled = isDebugEnabled(); try { - trace(StatementType.MULTIPLE, sql, log(isTraceEnabled(), "execute", true, new StringBuilder(sql), Integer.MIN_VALUE, null, columnNames, null, -1)); + if (isTraceEnabled()) + trace(StatementType.MULTIPLE, sql, log("execute", true, sql, Integer.MIN_VALUE, null, columnNames, null, -1)); + time = getLogTimestamp(isDebugEnabled); return result = getTarget().execute(sql, columnNames); } @@ -398,7 +424,8 @@ public boolean execute(final String sql, final String[] columnNames) throws SQLE throw t; } finally { - debug(StatementType.MULTIPLE, sql, log(isDebugEnabled, "execute", true, new StringBuilder(sql), Integer.MIN_VALUE, null, columnNames, result, time), exception); + if (isDebugEnabled) + debug(StatementType.MULTIPLE, sql, log("execute", true, sql, Integer.MIN_VALUE, null, columnNames, result, time), exception); } } diff --git a/src/main/java/org/libj/sql/AuditUtil.java b/src/main/java/org/libj/sql/AuditUtil.java index df9a158..15608cd 100644 --- a/src/main/java/org/libj/sql/AuditUtil.java +++ b/src/main/java/org/libj/sql/AuditUtil.java @@ -22,7 +22,7 @@ import org.libj.lang.Strings; class AuditUtil { - static StringBuilder log(final Object self, final String method, final Connection connection, final boolean newLine, final StringBuilder sql) { + static StringBuilder log(final Object self, final String method, final Connection connection, final boolean newLine, final CharSequence sql) { final StringBuilder b = new StringBuilder("[").append(ObjectUtil.identityString(self)).append("].").append(method).append('(').append(ObjectUtil.simpleIdentityString(connection)).append(','); if (newLine) b.append("\n ");