List of usage examples for org.springframework.jdbc.core.namedparam MapSqlParameterSource MapSqlParameterSource
public MapSqlParameterSource(@Nullable Map<String, ?> values)
From source file:org.cloudfoundry.identity.uaa.scim.job.MapItemSqlParameterSourceProvider.java
@Override public SqlParameterSource createSqlParameterSource(Map<String, ?> item) { return new MapSqlParameterSource(item); }
From source file:com.github.ferstl.spring.jdbc.oracle.AbstractNamedParameterIntegrationTest.java
private static SqlParameterSource[] createParamSources(int nrOfRows) { Map<String, Object>[] batchArgs = createArgMaps(nrOfRows); SqlParameterSource[] sources = new SqlParameterSource[nrOfRows]; for (int i = 0; i < sources.length; i++) { sources[i] = new MapSqlParameterSource(batchArgs[i]); }//w w w.j a v a 2s. co m return sources; }
From source file:anyframe.core.query.impl.jdbc.PagingNamedParamJdbcTemplate.java
public List query(String sql, Map data, RowMapper rowMapper, PaginationVO paginationVO) throws Exception { MapSqlParameterSource mapSqlParameterSource = new MapSqlParameterSource(data); SqlParameterSetter sqlParameterSetter = setSqlParameter(sql, mapSqlParameterSource, data); return pagingJdbcTemplate.queryWithPagination(sqlParameterSetter.getSubstitutedSql(), sqlParameterSetter.getArgs(), sqlParameterSetter.getArgTypes(), rowMapper, paginationVO); }
From source file:ru.mystamps.web.dao.impl.JdbcImageDao.java
@Override public Integer add(String type) { KeyHolder holder = new GeneratedKeyHolder(); int affected = jdbcTemplate.update(addImageSql, new MapSqlParameterSource(Collections.singletonMap("type", type)), holder); Validate.validState(affected == 1, "Unexpected number of affected rows after adding image: %d", affected); return Integer.valueOf(holder.getKey().intValue()); }
From source file:com.github.ferstl.spring.jdbc.oracle.OracleNamedParameterJdbcTemplateTest.java
@Test public void endingNoSpace() throws SQLException { Map<String, Object> map = new HashMap<>(3); map.put("ten", 10); map.put("twenty", 20); String sql = "SELECT 1 FROM dual WHERE 1 = :ten or 20 = :twenty"; PreparedStatementCreator preparedStatementCreator = this.namedJdbcTemplate.getPreparedStatementCreator(sql, new MapSqlParameterSource(map)); Connection connection = mock(Connection.class); PreparedStatement preparedStatement = mock(PreparedStatement.class); OraclePreparedStatement oracleStatement = mock(OraclePreparedStatement.class); when(connection.prepareStatement(sql)).thenReturn(preparedStatement); when(preparedStatement.unwrap(OraclePreparedStatement.class)).thenReturn(oracleStatement); preparedStatementCreator.createPreparedStatement(connection); verify(oracleStatement).setObjectAtName("ten", 10); verify(oracleStatement).setObjectAtName("twenty", 20); }
From source file:ru.mystamps.web.dao.impl.JdbcImageDataDao.java
@Override public Integer add(AddImageDataDbDto imageData) { Map<String, Object> params = new HashMap<>(); params.put("image_id", imageData.getImageId()); params.put("content", imageData.getContent()); KeyHolder holder = new GeneratedKeyHolder(); int affected = jdbcTemplate.update(addImageDataSql, new MapSqlParameterSource(params), holder); Validate.validState(affected == 1, "Unexpected number of affected rows after creation of image's data: %d", affected);/*ww w .j a v a 2 s . c o m*/ return Integer.valueOf(holder.getKey().intValue()); }
From source file:pl.edu.agh.samm.db.impl.ActionExecutionDAO.java
@Override public void store(ActionExecution execution) { Map<String, Object> params = new HashMap<String, Object>(); params.put("actionUri", execution.getAction().getActionURI()); params.put("start", execution.getStartTime()); params.put("end", execution.getEndTime()); SqlParameterSource sps = new MapSqlParameterSource(params); getSimpleJdbcTemplate().update(SQL_INSERT, sps); Integer actionId = getLastId(); List<Object[]> batchParams = new LinkedList<Object[]>(); // if there are any parameters - store them too if (execution.getAction().getParameterValues() != null) { for (Map.Entry<String, String> entry : execution.getAction().getParameterValues().entrySet()) { batchParams.add(new Object[] { actionId, entry.getKey(), entry.getValue() }); }/*from w w w .jav a 2 s . c o m*/ getSimpleJdbcTemplate().batchUpdate(SQL_INSERT_PARAM, batchParams); } }
From source file:net.duckling.falcon.api.orm.BaseDao.java
/** * @description ????,"id"/*from www. j a v a 2 s .co m*/ * @author lvly * @since 2012-08-07 * @param t * ?? * @param expect * ?bean * @return id * **/ public <T> int insert(T t, String expect) { DAOUtils<T> daoUtils = new DAOUtils<T>(t.getClass()); String sql = daoUtils.getInsert("id," + expect); LOG.debug(sql); KeyHolder keyHolder = new GeneratedKeyHolder(); getNamedParameterJdbcTemplate().update(sql, new MapSqlParameterSource(daoUtils.getParamMap(t, true)), keyHolder); return keyHolder.getKey().intValue(); }
From source file:io.kahu.hawaii.util.call.sql.AbortableQuery.java
@Override protected void executeInternally(ResponseHandler responseHandler, Response response) throws ServerException { SqlParameterSource paramSource = new MapSqlParameterSource(params); PreparedStatementCreator psc = getPreparedStatementCreator(sql, paramSource); Connection connection = DataSourceUtils.getConnection(dataSource); try {//from w ww . j a v a 2 s .c om preparedStatement = psc.createPreparedStatement(connection); switch (callType) { case INSERT: preparedStatement.executeUpdate(); new UpdateIdResponseHandler().addToResponse(preparedStatement, response); break; case DELETE: // fall though case UPDATE: response.set(preparedStatement.executeUpdate()); break; case SELECT: ResultSet resultSet = preparedStatement.executeQuery(); responseHandler.addToResponse(resultSet, response); break; default: throw new ServerException(ServerError.ILLEGAL_ARGUMENT, "Unknown call type '" + callType + "'."); } } catch (SQLException e) { try { connection.rollback(); } catch (Throwable t) { // } if (!aborted) { response.setStatus(ResponseStatus.BACKEND_FAILURE, e); } throw new ServerException(ServerError.UNEXPECTED_EXCEPTION, e); } finally { DataSourceUtils.releaseConnection(connection, dataSource); } }
From source file:tomekkup.helenos.dao.ClusterConfigDao.java
private SqlParameterSource prepareParameterSource(ClusterConfiguration configuration) { return new MapSqlParameterSource(configuration.toParametersMap()); }