@Test(expected = IllegalArgumentException.class) public void getValueChokesIfParameterIsNotPresent() throws Exception { MapSqlParameterSource source = new MapSqlParameterSource(); source.getValue("pechorin was right!"); }
params.addValue("histOperation", operation); params.addValue("histStamp",""); params.addValue("histUserId", (String)params.getValue("userId")); insert("__insertHistory", insertHistorySql, params, original); } catch (Throwable e) {
public int create(Job job) { Assert.notNull(job,"Job must not be null."); Assert.notNull(job.getSite(),"Site must not be null."); MapSqlParameterSource params = params("intSiteId",job.getSite().getId()) .addValue("dtmStart", job.getStartDate() == null ? null : dateTimeString(job.getStartDate())) .addValue("dtmEnd", job.getEndDate() == null ? null : dateTimeString(job.getEndDate())) .addValue("intManualFl",job.isManual()) .addValue("insertDate",dateTimeString(DateTime.now(DateTimeZone.UTC))); getTemplate().execute(getSql("create"), params, new PreparedStatementCallback<Boolean>(){ @Override public Boolean doInPreparedStatement(PreparedStatement ps) throws SQLException, DataAccessException { return 0; } }); return (int)params.getValue("intSiteId"); }
public class CombinedSqlParameterSource extends AbstractSqlParameterSource { private MapSqlParameterSource mapSqlParameterSource = new MapSqlParameterSource(); private BeanPropertySqlParameterSource beanPropertySqlParameterSource; public CombinedSqlParameterSource(Object object) { this.beanPropertySqlParameterSource = new BeanPropertySqlParameterSource(object); } public void addValue(String paramName, Object value) { mapSqlParameterSource.addValue(paramName, value); } @Override public boolean hasValue(String paramName) { return beanPropertySqlParameterSource.hasValue(paramName) || mapSqlParameterSource.hasValue(paramName); } @Override public Object getValue(String paramName) { return beanPropertySqlParameterSource.hasValue(paramName) ? beanPropertySqlParameterSource.getValue(paramName) : mapSqlParameterSource.getValue(paramName); } @Override public int getSqlType(String paramName) { return beanPropertySqlParameterSource.hasValue(paramName) ? beanPropertySqlParameterSource.getSqlType(paramName) : mapSqlParameterSource.getSqlType(paramName); } }