@Test public void reformatSql() { assertThat(SqlLogFormatter.reformatSql("")).isEqualTo(""); assertThat(SqlLogFormatter.reformatSql("select *")).isEqualTo("select *"); assertThat(SqlLogFormatter.reformatSql("select *\nfrom issues")).isEqualTo("select * from issues"); assertThat(SqlLogFormatter.reformatSql("select *\n from issues")).isEqualTo("select * from issues"); assertThat(SqlLogFormatter.reformatSql("select *\n from issues")).isEqualTo("select * from issues"); assertThat(SqlLogFormatter.reformatSql("select *\n from issues")).isEqualTo("select * from issues"); assertThat(SqlLogFormatter.reformatSql("select *\n\t\t from \tissues")).isEqualTo("select * from issues"); }
@Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if (method.getName().startsWith("execute")) { Profiler profiler = Profiler.create(ProfiledDataSource.SQL_LOGGER).start(); Object result = null; try { result = InvocationUtils.invokeQuietly(statement, method, args); } finally { String sql = (String) args[0]; profiler.addContext("sql", SqlLogFormatter.reformatSql(sql)); profiler.stopTrace(""); } return result; } else { return InvocationUtils.invokeQuietly(statement, method, args); } } }
@Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if (method.getName().startsWith("execute")) { Profiler profiler = Profiler.create(ProfiledDataSource.SQL_LOGGER).start(); Object result = null; try { result = InvocationUtils.invokeQuietly(statement, method, args); } finally { profiler.addContext("sql", SqlLogFormatter.reformatSql(sql)); if (sqlParams.length > 0) { profiler.addContext("params", SqlLogFormatter.reformatParams(sqlParams)); } profiler.stopTrace(""); } return result; } else if (method.getName().startsWith("set") && args.length > 1) { sqlParams[(int) args[0] - 1] = args[1]; return InvocationUtils.invokeQuietly(statement, method, args); } else { return InvocationUtils.invokeQuietly(statement, method, args); } }
@Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if (method.getName().startsWith("execute")) { Profiler profiler = Profiler.create(ProfiledDataSource.SQL_LOGGER).start(); Object result = null; try { result = InvocationUtils.invokeQuietly(statement, method, args); } finally { String sql = (String) args[0]; profiler.addContext("sql", SqlLogFormatter.reformatSql(sql)); profiler.stopTrace(""); } return result; } else { return InvocationUtils.invokeQuietly(statement, method, args); } } }
@Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if (method.getName().startsWith("execute")) { Profiler profiler = Profiler.create(ProfiledDataSource.SQL_LOGGER).start(); Object result = null; try { result = InvocationUtils.invokeQuietly(statement, method, args); } finally { profiler.addContext("sql", SqlLogFormatter.reformatSql(sql)); if (sqlParams.length > 0) { profiler.addContext("params", SqlLogFormatter.reformatParams(sqlParams)); } profiler.stopTrace(""); } return result; } else if (method.getName().startsWith("set") && args.length > 1) { sqlParams[(int) args[0] - 1] = args[1]; return InvocationUtils.invokeQuietly(statement, method, args); } else { return InvocationUtils.invokeQuietly(statement, method, args); } }