List of usage examples for org.springframework.jdbc.core RowMapper RowMapper
RowMapper
From source file:net.chrisrichardson.bankingExample.domain.jdbc.JdbcAccountDao.java
public Account findAccount(String accountId) { logger.debug("finding account"); return (Account) jdbcTemplate.queryForObject("SELECT * FROM BANK_ACCOUNT WHERE accountId = ?", new Object[] { accountId }, new RowMapper() { public Object mapRow(ResultSet rs, int rowNum) throws SQLException { return new Account(rs.getInt("ACCOUNT_ID"), rs.getString("accountId"), rs.getDouble("BALANCE"), rs.getInt("overdraftPolicy"), new Date(rs.getTimestamp("dateOpened").getTime()), rs.getDouble("requiredYearsOpen"), rs.getDouble("limit")); }/*ww w . ja va 2s.c om*/ }); }
From source file:org.openinfinity.core.spring.JdbcPropertyPlaceholderConfigurer.java
/** * Reads properties from the shared data source. * /* www .j av a 2 s . c o m*/ * @return Properties Returns properties fetched from the shared database. */ public Properties readPropertiesFromDataSource() { properties = new Properties(); jdbcTemplate.query(PROPERTIES_QUERY_SQL, new RowMapper<Properties>() { @Override public Properties mapRow(ResultSet resultSet, int rowNum) throws SQLException { String key = resultSet.getString("KEY_COLUMN"); String value = resultSet.getString("VALUE_COLUMN"); properties.setProperty(key, value); return properties; } }); return properties; }
From source file:com.abcd.employeemaven.dao.impl.EmployeeDaoImpl.java
@Override public Employee getById(int id) { return jdbcTemplate.queryForObject(EmployeeSQL.GETBYID, new Object[] { id }, new RowMapper<Employee>() { @Override/*from w w w. j av a 2s. com*/ public Employee mapRow(ResultSet rs, int i) throws SQLException { return mapData(rs); } }); }
From source file:CRM.repository.ClientsDAO.java
public List<clients> getClientsList() { return template.query("SELECT * FROM clients", new RowMapper<clients>() { @Override//from w w w .j a va 2s. com public clients mapRow(ResultSet rs, int row) throws SQLException { clients c = new clients(); c.setClient_id(rs.getInt("client_id")); c.setFirst_name(rs.getString("first_name")); c.setLast_name(rs.getString("last_name")); return c; } }); }
From source file:com.epam.repository.author.AuthorRepository.java
public Author findBySurname(final String surname) { return jdbcTemplate.queryForObject(FIND_AUTHORS_BY_SURNAME, new Object[] { surname }, new RowMapper<Author>() { public Author mapRow(ResultSet rs, int rowNum) throws SQLException { Author author = new Author(); author.setId(rs.getInt("ID")); author.setName(rs.getString("Name")); author.setSurname(surname); return author; }/*from ww w . j a va2s .c om*/ }); }
From source file:com.leapfrog.inventorymanagementsystem.dao.impl.SalesDAOImpl.java
@Override public Sales getById(int id) throws SQLException, ClassNotFoundException { String sql = "SELECT * FROM tbl_sales WHERE sales_id =?"; return jdbcTemplate.queryForObject(sql, new Object[] { id }, new RowMapper<Sales>() { @Override//w w w . j ava 2s .c o m public Sales mapRow(ResultSet rs, int i) throws SQLException { Sales s = new Sales(); s.setId(rs.getInt("sales_id")); s.setProductId(rs.getInt("product_id")); s.setSellingPrice(rs.getInt("selling_price")); s.setQuantity(rs.getInt("quantity")); s.setDiscount(rs.getBigDecimal("discount")); s.setTotalCost(rs.getInt("total_cost")); s.setSalesDate(rs.getDate("sales_date")); s.setPaymentMethod(rs.getString("payment_method")); s.setStatus(rs.getBoolean("status")); return s; } }); }
From source file:cz.dasnet.dasik.plugin.WordCounter.java
public String getTop10(Dasik bot, int from) { String sql = "SELECT * FROM users WHERE words > 0 ORDER BY words DESC LIMIT " + from + ", 10"; List<User> users = bot.getUserDao().query(sql, UserDaoImpl.userRowMapper); sql = "SELECT SUM(words) FROM users"; double sum = bot.getUserDao().query(sql, new RowMapper<Integer>() { public Integer mapRow(ResultSet rs, int rowNum) throws SQLException { return rs.getInt(1); }// www . j a va 2s . c om }).get(0); StringBuilder sb = new StringBuilder(); sb.append("Top spammers [").append(from + 1).append("-").append(from + users.size()).append("]: "); int i = from + 1; for (User u : users) { if (u.getWords() == 0) { break; } String nick = bot.maskToNick(u.getMask()); if (nick == null) { if (u.getMask().contains("users.quakenet.org")) { nick = u.getMask().split("@")[1].split("\\.", 2)[0]; } else { nick = u.getMask().split("@")[0]; } } sb.append(i).append(". ").append(nick).append("(").append(u.getWords()).append(" :: ") .append(String.format("%1.1f%%", u.getWords() * 100 / sum)).append(") "); i++; } return sb.toString(); }
From source file:com.gvmax.data.user.JDBCBasedUserDAO.java
@Override @Timed//from w w w . j a va 2 s . c o m @ExceptionMetered public List<User> getUsers(int offset, int limit) { return jdbcTemplate.query("select user from " + USER_TABLE + " LIMIT ?,?", new Object[] { offset, limit }, new RowMapper<User>() { @Override public User mapRow(ResultSet rs, int rowNum) throws SQLException { String userJson = rs.getString("user"); return toUser(userJson); } }); }
From source file:shell.framework.organization.authority.service.impl.TblSysAuthorityService4JdbcImpl.java
@Override public VOResult findByPagination(int currentPage, int pageSize, TblSysFunctionVO sysFunctionVO) { StringBuilder sql = new StringBuilder("select * from TBL_SYS_FUNCTION func where func.FUNCTION_TYPE<>'' "); if (sysFunctionVO != null) { //????/*from w w w .ja v a 2 s . c o m*/ if (sysFunctionVO.getFunctionName() != null && !"".equals(sysFunctionVO.getFunctionName())) { sql.append(" and func.FUNCTION_NAME like '%").append(sysFunctionVO.getFunctionName().trim()) .append("%'"); } //?? if (sysFunctionVO.getFunctionType() != null && !"".equals(sysFunctionVO.getFunctionType())) { sql.append(" and func.FUNCTION_TYPE ='").append(sysFunctionVO.getFunctionType()).append("'"); } //??URL if (sysFunctionVO.getFunctionURL() != null && !"".equals(sysFunctionVO.getFunctionURL())) { sql.append(" and func.FUNCTION_URL like '%").append(sysFunctionVO.getFunctionURL().trim()) .append("%'"); } sql.append(" order by func.ORDER_NO"); } return jdbcBaseDao.query(sql.toString(), new RowMapper<Object>() { @Override public Object mapRow(ResultSet rs, int rowNum) throws SQLException { TblSysAuthority authority = new TblSysAuthority(); Map<String, String> propertiesMap = new HashMap<String, String>(); propertiesMap.put("functionName", "FUNCTION_NAME"); propertiesMap.put("functionURL", "FUNCTION_URL"); propertiesMap.put("functionType", "FUNCTION_TYPE"); propertiesMap.put("parentID", "PARENT_FUN_ID"); propertiesMap.put("orderNO", "ORDER_NO"); PopulateUtil.populate(authority, rs, propertiesMap); return authority; } }, currentPage, pageSize); }