List of usage examples for org.springframework.jdbc.core RowMapper RowMapper
RowMapper
From source file:com.sfs.whichdoctor.dao.WhichDoctorDAOImpl.java
/** * Load.// w w w. ja v a2 s. co m * * @param guid the guid * @param type the type * * @return the collection< which doctor bean> * * @throws WhichDoctorDaoException the which doctor dao exception */ @SuppressWarnings("unchecked") public final Collection<WhichDoctorBean> load(final int guid, final String type) throws WhichDoctorDaoException { if (type == null) { throw new NullPointerException("The type parameter cannot be null"); } dataLogger.info("History of GUID: " + guid + " requested"); String loadSQL = getSQL().getValue("whichdoctor/load/person"); if (type.compareToIgnoreCase("organisation") == 0) { loadSQL = getSQL().getValue("whichdoctor/load/organisation"); } if (type.compareToIgnoreCase("debit") == 0) { loadSQL = getSQL().getValue("whichdoctor/load/debit"); } if (type.compareToIgnoreCase("credit") == 0) { loadSQL = getSQL().getValue("whichdoctor/load/credit"); } if (type.compareToIgnoreCase("receipt") == 0) { loadSQL = getSQL().getValue("whichdoctor/load/receipt"); } if (type.compareToIgnoreCase("reimbursement") == 0) { loadSQL = getSQL().getValue("whichdoctor/load/reimbursement"); } if (type.compareToIgnoreCase("rotation") == 0) { loadSQL = getSQL().getValue("whichdoctor/load/rotation"); } if (type.compareToIgnoreCase("group") == 0) { loadSQL = getSQL().getValue("whichdoctor/load/group"); } Collection<WhichDoctorBean> history = new ArrayList<WhichDoctorBean>(); try { history = this.getJdbcTemplateReader().query(loadSQL, new Object[] { guid }, new RowMapper() { public Object mapRow(final ResultSet rs, final int rowNum) throws SQLException { WhichDoctorBean loadedHistory = loadHistory(rs); loadedHistory.setObjectType(type); return loadedHistory; } }); } catch (IncorrectResultSizeDataAccessException ie) { dataLogger.debug("No results found for this search: " + ie.getMessage()); } return history; }
From source file:edu.uca.aca2016.impulse.repository.UsersDAO.java
/** *List<Users> getUsersByPage method and SQL Query * @param start//from w w w. j ava2 s.c o m * @param total * @return */ public List<Users> getUsersByPage(int start, int total) { String sql = "SELECT * FROM users LIMIT " + (start - 1) + "," + total; return template.query(sql, new RowMapper<Users>() { public Users mapRow(ResultSet rs, int row) throws SQLException { Users u = new Users(); u.setUsername(rs.getString(1)); u.setPassword(rs.getString(2)); u.setEnabled(rs.getInt(3)); u.setName(rs.getString(4)); return u; } }); }
From source file:ru.org.linux.user.MemoriesDao.java
public MemoriesListItem getMemoriesListItem(int id) { List<MemoriesListItem> res = jdbcTemplate.query("SELECT * FROM memories WHERE id=?", new RowMapper<MemoriesListItem>() { @Override/* ww w . j ava 2 s. co m*/ public MemoriesListItem mapRow(ResultSet rs, int rowNum) throws SQLException { return new MemoriesListItem(rs); } }, id); if (res.isEmpty()) { return null; } else { return res.get(0); } }
From source file:org.lexevs.tree.dao.JdbcLexEvsTreeDao.java
@Transactional public LexEvsTreeNode getNode(String codingScheme, CodingSchemeVersionOrTag versionOrTag, String code, String namespace) {/* w w w . j ava 2 s. co m*/ setDataSource(); String[] arguments = null; if (namespace != null) { arguments = new String[] { code, namespace }; } else { arguments = new String[] { code }; } try { List<LexEvsTreeNode> nodes = this.getJdbcTemplate().query( getNodeSqlBuilder.buildSql(codingScheme, versionOrTag, code, namespace), arguments, new RowMapper() { public Object mapRow(ResultSet rs, int rowNum) throws SQLException { LexEvsTreeNode node = new LexEvsTreeNode(); node.setCode(rs.getString("entityCode")); node.setEntityDescription(rs.getString("description")); node.setNamespace(rs.getString("entityCodeNamespace")); return node; } }); for (LexEvsTreeNode node : nodes) { if (node != null && node.getNamespace().equals(namespace)) { return node; } } return null; } catch (EmptyResultDataAccessException e) { try { if (!ServiceUtility.isSupplement(codingScheme, versionOrTag)) { throw e; } else { AbsoluteCodingSchemeVersionReference parent = ServiceUtility.getParentOfSupplement(codingScheme, versionOrTag); return this.getNode(parent.getCodingSchemeURN(), Constructors.createCodingSchemeVersionOrTagFromVersion(parent.getCodingSchemeVersion()), code, namespace); } } catch (LBParameterException e2) { throw e; } } }
From source file:net.solarnetwork.node.dao.jdbc.power.JdbcPowerDatumDao.java
@Override @Transactional(readOnly = true, propagation = Propagation.REQUIRED) public List<PowerDatum> getDatumNotUploaded(String destination) { return findDatumNotUploaded(new RowMapper<PowerDatum>() { @Override/*from w w w . j a v a 2 s . co m*/ public PowerDatum mapRow(ResultSet rs, int rowNum) throws SQLException { if (log.isTraceEnabled()) { log.trace("Handling result row " + rowNum); } PowerDatum datum = new PowerDatum(); int col = 1; datum.setCreated(rs.getTimestamp(col++)); datum.setSourceId(rs.getString(col++)); Number val = (Number) rs.getObject(col++); datum.setLocationId(val == null ? null : val.longValue()); val = (Number) rs.getObject(col++); datum.setWatts(val == null ? null : val.intValue()); val = (Number) rs.getObject(col++); datum.setBatteryVolts(val == null ? null : val.floatValue()); val = (Number) rs.getObject(col++); datum.setBatteryAmpHours(val == null ? null : val.doubleValue()); val = (Number) rs.getObject(col++); datum.setDcOutputVolts(val == null ? null : val.floatValue()); val = (Number) rs.getObject(col++); datum.setDcOutputAmps(val == null ? null : val.floatValue()); val = (Number) rs.getObject(col++); datum.setAcOutputVolts(val == null ? null : val.floatValue()); val = (Number) rs.getObject(col++); datum.setAcOutputAmps(val == null ? null : val.floatValue()); val = (Number) rs.getObject(col++); datum.setWattHourReading(val == null ? null : val.longValue()); val = (Number) rs.getObject(col++); datum.setAmpHourReading(val == null ? null : val.doubleValue()); return datum; } }); }
From source file:com.xinferin.dao.DAOCustomerImpl.java
@Override public List<Customer> list() { String sql = "SELECT * FROM customer"; List<Customer> list = jdbcTemplate.query(sql, new RowMapper<Customer>() { @Override//from ww w. ja v a 2 s . c o m public Customer mapRow(ResultSet rs, int rowNum) throws SQLException { Customer aCustomer = new Customer(); aCustomer.setId(rs.getInt("id")); aCustomer.setFname(rs.getString("fname")); aCustomer.setLname(rs.getString("lname")); aCustomer.setCompany(rs.getString("company")); aCustomer.setStreet(rs.getString("street")); aCustomer.setCity(rs.getString("city")); aCustomer.setState(rs.getString("state")); aCustomer.setCountry(rs.getString("country")); aCustomer.setPostcode(rs.getString("postcode")); aCustomer.setTelephone(rs.getString("telephone")); aCustomer.setEmail(rs.getString("email")); aCustomer.setComments(rs.getString("comments")); aCustomer.setDateAdded(rs.getDate("date_added")); return aCustomer; } }); return list; }
From source file:model.DbTable.java
@Override public List<customer> getCustomer() { List<customer> list = new ArrayList<customer>(); list = jdbcTemplateObject.query("SELECT * FROM `customer`", new RowMapper<customer>() { @Override/*from w w w . ja va2s. co m*/ public customer mapRow(ResultSet rs, int rowNum) throws SQLException { customer c = new customer(); c.setId(rs.getInt("id")); c.setCustomer_name(rs.getString("customer_name")); c.setCustomer_address(rs.getString("customer_address")); System.out.print("run list "); return c; } }); return list; }
From source file:edu.uca.aca2016.impulse.repository.ClientDAO.java
/** *getClientsByPage method and SQL Query// w ww .jav a 2 s . c o m * @param start * @param total * @return */ public List<Client> getClientsByPage(int start, int total) { String sql = "SELECT * FROM client LIMIT " + (start - 1) + "," + total; return template.query(sql, new RowMapper<Client>() { public Client mapRow(ResultSet rs, int row) throws SQLException { Client c = new Client(); c.setClientid(rs.getInt(1)); c.setFirstName(rs.getString(2)); c.setLastName(rs.getString(3)); c.setAddress1(rs.getString(4)); c.setAddress2(rs.getString(5)); c.setCity(rs.getString(6)); c.setState(rs.getString(7)); c.setZip(rs.getString(8)); c.setEmail(rs.getString(9)); c.setPhone(rs.getString(10)); c.setStatus(rs.getString(11)); return c; } }); }
From source file:net.solarnetwork.node.dao.jdbc.general.JdbcGeneralNodeDatumDao.java
@Override @Transactional(readOnly = true, propagation = Propagation.REQUIRED) public List<GeneralNodeDatum> getDatumNotUploaded(String destination) { return findDatumNotUploaded(new RowMapper<GeneralNodeDatum>() { @Override// w ww.j av a 2 s. c o m public GeneralNodeDatum mapRow(ResultSet rs, int rowNum) throws SQLException { if (log.isTraceEnabled()) { log.trace("Handling result row " + rowNum); } GeneralNodeDatum datum = new GeneralNodeDatum(); int col = 0; datum.setCreated(rs.getTimestamp(++col)); datum.setSourceId(rs.getString(++col)); String jdata = rs.getString(++col); if (jdata != null) { GeneralNodeDatumSamples s; try { s = objectMapper.readValue(jdata, GeneralNodeDatumSamples.class); datum.setSamples(s); } catch (IOException e) { log.error("Error deserializing JSON into GeneralNodeDatumSamples: {}", e.getMessage()); } } return datum; } }); }
From source file:com.ewcms.component.comment.dao.CommentDAO.java
private List<Reply> findReply(final Long commentId) { String sql = "Select * From component_comment_reply Where comment_id = ?"; Object[] params = { commentId }; return jdbcTemplate.query(sql, params, new RowMapper<Reply>() { @Override/*w ww. j ava2s.com*/ public Reply mapRow(ResultSet rs, int rowNum) throws SQLException { Reply reply = new Reply(); reply.setId(rs.getLong("id")); reply.setCommentId(commentId); reply.setIp(rs.getString("ip")); reply.setUsername(rs.getString("username")); reply.setDate(rs.getTimestamp("date")); return reply; } }); }