created a protected doSetValue method so sub-classes can override the implementation easier (SPR-3978)
This commit is contained in:
parent
b88db7a594
commit
e27330ec5d
|
|
@ -43,14 +43,26 @@ class ArgPreparedStatementSetter implements PreparedStatementSetter, ParameterDi
|
||||||
if (this.args != null) {
|
if (this.args != null) {
|
||||||
for (int i = 0; i < this.args.length; i++) {
|
for (int i = 0; i < this.args.length; i++) {
|
||||||
Object arg = this.args[i];
|
Object arg = this.args[i];
|
||||||
if (arg instanceof SqlParameterValue) {
|
doSetValue(ps, i, arg);
|
||||||
SqlParameterValue paramValue = (SqlParameterValue) arg;
|
}
|
||||||
StatementCreatorUtils.setParameterValue(ps, i + 1, paramValue, paramValue.getValue());
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the value for prepared statements specified parameter index using the passed in value.
|
||||||
|
* This method can be overridden by sub-classes if needed.
|
||||||
|
* @param ps the PreparedStatement
|
||||||
|
* @param parameterPosition index of the parameter position
|
||||||
|
* @param argValue the value to set
|
||||||
|
* @throws SQLException
|
||||||
|
*/
|
||||||
|
protected void doSetValue(PreparedStatement ps, int parameterPosition, Object argValue) throws SQLException {
|
||||||
|
if (argValue instanceof SqlParameterValue) {
|
||||||
|
SqlParameterValue paramValue = (SqlParameterValue) argValue;
|
||||||
|
StatementCreatorUtils.setParameterValue(ps, parameterPosition + 1, paramValue, paramValue.getValue());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
StatementCreatorUtils.setParameterValue(ps, i + 1, SqlTypeValue.TYPE_UNKNOWN, arg);
|
StatementCreatorUtils.setParameterValue(ps, parameterPosition + 1, SqlTypeValue.TYPE_UNKNOWN, argValue);
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ class ArgTypePreparedStatementSetter implements PreparedStatementSetter, Paramet
|
||||||
|
|
||||||
|
|
||||||
public void setValues(PreparedStatement ps) throws SQLException {
|
public void setValues(PreparedStatement ps) throws SQLException {
|
||||||
int argIndx = 1;
|
int parameterPosition = 1;
|
||||||
if (this.args != null) {
|
if (this.args != null) {
|
||||||
for (int i = 0; i < this.args.length; i++) {
|
for (int i = 0; i < this.args.length; i++) {
|
||||||
Object arg = this.args[i];
|
Object arg = this.args[i];
|
||||||
|
|
@ -65,21 +65,38 @@ class ArgTypePreparedStatementSetter implements PreparedStatementSetter, Paramet
|
||||||
Object[] valueArray = ((Object[])entry);
|
Object[] valueArray = ((Object[])entry);
|
||||||
for (int k = 0; k < valueArray.length; k++) {
|
for (int k = 0; k < valueArray.length; k++) {
|
||||||
Object argValue = valueArray[k];
|
Object argValue = valueArray[k];
|
||||||
StatementCreatorUtils.setParameterValue(ps, argIndx++, this.argTypes[i], argValue);
|
doSetValue(ps, parameterPosition, this.argTypes[i], argValue);
|
||||||
|
parameterPosition++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
StatementCreatorUtils.setParameterValue(ps, argIndx++, this.argTypes[i], entry);
|
doSetValue(ps, parameterPosition, this.argTypes[i], entry);
|
||||||
|
parameterPosition++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
StatementCreatorUtils.setParameterValue(ps, argIndx++, this.argTypes[i], arg);
|
doSetValue(ps, parameterPosition, this.argTypes[i], arg);
|
||||||
|
parameterPosition++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the value for the prepared statement's specified parameter position using the passed in
|
||||||
|
* value and type. This method can be overridden by sub-classes if needed.
|
||||||
|
* @param ps the PreparedStatement
|
||||||
|
* @param parameterPosition index of the parameter position
|
||||||
|
* @param argType the argument type
|
||||||
|
* @param argValue the argument value
|
||||||
|
* @throws SQLException
|
||||||
|
*/
|
||||||
|
protected void doSetValue(PreparedStatement ps, int parameterPosition, int argType, Object argValue)
|
||||||
|
throws SQLException {
|
||||||
|
StatementCreatorUtils.setParameterValue(ps, parameterPosition, argType, argValue);
|
||||||
|
}
|
||||||
|
|
||||||
public void cleanupParameters() {
|
public void cleanupParameters() {
|
||||||
StatementCreatorUtils.cleanupParameters(this.args);
|
StatementCreatorUtils.cleanupParameters(this.args);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue