List of usage examples for org.springframework.jdbc.core.namedparam MapSqlParameterSource MapSqlParameterSource
public MapSqlParameterSource(@Nullable Map<String, ?> values)
From source file:com.github.ferstl.spring.jdbc.oracle.OracleNamedParameterJdbcTemplateTest.java
@Test @Ignore("unsupported") public void endsWithCollectionSpace() throws SQLException { Map<String, Object> map = new HashMap<>(3); map.put("ten", 10); map.put("twenty", 20); map.put("collection", Arrays.asList(1, 23, 42)); String sql = "SELECT 1 FROM dual WHERE 10 = :ten or 42 in (:collection) "; String expectedSql = "SELECT 1 FROM dual WHERE 10 = :ten or 42 in (?,?,?) "; PreparedStatementCreator preparedStatementCreator = this.namedJdbcTemplate.getPreparedStatementCreator(sql, new MapSqlParameterSource(map)); Connection connection = mock(Connection.class); PreparedStatement preparedStatement = mock(PreparedStatement.class); when(connection.prepareStatement(expectedSql)).thenReturn(preparedStatement); preparedStatementCreator.createPreparedStatement(connection); verify(preparedStatement).setObject(1, 10); verify(preparedStatement).setObject(2, 1); verify(preparedStatement).setObject(3, 23); verify(preparedStatement).setObject(4, 42); }
From source file:net.turnbig.jdbcx.JdbcxDaoSupport.java
@SuppressWarnings("unchecked") public final int[] batchUpdate(String sql, List<?> batchArgs) { SqlParameterSource[] params = new SqlParameterSource[batchArgs.size()]; for (int i = 0; i < batchArgs.size(); i++) { if (batchArgs.get(i) instanceof Map) { params[i] = new MapSqlParameterSource((Map<String, ?>) batchArgs.get(i)); } else {/*from w w w .ja v a2s . c o m*/ params[i] = new RichBeanPropertySqlParameterSource(batchArgs.get(i)); } } return getNamedParameterJdbcTemplate().batchUpdate(sql, params); }
From source file:com.lakeside.data.sqldb.BaseDao.java
public long insertWithGeneratedKey(final String sql, final Map<String, ?> paramMap) { MapSqlParameterSource mapSqlParameterSource = new MapSqlParameterSource(paramMap); KeyHolder keyHolder = new GeneratedKeyHolder(); int row = this.jdbcTemplate.update(sql, mapSqlParameterSource, keyHolder); if (row > 0) return keyHolder.getKey().longValue(); //line 72 return -1;/*from www . ja v a2s. c o m*/ }