List of usage examples for org.springframework.jdbc.core.namedparam MapSqlParameterSource MapSqlParameterSource
public MapSqlParameterSource()
From source file:ru.org.linux.tracker.TrackerDao.java
public List<TrackerItem> getTrackAll(TrackerFilterEnum filter, User currentUser, Timestamp interval, int topics, int offset, final int messagesInPage) { MapSqlParameterSource parameter = new MapSqlParameterSource(); parameter.addValue("interval", interval); parameter.addValue("topics", topics); parameter.addValue("offset", offset); String partIgnored;//from www.jav a2 s .c o m if (currentUser != null) { partIgnored = queryPartIgnored + queryPartTagIgnored; parameter.addValue("userid", currentUser.getId()); } else { partIgnored = ""; } String partFilter; String partWiki = queryPartWiki; switch (filter) { case ALL: partFilter = ""; break; case NOTALKS: partFilter = queryPartNoTalks; break; case TECH: partFilter = queryPartTech; break; case MINE: if (currentUser != null) { partFilter = queryPartMine; partWiki = queryPartWikiMine; } else { partFilter = ""; } break; default: partFilter = ""; } boolean showUncommited = currentUser != null && (currentUser.isModerator() || currentUser.isCorrector()); String partUncommited = showUncommited ? "" : noUncommited; String query; if (filter != TrackerFilterEnum.ZERO) { query = String.format(queryTrackerMain, partUncommited, partIgnored, partFilter, partUncommited, partIgnored, partFilter, partWiki); } else { query = String.format(queryTrackerZeroMain, partIgnored); } SqlRowSet resultSet = jdbcTemplate.queryForRowSet(query, parameter); List<TrackerItem> res = new ArrayList<>(topics); while (resultSet.next()) { User author; try { int author_id = resultSet.getInt("author"); if (author_id != 0) { author = userDao.getUserCached(author_id); } else { author = null; } } catch (UserNotFoundException e) { throw new RuntimeException(e); } int msgid = resultSet.getInt("id"); Timestamp lastmod = resultSet.getTimestamp("lastmod"); int stat1 = resultSet.getInt("stat1"); int groupId = resultSet.getInt("gid"); String groupTitle = resultSet.getString("gtitle"); String title = resultSet.getString("title"); int cid = resultSet.getInt("cid"); User lastCommentBy; try { int id = resultSet.getInt("last_comment_by"); if (id != 0) { lastCommentBy = userDao.getUserCached(id); } else { lastCommentBy = null; } } catch (UserNotFoundException e) { throw new RuntimeException(e); } boolean resolved = resultSet.getBoolean("resolved"); int section = resultSet.getInt("section"); String groupUrlName = resultSet.getString("urlname"); Timestamp postdate = resultSet.getTimestamp("postdate"); boolean uncommited = resultSet.getBoolean("smod") && !resultSet.getBoolean("moderate"); int pages = Topic.getPageCount(stat1, messagesInPage); ImmutableList<String> tags; if (msgid != 0) { tags = topicTagService.getMessageTagsForTitle(msgid); } else { tags = ImmutableList.of(); } res.add(new TrackerItem(author, msgid, lastmod, stat1, groupId, groupTitle, title, cid, lastCommentBy, resolved, section, groupUrlName, postdate, uncommited, pages, tags)); } return res; }
From source file:tds.assessment.repositories.impl.ItemMeasurementQueryRepositoryImplIntegrationTests.java
@Before public void setUp() { itemMeasurementQueryRepository = new ItemMeasurementQueryRepositoryImpl(jdbcTemplate); // Segmented test assessment final String tblSetOfAdminSubjectsInsertSQL2 = "INSERT INTO itembank.tblsetofadminsubjects VALUES ('(SBAC_PT)SBAC-Mathematics-8-Spring-2013-2015','SBAC_PT', 'SBAC_PT-ELA','SBAC-Mathematics-8'," + "0,1,4,4,1,1,NULL,NULL,0,0,NULL,'virtual',NULL,5,1,20,1,5,NULL,NULL,1,1,8185,8185,5,0,'SBAC_PT',NULL,'ABILITY',NULL,1,NULL,1,1,NULL,NULL,0,0,0,0," + "0,'bp1',NULL,NULL,'summative');"; // Segment 1//from w w w .j a v a2 s . co m final String tblSetOfAdminSubjectsInsertSQL2a = "INSERT INTO itembank.tblsetofadminsubjects VALUES ('(SBAC_PT)SBAC-SEG1-MATH-8-Spring-2013-2015','SBAC_PT', 'SBAC_PT-ELA','SBAC-SEG1-MATH-8'," + "0,1,4,4,1,1,NULL,NULL,2,3,NULL,'fixedform',NULL,5,1,20,1,5,'(SBAC_PT)SBAC-Mathematics-8-Spring-2013-2015',1,0,1,8185,8185,5,0,'SBAC_PT',NULL,'ABILITY',NULL,1,NULL,1,1,NULL,NULL,0,0,0,0," + "0,'bp1',NULL,NULL,'summative');"; // Segment2 final String tblSetOfAdminSubjectsInsertSQL2b = "INSERT INTO itembank.tblsetofadminsubjects VALUES ('(SBAC_PT)SBAC-SEG2-MATH-8-Spring-2013-2015','SBAC_PT', 'SBAC_PT-ELA','SBAC-SEG2-MATH-8'," + "0,1,4,4,1,1,NULL,NULL,1,4,NULL,'fixedform',NULL,5,1,20,1,5,'(SBAC_PT)SBAC-Mathematics-8-Spring-2013-2015',2,0,1,8185,8185,5,0,'SBAC_PT',NULL,'ABILITY',NULL,1,NULL,1,1,NULL,NULL,0,0,0,0," + "0,'bp1',NULL,NULL,'summative');"; final String tblSetAdminItemsInsertSQL = "INSERT INTO itembank.tblsetofadminitems \n" + " (_fk_item, _fk_adminsubject, groupid, groupkey, blockid, itemposition, isfieldtest, isactive, isrequired, " + " strandname, isprintable, responsemimetype, notforscoring, irt_model, irt_a, irt_b, irt_c, clstring, bvector) \n" + "VALUES \n" + " ('187-1233', '(SBAC_PT)SBAC-Mathematics-8-Spring-2013-2015', 'G-1', 'GK-1', 'A', 1, 0, 1, 1, 'strand 99', 0, 'text/plain', 0, NULL, NULL, NULL, NULL, NULL, NULL),\n" + " ('187-1234', '(SBAC_PT)SBAC-SEG1-MATH-8-Spring-2013-2015', 'G-1', 'GK-1', 'A', 1, 0, 1, 1, 'strand1', 0, 'text/plain', 0, NULL, NULL, NULL, NULL, NULL, NULL),\n" + " ('187-1235', '(SBAC_PT)SBAC-SEG1-MATH-8-Spring-2013-2015', 'G-2', 'GK-2', 'A', 2, 0, 1, 1, 'strand2', 0, 'text/xml', 1, NULL, NULL, NULL, NULL, NULL, NULL),\n" + " ('187-1236', '(SBAC_PT)SBAC-SEG2-MATH-8-Spring-2013-2015', 'G-3', 'GK-3', 'A', 1, 0, 1, 1, 'strand3', 1, 'foo', 0, 'IRT3PLn', 0.54343, '1.2160500288009644', 0, 'SBAC-2-W;SBAC-2-W|9-5', 1.21605), \n" + " ('187-1237', '(SBAC_PT)IRP-Perf-ELA-11-Summer-2015-2016', 'G-4', 'GK-4', 'A', 1, 1, 1, 1, 'silver strand', 0, 'bar', 1, NULL, NULL, NULL, NULL, NULL, NULL)"; final String parentItemScoreDimensionSQL = "INSERT INTO itemscoredimension (dimension, recoderule, responsebankscale, scorepoints, surrogateitemid, weight, _key, _efk_surrogateitskey, _fk_adminsubject, _fk_item, _fk_measurementmodel)" + " VALUES ('parentDimension', '', NULL, 1, NULL, 1, :key, NULL, '(SBAC_PT)SBAC-Mathematics-8-Spring-2013-2015', '187-1233', 1)"; final String segmentItemScoreDimensionSQL = "INSERT INTO itemscoredimension (dimension, recoderule, responsebankscale, scorepoints, surrogateitemid, weight, _key, _efk_surrogateitskey, _fk_adminsubject, _fk_item, _fk_measurementmodel)" + " VALUES ('segmentDimension', '', NULL, 1, NULL, 1, :key, NULL, '(SBAC_PT)SBAC-SEG1-MATH-8-Spring-2013-2015', '187-1234', 1)"; final String measurementModelSQL = "INSERT INTO measurementmodel (modelnumber, modelname) VALUES (1, 'IRT3PL');"; final String measureParameterSQL = "INSERT INTO measurementparameter (_fk_measurementmodel, parmnum, parmname, parmdescription) VALUES\n" + "(1, 0, 'a', 'Slope (a)'),\n" + "(1, 1, 'b', 'Difficulty (b)'),\n" + "(1, 2, 'c', 'Guessing (c)')"; final String parentItemMeasurementParameter = "INSERT INTO itemmeasurementparameter (_fk_itemscoredimension, _fk_measurementparameter, parmvalue) VALUES (:key, 1, 0.85457);"; final String segmentItemMeasurementParameterSQL = "INSERT INTO itemmeasurementparameter (_fk_itemscoredimension, _fk_measurementparameter, parmvalue) VALUES (:key, 1, 1.71271);"; final SqlParameterSource emptyParameters = new MapSqlParameterSource(); jdbcTemplate.update(tblSetOfAdminSubjectsInsertSQL2, emptyParameters); jdbcTemplate.update(tblSetOfAdminSubjectsInsertSQL2a, emptyParameters); jdbcTemplate.update(tblSetOfAdminSubjectsInsertSQL2b, emptyParameters); jdbcTemplate.update(tblSetAdminItemsInsertSQL, emptyParameters); SqlParameterSource parameters = new MapSqlParameterSource("key", UuidAdapter.getBytesFromUUID(UUID.randomUUID())); jdbcTemplate.update(parentItemScoreDimensionSQL, parameters); jdbcTemplate.update(parentItemMeasurementParameter, parameters); parameters = new MapSqlParameterSource("key", UuidAdapter.getBytesFromUUID(UUID.randomUUID())); jdbcTemplate.update(segmentItemScoreDimensionSQL, parameters); jdbcTemplate.update(segmentItemMeasurementParameterSQL, parameters); jdbcTemplate.update(measurementModelSQL, emptyParameters); jdbcTemplate.update(measureParameterSQL, emptyParameters); }
From source file:com.epam.catgenome.dao.BiologicalDataItemDao.java
/** * Loads a List of BiologicalDataItem from the database by their IDs * @param ids List of IDs of BiologicalDataItem instances * @return List of BiologicalDataItem, matching specified IDs *///from w w w . j av a2 s . c om @Transactional(propagation = Propagation.MANDATORY) public List<BiologicalDataItem> loadBiologicalDataItemsByIds(List<Long> ids) { if (ids == null || ids.isEmpty()) { return Collections.emptyList(); } Long listId = daoHelper.createTempLongList(ids); final MapSqlParameterSource params = new MapSqlParameterSource(); params.addValue(BiologicalDataItemParameters.BIO_DATA_ITEM_ID.name(), listId); List<BiologicalDataItem> items = getNamedParameterJdbcTemplate().query(loadBiologicalDataItemsByIdsQuery, params, getRowMapper()); daoHelper.clearTempList(listId); return items; }
From source file:Implement.DAO.CommonDAOImpl.java
@Override public List<PackagesViewDTO> searchWithPageNumber(String searchText, int pageNumber, int pageSize) { simpleJdbcCall = new SimpleJdbcCall(dataSource).withProcedureName("searchPackagesWithPageNumber"); simpleJdbcCall.returningResultSet("rs1", PackagesViewMapper.getInstance()); SqlParameterSource in = new MapSqlParameterSource().addValue("searchText", searchText) .addValue("PageNumber", pageNumber).addValue("RowspPage", pageSize); Map<String, Object> record = simpleJdbcCall.execute(in); return (List<PackagesViewDTO>) record.get("rs1"); }
From source file:ru.org.linux.user.UserTagDao.java
/** * .// w w w .j a va2 s .co m * * @param oldTagId ? * @param newTagId */ public void replaceTag(int oldTagId, int newTagId) { MapSqlParameterSource parameters = new MapSqlParameterSource(); parameters.addValue("new_tag_id", newTagId); parameters.addValue("old_tag_id", oldTagId); jdbcTemplate.update( "UPDATE user_tags SET tag_id=:new_tag_id WHERE tag_id=:old_tag_id " + "AND user_id NOT IN (SELECT user_id FROM user_tags WHERE tag_id=:new_tag_id)", parameters); }
From source file:com.joliciel.frenchTreebank.TreebankDaoImpl.java
public void saveCategory(CategoryInternal category) { NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource()); MapSqlParameterSource paramSource = new MapSqlParameterSource(); paramSource.addValue("cat_code", category.getCode()); paramSource.addValue("cat_description", category.getDescription()); if (category.isNew()) { String sql = "SELECT nextval('ftb_category_cat_id_seq')"; LOG.info(sql);//from w w w . jav a2 s . c om int categoryId = jt.queryForInt(sql, paramSource); paramSource.addValue("cat_id", categoryId); sql = "INSERT INTO ftb_category (cat_id, cat_code, cat_description) VALUES (:cat_id, :cat_code, :cat_description)"; LOG.info(sql); TreebankDaoImpl.LogParameters(paramSource); jt.update(sql, paramSource); category.setId(categoryId); } else { String sql = "UPDATE ftb_category" + " SET cat_code = :cat_code" + ", cat_description = :cat_description" + " WHERE cat_id = :cat_id"; paramSource.addValue("cat_id", category.getId()); LOG.info(sql); TreebankDaoImpl.LogParameters(paramSource); jt.update(sql, paramSource); } }
From source file:com.ushahidi.swiftriver.core.api.dao.impl.JpaDropDao.java
/** * For the given list of new drops, find those that the hash already exist * and update the drop entry with the existing id and remove the hash from * the new drop index.//from ww w . j ava 2s . co m * * @param newDropIndex * @param drops */ private void updateNewDropIndex(Map<String, List<Integer>> newDropIndex, List<Drop> drops) { // First find and update existing drops with their ids. String sql = "SELECT id, droplet_hash FROM droplets WHERE droplet_hash IN (:hashes)"; MapSqlParameterSource params = new MapSqlParameterSource(); params.addValue("hashes", newDropIndex.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("droplet_hash"); Long id = ((Number) result.get("id")).longValue(); List<Integer> indexes = newDropIndex.get(hash); for (Integer index : indexes) { drops.get(index).setId(id); } // Hash is not for a new drop so remove it newDropIndex.remove(hash); } }
From source file:org.jasig.schedassist.impl.statistics.SpringJDBCStatisticsDaoImpl.java
@Override public List<AppointmentEvent> getEvents(IScheduleOwner owner, Date startTime, Date endTime, List<EventType> eventTypes) { MapSqlParameterSource parameterSource = new MapSqlParameterSource(); parameterSource.addValue("ownerId", owner.getId()); parameterSource.addValue("startTime", startTime); parameterSource.addValue("endTime", endTime); parameterSource.addValue("eventTypes", eventTypes); List<AppointmentEvent> results = this.simpleJdbcTemplate.query( "select event_id,owner_id,visitor_id,event_type,event_timestamp,event_start from event_statistics where owner_id = :ownerId and event_timestamp >= :startTime and event_timestamp <= :endTime and event_type in (:eventTypes)", new AppointmentEventRowMapper(ownerDao), parameterSource); return results; }
From source file:com.joliciel.jochre.doc.DocumentDaoJdbc.java
@Override public JochreDocument loadJochreDocument(int jochreDocumentId) { NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource()); String sql = "SELECT " + SELECT_DOCUMENT + " FROM ocr_document WHERE doc_id=:doc_id"; MapSqlParameterSource paramSource = new MapSqlParameterSource(); paramSource.addValue("doc_id", jochreDocumentId); LOG.info(sql);/*from ww w.ja va2 s .c o m*/ logParameters(paramSource); JochreDocument jochreDocument = null; try { jochreDocument = (JochreDocument) jt.queryForObject(sql, paramSource, new JochreDocumentMapper(this.getDocumentServiceInternal())); } catch (EmptyResultDataAccessException ex) { ex.hashCode(); } return jochreDocument; }
From source file:com.joliciel.jochre.graphics.GraphicsDaoJdbc.java
@Override public List<Shape> findShapesToSplit(Locale locale) { NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource()); String sql = "SELECT " + SELECT_SHAPE + ", count(split_id) as the_count FROM ocr_shape" + " LEFT JOIN ocr_split on shape_id = split_shape_id" + " LEFT JOIN ocr_group ON shape_group_id = group_id" + " LEFT JOIN ocr_row ON group_row_id = row_id" + " LEFT JOIN ocr_paragraph ON row_paragraph_id = paragraph_id" + " LEFT JOIN ocr_image ON paragraph_image_id = image_id" + " WHERE length(shape_letter)>1" + " AND shape_letter not like '%|'" + " AND shape_letter not like '|%'" + " AND shape_letter not in (:dual_character_letters)" + " AND image_imgstatus_id in (:image_imgstatus_id)" + " GROUP BY " + SELECT_SHAPE + " ORDER BY the_count, shape_letter, shape_id"; MapSqlParameterSource paramSource = new MapSqlParameterSource(); Linguistics linguistics = Linguistics.getInstance(locale); paramSource.addValue("dual_character_letters", linguistics.getDualCharacterLetters()); List<Integer> imageStatusList = new ArrayList<Integer>(); imageStatusList.add(ImageStatus.TRAINING_VALIDATED.getId()); imageStatusList.add(ImageStatus.TRAINING_HELD_OUT.getId()); imageStatusList.add(ImageStatus.TRAINING_TEST.getId()); paramSource.addValue("image_imgstatus_id", imageStatusList); LOG.debug(sql);/* w w w . java2 s . com*/ logParameters(paramSource); @SuppressWarnings("unchecked") List<Shape> shapes = jt.query(sql, paramSource, new ShapeMapper(this.getGraphicsServiceInternal())); return shapes; }