List of usage examples for org.springframework.jdbc.core.namedparam MapSqlParameterSource MapSqlParameterSource
public MapSqlParameterSource()
From source file:Implement.DAO.CommonDAOImpl.java
@Override public AdvancedSearchForm search(String searchText, int pageNumber, int pageSize) { simpleJdbcCall = new SimpleJdbcCall(dataSource).withProcedureName("searchPackages"); simpleJdbcCall.returningResultSet("rs1", PackagesViewMapper.getInstance()) .returningResultSet("rs2", new RowMapper<String>() { @Override//w w w . java 2 s . c o m public String mapRow(ResultSet rs, int i) throws SQLException { return rs.getString("Keyword"); } }).returningResultSet("rs3", PopularPackageMapper.getInstance()) .returningResultSet("rs4", LocationDTOMapper.getInstance()); SqlParameterSource in = new MapSqlParameterSource().addValue("searchText", searchText) .addValue("PageNumber", pageNumber).addValue("RowspPage", pageSize); Map<String, Object> record = simpleJdbcCall.execute(in); List<PackagesViewDTO> packages = (List<PackagesViewDTO>) record.get("rs1"); List<String> keywords = (List<String>) record.get("rs2"); List<LocationDTO> locations = (List<LocationDTO>) record.get("rs4"); List<PopularPackageDTO> popularPackages = (List<PopularPackageDTO>) record.get("rs3"); return new AdvancedSearchForm(packages, keywords, locations, popularPackages); }
From source file:com.opengamma.elsql.ElSqlBundle.java
/** * Gets SQL for a named fragment key, without specifying parameters. * <p>/*from w w w . ja va2s. c om*/ * Note that if the SQL contains tags that depend on variables, like AND or LIKE, * then an error will be thrown. * * @param name the name, not null * @return the SQL, not null * @throws IllegalArgumentException if there is no fragment with the specified name * @throws RuntimeException if a problem occurs */ public String getSql(String name) { return getSql(name, new MapSqlParameterSource()); }
From source file:com.siblinks.ws.service.impl.VideoSubscriptionsServiceImpl.java
/** * {@inheritDoc}//from www. ja v a2 s . c o m */ @Override @RequestMapping(value = "/getListVideoSubscription", method = RequestMethod.GET) public ResponseEntity<Response> getListVideoSubscription(@RequestParam("userId") final String userId, @RequestParam("subjectId") final String subjectId) { SimpleResponse response = null; try { String method = "getListVideoSubscription()"; logger.debug(method + " start"); String entityName = null; List<Object> readObject = null; String currentDate = ""; String firstDayOfCurrentWeek = ""; Object[] queryParams = null; Map<String, List<Object>> mapListVideo = new HashMap<String, List<Object>>(); try { Calendar cal = Calendar.getInstance(); cal.setTime(new Date()); cal.setFirstDayOfWeek(Calendar.MONDAY); cal.set(Calendar.DAY_OF_WEEK, cal.getFirstDayOfWeek()); Date firstDayOfTheWeek = cal.getTime(); currentDate = DateUtil.date2YYYYMMDD000000(new Date()); firstDayOfCurrentWeek = DateUtil.date2YYYYMMDD000000(firstDayOfTheWeek); if ("-2".equals(subjectId)) { entityName = SibConstants.SqlMapper.SQL_SIB_GET_ALL_VIDEO_SUBSCRIPTION; queryParams = new Object[] { userId, currentDate, userId, firstDayOfCurrentWeek, currentDate, userId, firstDayOfCurrentWeek }; readObject = dao.readObjects(entityName, queryParams); } else { // Get child category by subjectId List<Map<String, Object>> readObjectNoCondition = dao .readObjectNoCondition(SibConstants.SqlMapper.SQL_GET_ALL_CATEGORY_TOPIC); MapSqlParameterSource params = new MapSqlParameterSource(); String allChildCategory = CommonUtil.getAllChildCategory(subjectId, readObjectNoCondition); if (!StringUtil.isNull(allChildCategory)) { List<Integer> listChildCategory = new ArrayList<Integer>(); String[] arrChildCategory = allChildCategory.split(","); for (String string : arrChildCategory) { listChildCategory.add(Integer.parseInt(string)); } params.addValue("subjectID", listChildCategory); } params.addValue("userID", userId); params.addValue("currentDate", currentDate); params.addValue("firstDayOfCurrentWeek", firstDayOfCurrentWeek); entityName = SibConstants.SqlMapper.SQL_SIB_GET_ALL_VIDEO_SUBSCRIPTION_BY_CATEGORY; readObject = dao.readObjectNamedParameter(entityName, params); } if (readObject == null) { readObject = new ArrayList<Object>(); } JSONArray jsonAraay = new JSONArray(readObject); for (int i = 0; i < jsonAraay.length(); i++) { JSONObject jsonObj = jsonAraay.getJSONObject(i); ObjectMapper mapper = new ObjectMapper(); Object obj = mapper.readValue(jsonObj.toString(), Object.class); addMapVideo(mapListVideo, jsonObj.get("flag").toString(), obj); } } catch (ParseException | IOException e) { logger.error(method + " - error : " + e.getMessage()); } response = new SimpleResponse("true", mapListVideo); } catch (Exception e) { e.printStackTrace(); response = new SimpleResponse(SibConstants.FAILURE, "video", "getListVideoSubscription", e.getMessage()); } return new ResponseEntity<Response>(response, HttpStatus.OK); }
From source file:com.joliciel.jochre.graphics.GraphicsDaoJdbc.java
@Override public List<Shape> findShapes(RowOfShapes row) { NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource()); String sql = "SELECT " + SELECT_SHAPE + " FROM ocr_shape" + " INNER JOIN ocr_group ON shape_group_id = group_id" + " WHERE group_row_id = :group_row_id" + " ORDER BY group_index, shape_index"; MapSqlParameterSource paramSource = new MapSqlParameterSource(); paramSource.addValue("group_row_id", row.getId()); LOG.debug(sql);//from w w w. j av a 2 s . com logParameters(paramSource); @SuppressWarnings("unchecked") List<Shape> shapes = jt.query(sql, paramSource, new ShapeMapper(this.getGraphicsServiceInternal())); return shapes; }
From source file:com.perry.infrastructure.call.CallDaoServiceImpl.java
@Override public void delete(long callId) { String sql = "delete from calls where call_id = :callId"; MapSqlParameterSource params = new MapSqlParameterSource(); params.addValue("callId", callId); namedParameterJdbcTemplate.update(sql, params); }
From source file:org.inbio.modeling.core.dao.impl.LayerDAOImpl.java
@Override public List<Layer> findAllSpeciesLayers() { String sqlStatement = null;/* w w w .j a v a 2 s .co m*/ MapSqlParameterSource args = null; List<Layer> layers = null; sqlStatement = "SELECT * FROM " + this.table + " " + " WHERE is_species_map = :isSpecies"; args = new MapSqlParameterSource(); args.addValue("isSpecies", true); layers = getSimpleJdbcTemplate().query(sqlStatement, new LayerRowMapper(), args); return layers; }
From source file:ru.org.linux.user.UserTagDao.java
/** * ?? ID , ? ? ./*from w w w .j ava 2 s. co m*/ * * @param userId ?, ? * @param tags ?? * @return ?? ID */ public List<Integer> getUserIdListByTags(int userId, List<String> tags) { if (tags.isEmpty()) { return ImmutableList.of(); } MapSqlParameterSource parameters = new MapSqlParameterSource(); parameters.addValue("values", tags); parameters.addValue("user_id", userId); return jdbcTemplate.queryForList( "select distinct user_id from user_tags where tag_id in (select id from tags_values where value in ( :values )) " + "AND is_favorite = true AND user_id <> :user_id", parameters, Integer.class); }
From source file:com.ushahidi.swiftriver.core.api.dao.impl.JpaTagDao.java
/** * For the given list of new drops, find those that the tag hash already * exists in the db and update the drop entry with the existing id. Also * remove the hash from the new tag index for those that already exist. * /*from w w w. j av a 2 s . co m*/ * @param newTagIndex * @param drops */ private void updateNewTagIndex(Map<String, List<int[]>> newTagIndex, List<Drop> drops) { // First find and update existing drops with their ids. String sql = "SELECT id, hash FROM tags WHERE hash IN (:hashes)"; MapSqlParameterSource params = new MapSqlParameterSource(); params.addValue("hashes", newTagIndex.keySet()); List<Map<String, Object>> results = this.namedJdbcTemplate.queryForList(sql, params); // Update id for the drops that were found for (Map<String, Object> result : results) { String hash = (String) result.get("hash"); Long id = ((Number) result.get("id")).longValue(); List<int[]> indexes = newTagIndex.get(hash); for (int[] index : indexes) { drops.get(index[0]).getTags().get(index[1]).setId(id); } // Hash is not for a new drop so remove it newTagIndex.remove(hash); } }
From source file:br.com.asisprojetos.DAO.TBRelatorioDiagnosticoDAO.java
public List<Map<String, Object>> getConsolidatedRecurrentResults( List<String> listProtocols/*, List<String> listCodCliente*/ ) { List<Map<String, Object>> listResults = null; String SQL = " SELECT T.COD_FORMULA, " + " T.NOM_FORMULA, " + " COUNT(T.COD_FORMULA) AS RECORRENCIA " + " FROM " + " (SELECT P.NUM_PROT, " + " F.NOM_FORMULA, " + " F.COD_FORMULA " + " FROM SPF_TBCTRL_PROCESSO P " + " INNER JOIN SPF_TBITEM_RESULT IR ON P.NUM_PROT = IR.NUM_PROT " + " INNER JOIN SPF_TBFORMULA F ON IR.COD_FORMULA = F.COD_FORMULA " + " WHERE P.NUM_PROT IN ( :numProtocol ) " + " AND F.NIVEL_FORMULA NOT IN ('4', '5') " + //" AND P.COD_CLIENTE IN ( :codCliente ) " + " GROUP BY P.NUM_PROT, F.COD_FORMULA) AS T " + " GROUP BY T.COD_FORMULA " + " ORDER BY COUNT(T.COD_FORMULA) DESC LIMIT 5 "; MapSqlParameterSource namedParameters = new MapSqlParameterSource(); namedParameters.addValue("numProtocol", listProtocols); //namedParameters.addValue( "codCliente" , listCodCliente ); try {/* w ww. j a v a 2 s . c o m*/ listResults = getNamedParameterJdbcTemplate().queryForList(SQL, namedParameters); } catch (DataAccessException ex) { logger.error("Erro ao efetuar busca no banco de dados. Message {}", ex); } return listResults; }
From source file:com.joliciel.lefff.LefffDaoImpl.java
public void saveAttribute(AttributeInternal attribute) { NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource()); MapSqlParameterSource paramSource = new MapSqlParameterSource(); paramSource.addValue("attribute_code", attribute.getCode()); paramSource.addValue("attribute_value", attribute.getValue()); paramSource.addValue("attribute_morph", attribute.isMorphological()); if (attribute.isNew()) { String sql = "SELECT nextval('seq_attribute_id')"; LOG.info(sql);//from ww w . jav a 2 s .c om int attributeId = jt.queryForInt(sql, paramSource); paramSource.addValue("attribute_id", attributeId); sql = "INSERT INTO lef_attribute (attribute_id, attribute_code, attribute_value, attribute_morph)" + " VALUES (:attribute_id, :attribute_code, :attribute_value, :attribute_morph)"; LOG.info(sql); LefffDaoImpl.LogParameters(paramSource); jt.update(sql, paramSource); attribute.setId(attributeId); } else { String sql = "UPDATE lef_attribute" + " SET attribute_code = :attribute_code" + ", attribute_value = :attribute_value" + ", attribute_morph = :attribute_morph" + " WHERE attribute_id = :attribute_id"; paramSource.addValue("attribute_id", attribute.getId()); LOG.info(sql); LefffDaoImpl.LogParameters(paramSource); jt.update(sql, paramSource); } }