created a protected doSetValue method so sub-classes can override the implementation easier (SPR-3978)

This commit is contained in:
Thomas Risberg 2009-11-12 20:47:48 +00:00
parent b88db7a594
commit e27330ec5d
2 changed files with 40 additions and 11 deletions

View File

@ -43,17 +43,29 @@ class ArgPreparedStatementSetter implements PreparedStatementSetter, ParameterDi
if (this.args != null) {
for (int i = 0; i < this.args.length; i++) {
Object arg = this.args[i];
if (arg instanceof SqlParameterValue) {
SqlParameterValue paramValue = (SqlParameterValue) arg;
StatementCreatorUtils.setParameterValue(ps, i + 1, paramValue, paramValue.getValue());
}
else {
StatementCreatorUtils.setParameterValue(ps, i + 1, SqlTypeValue.TYPE_UNKNOWN, arg);
}
doSetValue(ps, i, arg);
}
}
}
/**
* 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 {
StatementCreatorUtils.setParameterValue(ps, parameterPosition + 1, SqlTypeValue.TYPE_UNKNOWN, argValue);
}
}
public void cleanupParameters() {
StatementCreatorUtils.cleanupParameters(this.args);
}

View File

@ -53,7 +53,7 @@ class ArgTypePreparedStatementSetter implements PreparedStatementSetter, Paramet
public void setValues(PreparedStatement ps) throws SQLException {
int argIndx = 1;
int parameterPosition = 1;
if (this.args != null) {
for (int i = 0; i < this.args.length; i++) {
Object arg = this.args[i];
@ -65,21 +65,38 @@ class ArgTypePreparedStatementSetter implements PreparedStatementSetter, Paramet
Object[] valueArray = ((Object[])entry);
for (int k = 0; k < valueArray.length; k++) {
Object argValue = valueArray[k];
StatementCreatorUtils.setParameterValue(ps, argIndx++, this.argTypes[i], argValue);
doSetValue(ps, parameterPosition, this.argTypes[i], argValue);
parameterPosition++;
}
}
else {
StatementCreatorUtils.setParameterValue(ps, argIndx++, this.argTypes[i], entry);
doSetValue(ps, parameterPosition, this.argTypes[i], entry);
parameterPosition++;
}
}
}
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() {
StatementCreatorUtils.cleanupParameters(this.args);
}