Skip to content

Commit e27330e

Browse files
author
Thomas Risberg
committed
created a protected doSetValue method so sub-classes can override the implementation easier (SPR-3978)
1 parent b88db7a commit e27330e

File tree

2 files changed

+40
-11
lines changed

2 files changed

+40
-11
lines changed

org.springframework.jdbc/src/main/java/org/springframework/jdbc/core/ArgPreparedStatementSetter.java

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,29 @@ public void setValues(PreparedStatement ps) throws SQLException {
4343
if (this.args != null) {
4444
for (int i = 0; i < this.args.length; i++) {
4545
Object arg = this.args[i];
46-
if (arg instanceof SqlParameterValue) {
47-
SqlParameterValue paramValue = (SqlParameterValue) arg;
48-
StatementCreatorUtils.setParameterValue(ps, i + 1, paramValue, paramValue.getValue());
49-
}
50-
else {
51-
StatementCreatorUtils.setParameterValue(ps, i + 1, SqlTypeValue.TYPE_UNKNOWN, arg);
52-
}
46+
doSetValue(ps, i, arg);
5347
}
5448
}
5549
}
5650

51+
/**
52+
* Set the value for prepared statements specified parameter index using the passed in value.
53+
* This method can be overridden by sub-classes if needed.
54+
* @param ps the PreparedStatement
55+
* @param parameterPosition index of the parameter position
56+
* @param argValue the value to set
57+
* @throws SQLException
58+
*/
59+
protected void doSetValue(PreparedStatement ps, int parameterPosition, Object argValue) throws SQLException {
60+
if (argValue instanceof SqlParameterValue) {
61+
SqlParameterValue paramValue = (SqlParameterValue) argValue;
62+
StatementCreatorUtils.setParameterValue(ps, parameterPosition + 1, paramValue, paramValue.getValue());
63+
}
64+
else {
65+
StatementCreatorUtils.setParameterValue(ps, parameterPosition + 1, SqlTypeValue.TYPE_UNKNOWN, argValue);
66+
}
67+
}
68+
5769
public void cleanupParameters() {
5870
StatementCreatorUtils.cleanupParameters(this.args);
5971
}

org.springframework.jdbc/src/main/java/org/springframework/jdbc/core/ArgTypePreparedStatementSetter.java

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public ArgTypePreparedStatementSetter(Object[] args, int[] argTypes) {
5353

5454

5555
public void setValues(PreparedStatement ps) throws SQLException {
56-
int argIndx = 1;
56+
int parameterPosition = 1;
5757
if (this.args != null) {
5858
for (int i = 0; i < this.args.length; i++) {
5959
Object arg = this.args[i];
@@ -65,21 +65,38 @@ public void setValues(PreparedStatement ps) throws SQLException {
6565
Object[] valueArray = ((Object[])entry);
6666
for (int k = 0; k < valueArray.length; k++) {
6767
Object argValue = valueArray[k];
68-
StatementCreatorUtils.setParameterValue(ps, argIndx++, this.argTypes[i], argValue);
68+
doSetValue(ps, parameterPosition, this.argTypes[i], argValue);
69+
parameterPosition++;
6970
}
7071
}
7172
else {
72-
StatementCreatorUtils.setParameterValue(ps, argIndx++, this.argTypes[i], entry);
73+
doSetValue(ps, parameterPosition, this.argTypes[i], entry);
74+
parameterPosition++;
7375
}
7476
}
7577
}
7678
else {
77-
StatementCreatorUtils.setParameterValue(ps, argIndx++, this.argTypes[i], arg);
79+
doSetValue(ps, parameterPosition, this.argTypes[i], arg);
80+
parameterPosition++;
7881
}
7982
}
8083
}
8184
}
8285

86+
/**
87+
* Set the value for the prepared statement's specified parameter position using the passed in
88+
* value and type. This method can be overridden by sub-classes if needed.
89+
* @param ps the PreparedStatement
90+
* @param parameterPosition index of the parameter position
91+
* @param argType the argument type
92+
* @param argValue the argument value
93+
* @throws SQLException
94+
*/
95+
protected void doSetValue(PreparedStatement ps, int parameterPosition, int argType, Object argValue)
96+
throws SQLException {
97+
StatementCreatorUtils.setParameterValue(ps, parameterPosition, argType, argValue);
98+
}
99+
83100
public void cleanupParameters() {
84101
StatementCreatorUtils.cleanupParameters(this.args);
85102
}

0 commit comments

Comments
 (0)