List of usage examples for org.springframework.jdbc.core RowMapper RowMapper
RowMapper
From source file:eionet.meta.dao.mysql.VocabularyFolderDAOImpl.java
/** * {@inheritDoc}/*from w w w. ja v a 2s . co m*/ */ @Override public List<VocabularyFolder> getVocabularyFolders(String userName) { Map<String, Object> params = new HashMap<String, Object>(); StringBuilder sql = new StringBuilder(); sql.append( "select v.VOCABULARY_ID, v.IDENTIFIER, v.LABEL, v.REG_STATUS, v.WORKING_COPY, v.BASE_URI, v.VOCABULARY_TYPE, "); sql.append("v.WORKING_USER, v.DATE_MODIFIED, v.USER_MODIFIED, v.CHECKEDOUT_COPY_ID, v.CONTINUITY_ID, "); sql.append("v.CONCEPT_IDENTIFIER_NUMERIC, "); sql.append("f.ID, f.IDENTIFIER, f.LABEL, v.NOTATIONS_EQUAL_IDENTIFIERS "); sql.append("from VOCABULARY v "); sql.append("left join VOCABULARY_SET f on f.ID=v.FOLDER_ID "); sql.append("where "); if (StringUtils.isBlank(userName)) { sql.append("v.WORKING_COPY=FALSE "); } else { sql.append("(v.WORKING_COPY=FALSE or v.WORKING_USER=:workingUser) "); params.put("workingUser", userName); } sql.append("order by f.IDENTIFIER, v.IDENTIFIER "); List<VocabularyFolder> items = getNamedParameterJdbcTemplate().query(sql.toString(), params, new RowMapper<VocabularyFolder>() { @Override public VocabularyFolder mapRow(ResultSet rs, int rowNum) throws SQLException { VocabularyFolder vf = new VocabularyFolder(); vf.setId(rs.getInt("v.VOCABULARY_ID")); vf.setIdentifier(rs.getString("v.IDENTIFIER")); vf.setLabel(rs.getString("v.LABEL")); vf.setRegStatus(RegStatus.fromString(rs.getString("v.REG_STATUS"))); vf.setType(VocabularyType.valueOf(rs.getString("v.VOCABULARY_TYPE"))); vf.setWorkingCopy(rs.getBoolean("v.WORKING_COPY")); vf.setWorkingUser(rs.getString("v.WORKING_USER")); vf.setDateModified(rs.getTimestamp("v.DATE_MODIFIED")); vf.setUserModified(rs.getString("v.USER_MODIFIED")); vf.setCheckedOutCopyId(rs.getInt("v.CHECKEDOUT_COPY_ID")); vf.setContinuityId(rs.getString("v.CONTINUITY_ID")); vf.setNumericConceptIdentifiers(rs.getBoolean("v.CONCEPT_IDENTIFIER_NUMERIC")); vf.setNotationsEqualIdentifiers(rs.getBoolean("NOTATIONS_EQUAL_IDENTIFIERS")); vf.setBaseUri(rs.getString("v.BASE_URI")); vf.setFolderId(rs.getShort("f.ID")); vf.setFolderName(rs.getString("f.IDENTIFIER")); vf.setFolderLabel(rs.getString("f.LABEL")); return vf; } }); return items; }
From source file:repository.EventLogDAO.java
/** * Gets a list of events based on a User ID, used for specific Client * and User profiles//from ww w. j av a 2s . co m * @param id * @return */ public List<EventLog> getEventsByUserID(int id) { return template.query( "SELECT EventID,ClientID,First_Name,Last_Name,UserID,Username,Interaction_Type,Interaction_Date FROM interactions WHERE UserID = " + 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:com.havoc.hotel.admin.dao.impl.CustomerDAOImpl.java
@Override public List<Customer> getLast() throws SQLException { return jdbcTemplate.query(SQLConstant.CUSTOMER_GETLAST, new RowMapper<Customer>() { @Override/*from ww w. j a v a 2s .co m*/ public Customer mapRow(ResultSet rs, int i) throws SQLException { return mapData(rs); } }); }
From source file:ru.org.linux.spring.SameIPController.java
private List<UserItem> getUsers(String ip, final int uaId) { return jdbcTemplate.query( "SELECT MAX(c.postdate) AS lastdate, u.nick, c.ua_id, ua.name AS user_agent " + "FROM comments c LEFT JOIN user_agents ua ON c.ua_id = ua.id " + "JOIN users u ON c.userid = u.id " + "WHERE c.postip=?::inet " + "GROUP BY u.nick, c.ua_id, ua.name " + "ORDER BY MAX(c.postdate) DESC, u.nick, ua.name", new RowMapper<UserItem>() { @Override//from www. j av a2s . c om public UserItem mapRow(ResultSet rs, int rowNum) throws SQLException { return new UserItem(rs, uaId); } }, ip); }
From source file:org.ohmage.cache.KeyValueCache.java
/** * Reads the database for the information in the lookup table and populates * its map with the gathered information. If there is an issue reading the * database, it will just remain with the current lookup table it has. * /*ww w. j a va 2 s . com*/ * @complexity O(n) where n is the number of keys in the database. */ protected synchronized void refreshMap() { // Only one thread should be updating this information at a time. Once // other threads enter, they should check to see if an update was just // done and, if so, should abort a second update. if ((getLastUpdateTimestamp() + getUpdateFrequency()) > System.currentTimeMillis()) { return; } // This is the JdbcTemplate we will use for our query. If there is an // issue report it and abort the update. JdbcTemplate jdbcTemplate = new JdbcTemplate(getDataSource()); // Get all the keys and their corresponding values. List<KeyAndValue> keyAndValue; try { keyAndValue = jdbcTemplate.query(sqlForRetrievingValues, new RowMapper<KeyAndValue>() { @Override public KeyAndValue mapRow(ResultSet rs, int row) throws SQLException { return new KeyAndValue(rs.getString(keyColumn), rs.getString(valueColumn)); } }); } catch (org.springframework.dao.DataAccessException e) { LOGGER.error("Error executing SQL '" + sqlForRetrievingValues + "'. Aborting cache refresh.", e); return; } // Create a new Map, populate it, and replace the old one. This allows // for concurrent readying while the new Map is being created. Map<String, String> keyValueMap = new HashMap<String, String>(); for (KeyAndValue currStateAndId : keyAndValue) { keyValueMap.put(currStateAndId.key, currStateAndId.value); } this.keyValueMap = keyValueMap; setLastUpdateTimestamp(System.currentTimeMillis()); }
From source file:act.reports.dao.AbandonedVehicleDAO.java
public List<AccountNames> getAccountNames() { logger.info("In getAccountNames()..."); String accountNamesQry = "select name from Account"; List<AccountNames> accountNamesList = null; try {//www . j av a 2 s. c om accountNamesList = jdbcTemplate.query(accountNamesQry, new Object[] {}, new RowMapper<AccountNames>() { public AccountNames mapRow(ResultSet rs, int rowNum) throws SQLException { AccountNames accountNames = new AccountNames(); accountNames.setAccountName(rs.getString("name") != null ? rs.getString("name") : ""); return accountNames; } }); } catch (Exception e) { logger.error(e); } logger.info("accountNamesList.size() : " + accountNamesList.size()); return accountNamesList; }
From source file:com.netflix.simianarmy.aws.RDSRecorder.java
/** {@inheritDoc} */ @Override/*from w ww.j av a2s .c o m*/ public List<Event> findEvents(MonkeyType monkeyType, EventType eventType, Map<String, String> query, Date after) { ArrayList<Object> args = new ArrayList<>(); StringBuilder sqlquery = new StringBuilder(String.format("select * from %s where region = ?", table)); args.add(region); if (monkeyType != null) { sqlquery.append(String.format(" and %s = ?", FIELD_MONKEY_TYPE)); args.add(SimpleDBRecorder.enumToValue(monkeyType)); } if (eventType != null) { sqlquery.append(String.format(" and %s = ?", FIELD_EVENT_TYPE)); args.add(SimpleDBRecorder.enumToValue(eventType)); } for (Map.Entry<String, String> pair : query.entrySet()) { sqlquery.append(String.format(" and %s like ?", FIELD_DATA_JSON)); args.add((String.format("%s: \"%s\"", pair.getKey(), pair.getValue()))); } sqlquery.append(String.format(" and %s > ? order by %s desc", FIELD_EVENT_TIME, FIELD_EVENT_TIME)); args.add(new Long(after.getTime())); LOGGER.debug(String.format("Query is '%s'", sqlquery)); List<Event> events = jdbcTemplate.query(sqlquery.toString(), args.toArray(), new RowMapper<Event>() { public Event mapRow(ResultSet rs, int rowNum) throws SQLException { return mapEvent(rs); } }); return events; }
From source file:org.pegadi.server.sources.SourceServerImpl.java
public List<Category> getSourceCategories() { return template.query("SELECT ID,name from Source_Category ORDER BY name", new RowMapper<Category>() { @Override// w w w .j a v a2 s. co m public Category mapRow(ResultSet rs, int rowNum) throws SQLException { return getCategoryFromResultSet(rs); } }); }
From source file:com.hs.mail.imap.dao.MySqlMessageDao.java
public PhysMessage getDanglingMessageID(long messageID) { String sql = "SELECT m.physmessageid, p.internaldate FROM message m, physmessage p WHERE m.physmessageid = (SELECT physmessageid FROM message WHERE messageid = ?) AND p.id=m.physmessageid GROUP BY m.physmessageid HAVING COUNT(m.physmessageid) = 1"; return (PhysMessage) queryForObject(sql, new Object[] { new Long(messageID) }, new RowMapper() { public Object mapRow(ResultSet rs, int rowNum) throws SQLException { PhysMessage pm = new PhysMessage(); pm.setPhysMessageID(rs.getLong("physmessageid")); pm.setInternalDate(new Date(rs.getTimestamp("internaldate").getTime())); return pm; }//w w w . j a v a 2 s .co m }); }
From source file:com.sfs.whichdoctor.analysis.RevenueAnalysisDAOImpl.java
/** * Stream analysis./*from w ww . j ava 2 s . co m*/ * * @param search the search * * @return the revenue analysis bean * * @throws WhichDoctorAnalysisDaoException the which doctor analysis dao * exception */ @SuppressWarnings("unchecked") public final RevenueAnalysisBean streamAnalysis(final RevenueAnalysisBean search) throws WhichDoctorAnalysisDaoException { /* Zero out values in revenueanalysis bean */ search.setValue(0); search.setNetValue(0); /* Set ordering system of returned results */ String sqlORDER = " ORDER BY RevenueType, receipt.ReceiptNo"; final StringBuffer sqlWHERE = new StringBuffer(); Collection<Object> parameters = new ArrayList<Object>(); if (search.getSQLWhereStatement() != null) { if (search.getSQLWhereStatement().compareTo("") != 0) { sqlWHERE.append(" AND "); sqlWHERE.append(search.getSQLWhereStatement()); } } if (search.getSearchParameters() != null) { parameters = search.getSearchParameters(); } // BUILD SQL Statement final StringBuffer searchSQL = new StringBuffer(); searchSQL.append(this.getSQL().getValue("revenue")); searchSQL.append(sqlWHERE.toString()); searchSQL.append(" GROUP BY payment.PaymentId, RevenueType "); searchSQL.append(sqlORDER); dataLogger.info("SQL Query: " + searchSQL.toString()); Collection<RevenueBean> results = new ArrayList<RevenueBean>(); try { results = this.getJdbcTemplateReader().query(searchSQL.toString(), parameters.toArray(), new RowMapper() { public Object mapRow(final ResultSet rs, final int rowNum) throws SQLException { return loadStreamRevenue(rs); } }); } catch (IncorrectResultSizeDataAccessException ie) { // No results found for this search dataLogger.debug("No results found for search: " + ie.getMessage()); } TreeMap<Object, ArrayList<RevenueBean>> revenueTypeMap = new TreeMap<Object, ArrayList<RevenueBean>>(); for (RevenueBean revenue : results) { if (dataLogger.isDebugEnabled()) { dataLogger.debug("Net value: " + revenue.getNetValue()); dataLogger.debug("Value: " + revenue.getValue()); } ArrayList<RevenueBean> revenueList = new ArrayList<RevenueBean>(); if (revenueTypeMap.containsKey(revenue.getRevenueType())) { revenueList = revenueTypeMap.get(revenue.getRevenueType()); } revenueList.add(revenue); revenueTypeMap.put(revenue.getRevenueType(), revenueList); } final RevenueAnalysisBean summary = consolidateSummary(revenueTypeMap); search.setValue(summary.getValue()); search.setNetValue(summary.getNetValue()); search.setGSTValues(summary.getGSTValues()); search.setRevenue(summary.getRevenue()); return search; }