01: package liquibase.database.template;
02:
03: import java.sql.PreparedStatement;
04: import java.sql.SQLException;
05:
06: /**
07: * Simple adapter for PreparedStatementSetter that applies
08: * a given array of arguments.
09: *
10: * @author Spring Framework
11: */
12: class ArgPreparedStatementSetter implements PreparedStatementSetter {
13:
14: private final Object[] args;
15:
16: /**
17: * Create a new ArgPreparedStatementSetter for the given arguments.
18: *
19: * @param args the arguments to set
20: */
21: public ArgPreparedStatementSetter(Object[] args) {
22: this .args = args;
23: }
24:
25: public void setValues(PreparedStatement ps) throws SQLException {
26: if (this .args != null) {
27: for (int i = 0; i < this .args.length; i++) {
28: Object arg = this .args[i];
29: if (arg instanceof SqlParameterValue) {
30: SqlParameterValue paramValue = (SqlParameterValue) arg;
31: StatementCreatorUtils.setParameterValue(ps, i + 1,
32: paramValue, paramValue.getValue());
33: } else {
34: StatementCreatorUtils.setParameterValue(ps, i + 1,
35: SqlTypeValue.TYPE_UNKNOWN, arg);
36: }
37: }
38: }
39: }
40:
41: }
|