public Promise<Integer, MessageDroppedException, ?> update(PreparedStatementCreator psc) throws DataAccessException { if (psc instanceof SqlProvider) { SqlProvider sqlProvider = (SqlProvider) psc; String sql = sqlProvider.getSql(); Builder builder = Sql.builder().sql(sql); if (psc instanceof PreparedStatementSetter) { PreparedStatementSetter pss = (PreparedStatementSetter) psc; builder.preparedStatementSetter(pss); } return reporter.report(builder.build()); } throw new UnsupportedOperationException("Must be instance of SqlProvider"); }
/** * Determine SQL from potential provider object. * @param sqlProvider object that's potentially a SqlProvider * @return the SQL string, or <code>null</code> * @see SqlProvider */ private static String getSql(Object sqlProvider) { if (sqlProvider instanceof SqlProvider) { return ((SqlProvider) sqlProvider).getSql(); } else { return null; } }
public boolean execute(final String sql) throws DataAccessException { if (log.isDebugEnabled()) { log.debug("Executing SQL statement [" + sql + "]"); } class ExecuteStatementCallback implements StatementCallback<Boolean>, SqlProvider { public Boolean doInStatement(Statement stmt) throws SQLException { return stmt.execute(sql); } public String getSql() { return sql; } } return template.execute(new ExecuteStatementCallback()); }