List of usage examples for org.springframework.jdbc.core RowMapper RowMapper
RowMapper
From source file:com.gvmax.data.user.JDBCBasedUserDAO.java
@Override @Timed/*from ww w .j a va 2 s. c o m*/ @ExceptionMetered public GlobalStats getStats() { try { GlobalStats stats = jdbcTemplate.queryForObject( "select " + "count(email) as statsCount," + "sum(smsInCount) as smsInCount," + "sum(smsOutCount) as smsOutCount," + "sum(vmInCount) as vmInCount," + "sum(mcInCount) as mcInCount," + "sum(emailInCount) as emailInCount," + "sum(gTalkCount) as gTalkCount," + "sum(apiCount) as apiCount," + "sum(errorCount) as errorCount," + "sum(invalidEmailCount) as invalidEmailCount," + "sum(fallbackCount) as fallbackCount " + "from " + STATS_TABLE, new RowMapper<GlobalStats>() { @Override public GlobalStats mapRow(ResultSet rs, int row) throws SQLException { GlobalStats stats = new GlobalStats(); stats.setTimestamp(System.currentTimeMillis()); stats.setStatsCount(rs.getInt("statsCount")); stats.setSmsInCount(rs.getInt("smsInCount")); stats.setSmsOutCount(rs.getInt("smsOutCount")); stats.setVmInCount(rs.getInt("vmInCount")); stats.setMcInCount(rs.getInt("mcInCount")); stats.setEmailInCount(rs.getInt("emailInCount")); stats.setgTalkCount(rs.getInt("gTalkCount")); stats.setApiCount(rs.getInt("apiCount")); stats.setErrorCount(rs.getInt("errorCount")); stats.setInvalidEmailCount(rs.getInt("invalidEmailCount")); stats.setFallbackCount(rs.getInt("fallbackCount")); return stats; } }); // TODO: Review deprecated use int userCount = jdbcTemplate.queryForInt("select count(email) from " + USER_TABLE); stats.setUserCount(userCount); return stats; } catch (EmptyResultDataAccessException e) { return null; } }
From source file:net.algem.security.UserDaoImpl.java
@Override public List<User> exist(int id, String login) { String query = "SELECT idper,login FROM " + TABLE + " WHERE idper = ? OR login = ?"; return jdbcTemplate.query(query, new RowMapper<User>() { @Override/*from w w w . j a va2s.c o m*/ public User mapRow(ResultSet rs, int rowNum) throws SQLException { User u = new User(); u.setId(rs.getInt(1)); u.setLogin(getLoginFromStringResult(rs.getString(2))); return u; } }, id, login); }
From source file:com.sfs.whichdoctor.dao.AddressVerificationDAOImpl.java
/** * Load a collection of address verification beans that are pending verification * which are associated with the supplied address guid. * * @param guid the guid/*w ww . j a v a2s . c o m*/ * @return the address verification beans * @throws WhichDoctorDaoException the which doctor dao exception */ @SuppressWarnings("unchecked") public final Collection<AddressVerificationBean> loadPendingForGUID(final int guid) throws WhichDoctorDaoException { Collection<AddressVerificationBean> addressVerifications = new ArrayList<AddressVerificationBean>(); String loadGUID = this.getSQL().getValue("addressVerification/loadGUID") + " AND processstatus.Class = ?"; try { addressVerifications = this.getJdbcTemplateReader().query(loadGUID, new Object[] { guid, PENDING }, new RowMapper() { public Object mapRow(final ResultSet rs, final int rowNum) throws SQLException { return loadAddressVerification(rs); } }); } catch (IncorrectResultSizeDataAccessException ie) { dataLogger.debug( "Could not find an address verification record for GUID (" + guid + "): " + ie.getMessage()); } return addressVerifications; }
From source file:om.edu.squ.squportal.portlet.dps.dao.db.DpsDbImpl.java
/** * // w w w.jav a2 s . co m * method name : getStudentPersonalDetail * @param studentId * @param locale * @return * @throws NoDBRecordException * DpsDbImpl * return type : PersonalDetail * * purpose : * * Date : Jan 9, 2017 11:21:56 AM */ public PersonalDetail getStudentPersonalDetail(String studentId, String studentNo, Locale locale) throws NoDBRecordException { String SQL_PERSONAL_DETAIL_STUDENT = queryProps.getProperty(Constants.SQL_PERSONAL_DETAIL_STUDENT); RowMapper<PersonalDetail> mapper = new RowMapper<PersonalDetail>() { public PersonalDetail mapRow(ResultSet rs, int rowNum) throws SQLException { PersonalDetail personalDetail = new PersonalDetail(); personalDetail.setId(rs.getString(Constants.CONST_COLMN_STUDENT_ID)); personalDetail.setName(rs.getString(Constants.CONST_COLMN_STUDENT_NAME)); personalDetail.setPhone(rs.getString(Constants.CONST_COLMN_STUDENT_PHONE)); personalDetail.setEmail(rs.getString(Constants.CONST_COLMN_STUDENT_EMAIL)); personalDetail.setRegion(rs.getString(Constants.CONST_COLMN_STUDENT_HOME_REGION)); personalDetail.setWillayat(rs.getString(Constants.CONST_COLMN_STUDENT_HOME_WILAYAT)); personalDetail.setTown(rs.getString(Constants.CONST_COLMN_STUDENT_TOWN_VILLAGE)); personalDetail.setPoBox(rs.getString(Constants.CONST_COLMN_STUDENT_HOME_POBOX)); personalDetail.setPostalCode(rs.getString(Constants.CONST_COLMN_STUDENT_HOME_POSTALCD)); return personalDetail; } }; Map<String, String> namedParameterMap = new HashMap<String, String>(); namedParameterMap.put("paramLocale", locale.getLanguage()); namedParameterMap.put("paramStudentId", studentId); namedParameterMap.put("paramStudentNo", studentNo); try { return nPJdbcTemplDps.queryForObject(SQL_PERSONAL_DETAIL_STUDENT, namedParameterMap, mapper); } catch (EmptyResultDataAccessException ex) { throw new NoDBRecordException(ex.getMessage()); } }
From source file:com.bt.aloha.batchtest.PerformanceMeasurmentDao.java
@SuppressWarnings("unchecked") public List<Long[]> getNumberOfApplicationThreadsFromDescription(long runId) { List<Long[]> data = jdbcTemplate.query( "select id, description " + "from Performance where runId=? order by id", new Object[] { runId }, new RowMapper() { public Object mapRow(ResultSet rs, int row) throws SQLException { long id = rs.getInt("id"); String tt = rs.getString("description"); final String what = "number of application threads: "; int pos = tt.indexOf(what) + what.length(); String num = tt.substring(pos).trim(); Long ret = Long.parseLong(num); return new Long[] { id, ret }; }/*from w w w.j a v a 2 s . c om*/ }); return data; }
From source file:com.sfs.whichdoctor.dao.VoteDAOImpl.java
/** * Loads an array of groups based on the submitted voteNumber and year. * * @param voteNumber the vote number/* w ww. j a v a2 s . c o m*/ * @param year the year * * @return the collection< group bean> * * @throws WhichDoctorDaoException the which doctor dao exception */ @SuppressWarnings("unchecked") public final Collection<GroupBean> findElections(final int voteNumber, final int year) throws WhichDoctorDaoException { if (year == 0) { throw new WhichDoctorDaoException("Sorry a valid year is required"); } Collection<GroupBean> elections = new ArrayList<GroupBean>(); dataLogger.info("Loading elections for: " + voteNumber + "/" + year); /* Identify the referenceGUID from the vote number and year */ int referenceGUID = PersonBean.getVoterGUID(voteNumber, year); TreeMap<Integer, Integer> electionList = new TreeMap<Integer, Integer>(); try { Collection<Integer> guids = this.getJdbcTemplateReader().query( this.getSQL().getValue("vote/findPossibleElections"), new Object[] { year, referenceGUID }, new RowMapper() { public Object mapRow(final ResultSet rs, final int rowNum) throws SQLException { return rs.getInt("GUID"); } }); for (Integer guid : guids) { electionList.put(guid, guid); } } catch (IncorrectResultSizeDataAccessException ie) { dataLogger.debug("No results found for this search: " + ie.getMessage()); } try { Collection<Integer> guids = this.getJdbcTemplateReader().query( this.getSQL().getValue("vote/findVotedElections"), new Object[] { year, referenceGUID }, new RowMapper() { public Object mapRow(final ResultSet rs, final int rowNum) throws SQLException { return rs.getInt("GUID"); } }); for (Integer guid : guids) { if (electionList.containsKey(guid)) { // This election has been voted for already, remove it from the list electionList.remove(guid); } } } catch (IncorrectResultSizeDataAccessException ie) { dataLogger.debug("No results found for this search: " + ie.getMessage()); } if (electionList.size() > 0) { // An unvoted election exists in the map, perform a group search to load it Collection<Object> guidCollection = new ArrayList<Object>(); for (Integer groupGUID : electionList.keySet()) { guidCollection.add(groupGUID); } try { SearchBean search = this.searchDAO.initiate("group", null); search.setLimit(0); search.setOrderColumn("groups.Weighting"); search.setOrderColumn2("groups.Name"); search.setSearchArray(guidCollection, "Unvoted list of elections"); BuilderBean loadDetails = new BuilderBean(); loadDetails.setParameter("CANDIDATES", true); SearchResultsBean results = this.searchDAO.search(search, loadDetails); if (results != null) { // Add each group to the election array for (Object result : results.getSearchResults()) { GroupBean election = (GroupBean) result; elections.add(election); } } } catch (Exception e) { dataLogger.error("Error performing election search: " + e.getMessage()); throw new WhichDoctorDaoException("Error performing election search: " + e.getMessage()); } } return elections; }
From source file:com.ewcms.component.interaction.dao.InteractionDAO.java
@Override public List<Interaction> findInteractionByUsername(String username, int page, int row) { String sql = "Select * " + "From plugin_interaction " + "Where username = ? " + "Order By date desc Limit ? OffSet ?"; int offset = page * row; Object[] params = new Object[] { username, row, offset }; List<Interaction> list = jdbcTemplate.query(sql, params, new RowMapper<Interaction>() { @Override//from ww w. j av a 2 s.c o m public Interaction mapRow(ResultSet rs, int rowNum) throws SQLException { return interactionRowMapper(rs); } }); return list; }
From source file:com.havoc.hotel.admin.dao.impl.BookingDAOImpl.java
@Override public List<Booking> getByUser(String username) throws SQLException { return jdbcTemplate.query(SQLConstant.BOOKING_GETBYUSER, new Object[] { username }, new RowMapper<Booking>() { @Override/*from w w w.j a va2 s . co m*/ public Booking mapRow(ResultSet rs, int i) throws SQLException { return mapData(rs); } }); }
From source file:com.sfs.whichdoctor.dao.OnlineToolDAOImpl.java
/** * Loads all of the online tool beans.// w w w . jav a2s.co m * * @return the collection< online tool bean> * * @throws WhichDoctorDaoException the which doctor dao exception */ @SuppressWarnings("unchecked") public final Collection<OnlineToolBean> loadAll() throws WhichDoctorDaoException { Collection<OnlineToolBean> onlineTools = new ArrayList<OnlineToolBean>(); try { onlineTools = this.getJdbcTemplateReader().query(this.getSQL().getValue("onlineTool/loadAll"), new RowMapper() { public Object mapRow(final ResultSet rs, final int rowNum) throws SQLException { return loadOnlineTool(rs); } }); } catch (IncorrectResultSizeDataAccessException ie) { dataLogger.debug("No results found for this search: " + ie.getMessage()); } return onlineTools; }
From source file:com.sfs.whichdoctor.dao.RelationshipDAOImpl.java
/** * Used to get a Collection of RelationshipBeans for a specified objecttype. * * @param objectType the ObjectTypeBean to load * @param loadDetails the load details/*from w w w . j a v a2s.co m*/ * @return the collection< relationship bean> * * @throws WhichDoctorDaoException the which doctor dao exception */ @SuppressWarnings("unchecked") public final Collection<RelationshipBean> load(final ObjectTypeBean objectType, final BuilderBean loadDetails) throws WhichDoctorDaoException { dataLogger.info("Relationships for objectType: " + objectType.getObjectTypeId()); final String loadRelationships = this.getSQL().getValue("relationship/load") + " AND relationships.RelationshipTypeId = ?"; Collection<RelationshipBean> relationships = new ArrayList<RelationshipBean>(); try { relationships = this.getJdbcTemplateReader().query(loadRelationships, new Object[] { true, objectType.getObjectTypeId() }, new RowMapper() { public Object mapRow(final ResultSet rs, final int rowNum) throws SQLException { return loadRelationship(rs, loadDetails); } }); } catch (IncorrectResultSizeDataAccessException ie) { dataLogger.debug("No results found for search: " + ie.getMessage()); } return relationships; }