@Test public void successfulPropertyAccess() { BeanPropertySqlParameterSource source = new BeanPropertySqlParameterSource(new TestBean("tb", 99)); assertTrue(Arrays.asList(source.getReadablePropertyNames()).contains("name")); assertTrue(Arrays.asList(source.getReadablePropertyNames()).contains("age")); assertEquals("tb", source.getValue("name")); assertEquals(99, source.getValue("age")); assertEquals(Types.VARCHAR, source.getSqlType("name")); assertEquals(Types.INTEGER, source.getSqlType("age")); }
@Test public void successfulPropertyAccessWithOverriddenSqlType() { BeanPropertySqlParameterSource source = new BeanPropertySqlParameterSource(new TestBean("tb", 99)); source.registerSqlType("age", Types.NUMERIC); assertEquals("tb", source.getValue("name")); assertEquals(99, source.getValue("age")); assertEquals(Types.VARCHAR, source.getSqlType("name")); assertEquals(Types.NUMERIC, source.getSqlType("age")); }
msp.addValue(fn, sps.getValue(fn), sps.getSqlType(fn), sps.getTypeName(fn)); logger.debug(String.format("prepared sql arg: name=%s, value=%s, type=%s", fn, sps.getValue(fn), sps.getTypeName(fn)));
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); } }