List of usage examples for org.springframework.jdbc.core RowMapper RowMapper
RowMapper
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//ww w .j av a 2s . com 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:shell.framework.organization.user.service.impl.TblSysUserService4JdbcImpl.java
public TblSysUser findUserByUserCode(String userCode) { String sql = "select * from TBL_SYS_USER user where user.USERCODE=?"; List<?> resultList = jdbcBaseDao.query(sql, new Object[] { userCode }, new RowMapper<Object>() { /* (non-Javadoc) * @see org.springframework.jdbc.core.RowMapper#mapRow(java.sql.ResultSet, int) *///from w w w. j a v a 2 s. com public Object mapRow(ResultSet rs, int rowNum) throws SQLException { TblSysUser user = new TblSysUser(); Map<String, String> propertyMap = new HashMap<String, String>(); propertyMap.put("createdTime", "CREATE_TIME"); propertyMap.put("updatedTime", "UPDATE_TIME"); PopulateUtil.populate(user, rs, propertyMap); return user; } }); return (resultList == null || resultList.size() == 0) ? null : (TblSysUser) resultList.get(0); }
From source file:org.sakaiproject.delegatedaccess.dao.impl.DelegatedAccessDaoImpl.java
public String getSiteProperty(String propertyName, String siteId) { try {// w w w .j a va2 s. c o m return (String) getJdbcTemplate().queryForObject(getStatement("select.siteProperty"), new Object[] { propertyName, siteId }, new RowMapper() { public Object mapRow(ResultSet resultSet, int i) throws SQLException { return resultSet.getString("VALUE"); } }); } catch (DataAccessException ex) { log.error("Error executing query: " + ex.getClass() + ":" + ex.getMessage(), ex); return null; } }
From source file:com.sfs.dao.ObjectTypeDAOImpl.java
/** * Load an ObjectTypeBean for the supplied parameters. * * @param object the object//from w w w.j av a2s .co m * @param objectName the object name * @param objectClass the object class * * @return the object type bean * * @throws SFSDaoException the SFS dao exception */ @SuppressWarnings("unchecked") public final ObjectTypeBean load(final String object, final String objectName, final String objectClass) throws SFSDaoException { if (object == null) { throw new SFSDaoException("Object definition cannot be null"); } if (objectName == null) { throw new SFSDaoException("Object Name cannot be null"); } if (objectClass == null) { throw new SFSDaoException("Object Class canot be null"); } ObjectTypeBean objectType = null; try { objectType = (ObjectTypeBean) this.getJdbcTemplateReader().queryForObject( this.getSQL().getValue("objectType/loadType"), new Object[] { object, objectName, objectClass }, new RowMapper() { public Object mapRow(final ResultSet rs, final int rowNum) throws SQLException { return loadObject(rs); } }); } catch (IncorrectResultSizeDataAccessException ie) { dataLogger.debug("No results found for this search: " + ie.getMessage()); } if (objectType == null) { throw new SFSDaoException("No objecttype found"); } return objectType; }
From source file:com.sfs.whichdoctor.dao.TagDAOImpl.java
/** * Used to get an ArrayList of TagBeans for a specified search term. * * @param tagName the tag name/* w w w . java 2 s .co m*/ * @return the collection * @throws WhichDoctorDaoException the which doctor dao exception */ @SuppressWarnings("unchecked") public final Collection<TagBean> autocomplete(final String tagName) throws WhichDoctorDaoException { if (tagName == null) { throw new WhichDoctorDaoException("Tag search term cannot be null"); } Collection<TagBean> tags = new ArrayList<TagBean>(); /* Only perform a search if there is more than two characters to search on */ if (tagName.length() > 2) { dataLogger.info("Performing tag search for '" + tagName + "'"); final String loadTags = getSQL().getValue("tag/autocomplete"); try { tags = this.getJdbcTemplateReader().query(loadTags, new Object[] { "%" + tagName + "%" }, new RowMapper() { public Object mapRow(final ResultSet rs, final int rowNum) throws SQLException { TagBean tag = new TagBean(); tag.setTagName(rs.getString("TagName")); return tag; } }); } catch (IncorrectResultSizeDataAccessException ie) { dataLogger.debug("No results for this search: " + ie.getMessage()); } } return tags; }
From source file:bd.gov.forms.dao.UserDaoImpl.java
public List getUserList() { return jdbcTemplate.query("SELECT * FROM user ", new Object[] {}, new RowMapper() { public Object mapRow(ResultSet rs, int rowNum) throws SQLException { User user = new User(); user.setSysId(rs.getString("sys_id")); user.setName(rs.getString("name")); user.setTitle(rs.getString("title")); user.setUserName(rs.getString("user")); user.setAdmin(rs.getInt("admin")); user.setActive(rs.getInt("active")); return user; }//from www .j a v a 2s . co m }); }
From source file:org.ohmage.query.impl.ImageQueries.java
@Override public List<Image> getUnprocessedImages() throws DataAccessException { try {/*from w w w .j a v a 2s . co m*/ return getJdbcTemplate().query("SELECT uuid, url " + "FROM url_based_resource AS ubr " + "LEFT JOIN prompt_response AS pr " + "ON ubr.uuid = pr.response " + "WHERE pr.prompt_type = 'photo' " + "AND ubr.processed = false", new RowMapper<Image>() { /* * (non-Javadoc) * @see org.springframework.jdbc.core.RowMapper#mapRow(java.sql.ResultSet, int) */ @Override public Image mapRow(final ResultSet resultSet, final int rowNum) throws SQLException { try { return new Image(UUID.fromString(resultSet.getString("uuid")), resultSet.getURL("url")); } catch (DomainException e) { throw new SQLException("Could not create the Image " + "object.", e); } } }); } catch (org.springframework.dao.DataAccessException e) { throw new DataAccessException("SELECT url " + "FROM url_based_resource " + "WHERE processed = false", e); } }
From source file:repository.EventLogDAO.java
/** * Gets a list of events based on a Client ID, used for specific Client * and User profiles// ww w .j a v a 2 s . com * @param id * @return */ public List<EventLog> getEventsByClientID(int id) { return template.query( "SELECT EventID,ClientID,First_Name,Last_Name,UserID,Username,Interaction_Type,Interaction_Date FROM interactions WHERE ClientID = " + id, new RowMapper<EventLog>() { public EventLog mapRow(ResultSet rs, int row) throws SQLException { EventLog a = new EventLog(); a.setEventid(rs.getInt("EventID")); a.setClientid(rs.getInt("ClientID")); a.setClientFirstName(rs.getString("First_Name")); a.setClientLastName(rs.getString("Last_Name")); a.setUserid(rs.getInt("UserID")); a.setUsername(rs.getString("Username")); a.setInteraction(rs.getString("Interaction_Type")); a.setDate(rs.getString("Interaction_Date")); return a; } }); }
From source file:net.solarnetwork.node.dao.jdbc.JdbcSettingDao.java
@Override public List<KeyValuePair> getSettings(String key) { return getJdbcTemplate().query(this.sqlFind, new RowMapper<KeyValuePair>() { @Override//from w w w . j ava 2 s. c om public KeyValuePair mapRow(ResultSet rs, int rowNum) throws SQLException { return new KeyValuePair(rs.getString(1), rs.getString(2)); } }, key); }
From source file:org.ohmage.query.impl.UserImageQueries.java
@Override public Collection<URL> getImageUrlsFromUsername(String username) throws DataAccessException { try {//from www .j a v a2s . co m return getJdbcTemplate().query(SQL_GET_URLS_FOR_ALL_IMAGE_RESPONSES_FOR_USER, new Object[] { username }, new RowMapper<URL>() { /** * Converts the URL string to a URL object. */ @Override public URL mapRow(ResultSet rs, int rowNum) throws SQLException { try { return new URL(rs.getString("url")); } catch (MalformedURLException e) { throw new SQLException( "The URL in the database is malformed: " + rs.getString("url")); } } }); } catch (org.springframework.dao.DataAccessException e) { throw new DataAccessException("Error executing SQL '" + SQL_GET_URLS_FOR_ALL_IMAGE_RESPONSES_FOR_USER + "' with parameter: " + username, e); } }