1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springframework.jdbc.core;
18
19 import java.sql.PreparedStatement;
20 import java.sql.SQLException;
21
22
23
24
25
26
27
28 public class ArgumentPreparedStatementSetter implements PreparedStatementSetter, ParameterDisposer {
29
30 private final Object[] args;
31
32
33
34
35
36
37 public ArgumentPreparedStatementSetter(Object[] args) {
38 this.args = args;
39 }
40
41
42 @Override
43 public void setValues(PreparedStatement ps) throws SQLException {
44 if (this.args != null) {
45 for (int i = 0; i < this.args.length; i++) {
46 Object arg = this.args[i];
47 doSetValue(ps, i + 1, arg);
48 }
49 }
50 }
51
52
53
54
55
56
57
58
59
60 protected void doSetValue(PreparedStatement ps, int parameterPosition, Object argValue) throws SQLException {
61 if (argValue instanceof SqlParameterValue) {
62 SqlParameterValue paramValue = (SqlParameterValue) argValue;
63 StatementCreatorUtils.setParameterValue(ps, parameterPosition, paramValue, paramValue.getValue());
64 }
65 else {
66 StatementCreatorUtils.setParameterValue(ps, parameterPosition, SqlTypeValue.TYPE_UNKNOWN, argValue);
67 }
68 }
69
70 @Override
71 public void cleanupParameters() {
72 StatementCreatorUtils.cleanupParameters(this.args);
73 }
74
75 }