List of usage examples for org.springframework.jdbc.core RowMapper RowMapper
RowMapper
From source file:com.sfs.whichdoctor.dao.ReceiptDAOImpl.java
/** * Used to get a ReceiptBean for a specified receiptId and supplied load * options. A boolean parameter identifies whether to use the default reader * connection or optional writer connection datasource. * * @param receiptId the receipt id/*from w w w .j ava2 s.c o m*/ * @param loadDetails the load details * @param useWriterConn the use writer conn * * @return the receipt bean * * @throws WhichDoctorDaoException the which doctor dao exception */ private ReceiptBean load(final int receiptId, final BuilderBean loadDetails, final boolean useWriterConn) throws WhichDoctorDaoException { ReceiptBean receipt = null; final String loadSQL = getSQL().getValue("receipt/load") + " AND receipt.ReceiptId = ? GROUP BY receipt.ReceiptId"; JdbcTemplate jdbcTemplate = this.getJdbcTemplateReader(); if (useWriterConn) { jdbcTemplate = this.getJdbcTemplateWriter(); } try { receipt = (ReceiptBean) jdbcTemplate.queryForObject(loadSQL, new Object[] { receiptId }, new RowMapper() { public Object mapRow(final ResultSet rs, final int rowNum) throws SQLException { return loadReceipt(rs, loadDetails); } }); } catch (IncorrectResultSizeDataAccessException ie) { dataLogger.debug("No results found for this search:" + ie.getMessage()); } return receipt; }
From source file:nl.surfnet.coin.teams.service.impl.TeamExternalGroupDaoImpl.java
@Override public List<TeamExternalGroup> getByExternalGroupIdentifier(String identifier) { Object[] args = { identifier }; try {/*from w w w . j a va 2 s.co m*/ String s = "SELECT teg.id AS teg_id, teg.grouper_team_id, eg.id AS eg_id, eg.identifier, eg.name, eg.description, eg.group_provider " + " FROM team_external_groups AS teg " + " INNER JOIN external_groups AS eg " + " ON teg.external_groups_id = eg.id " + " WHERE eg.identifier = ? "; return this.jdbcTemplate.query(s, args, new RowMapper<TeamExternalGroup>() { @Override public TeamExternalGroup mapRow(ResultSet rs, int rowNum) throws SQLException { return mapRowToTeamExternalGroup(rs); } }); } catch (EmptyResultDataAccessException er) { return new ArrayList<TeamExternalGroup>(); } }
From source file:com.ewcms.content.particular.dao.FrontEmployeArticleDAO.java
public List<EmployeArticle> findEmployeChannelArticleByPage(int channelId, int page, int row) { String sql = "Select * " + "From particular_employe_article " + "where channel_id=? and release=true " + "Order By published desc Limit ? OffSet ?"; int offset = page * row; Object[] params = new Object[] { channelId, row, offset }; List<EmployeArticle> list = jdbcTemplate.query(sql, params, new RowMapper<EmployeArticle>() { @Override//w ww . j a va2s . co m public EmployeArticle mapRow(ResultSet rs, int rowNum) throws SQLException { return interactionRowMapper(rs); } }); return list; }
From source file:net.algem.security.UserDaoImpl.java
@Override public List<User> findAll() { String query = "SELECT * FROM login"; return jdbcTemplate.query(query, new RowMapper<User>() { @Override/*from w w w .jav a 2s . co m*/ public User mapRow(ResultSet rs, int rowNum) throws SQLException { return getFromRS(rs); } }); }
From source file:org.zenoss.zep.dao.impl.EventDetailsConfigDaoImpl.java
@Override @TransactionalReadOnly/*from w w w. j a v a 2s . c o m*/ public EventDetailItem findByName(String eventDetailName) throws ZepException { final Map<String, String> fields = Collections.singletonMap(COLUMN_DETAIL_ITEM_NAME, eventDetailName); final String sql = "SELECT proto_json FROM event_detail_index_config WHERE detail_item_name=:detail_item_name"; final List<EventDetailItem> items = this.template.query(sql, new RowMapper<EventDetailItem>() { @Override public EventDetailItem mapRow(ResultSet rs, int rowNum) throws SQLException { return DaoUtils.protobufFromJson(rs.getString(COLUMN_PROTO_JSON), EventDetailItem.getDefaultInstance()); } }, fields); return (items.isEmpty()) ? null : items.get(0); }
From source file:com.ewcms.component.interaction.dao.InteractionDAO.java
@Override public Organ getOrgan(Integer id) { String sql = "Select id,name From site_organ Where id = ?"; List<Organ> list = jdbcTemplate.query(sql, new Object[] { id }, new RowMapper<Organ>() { @Override// w w w. jav a2 s . com public Organ mapRow(ResultSet rs, int rowNum) throws SQLException { return organRowMapper(rs); } }); return list.isEmpty() ? null : list.get(0); }
From source file:com.sfs.whichdoctor.dao.QualificationDAOImpl.java
/** * Load the qualification bean./*from w ww . jav a 2 s. co m*/ * * @param qualificationId the qualification id * @return the qualification bean * @throws WhichDoctorDaoException the which doctor dao exception */ public final QualificationBean load(final int qualificationId) throws WhichDoctorDaoException { dataLogger.info("Getting qualificationId:" + qualificationId); final String loadQualificationId = getSQL().getValue("qualification/load") + " WHERE qualification.QualificationId = ?"; QualificationBean qualification = null; try { qualification = (QualificationBean) this.getJdbcTemplateReader().queryForObject(loadQualificationId, new Object[] { qualificationId }, new RowMapper() { public Object mapRow(final ResultSet rs, final int rowNum) throws SQLException { return loadQualification(rs); } }); } catch (IncorrectResultSizeDataAccessException ie) { dataLogger.debug("No results found for this search: " + ie.getMessage()); } return qualification; }
From source file:com.bt.aloha.batchtest.PerformanceMeasurmentDao.java
@SuppressWarnings("unchecked") public List<Metrics> findMetricsByRunId(long runId) { if (!exists) { log.warn("record skipped as schema does not exists"); return null; }//from www . ja v a 2 s. co m List<Metrics> metrics = null; try { metrics = jdbcTemplate.query("select unitPerSecond, averageDuration," + "numberOfRuns, numberOfSuccessfulRuns, variance, standardDeviation, success, description, threadInfo, testType " + "from Performance where runId=?", new Object[] { runId }, new RowMapper() { public Object mapRow(ResultSet rs, int row) throws SQLException { double ups = rs.getDouble("unitPerSecond"); double ad = rs.getDouble("averageDuration"); long nor = rs.getLong("numberOfRuns"); long nosr = rs.getLong("numberOfSuccessfulRuns"); double v = rs.getDouble("variance"); double sd = rs.getDouble("standardDeviation"); boolean s = rs.getBoolean("success"); String d = rs.getString("description"); String ti = rs.getString("threadInfo"); String tt = rs.getString("testType"); Metrics m = new Metrics(tt, ups, ad, nor, nosr, v, sd, s, d); m.setThreadInfo(ti); return m; } }); } catch (DataAccessException e) { log.error("Unable to access data for runId: " + runId, e); } return metrics; }
From source file:org.sakuli.services.receiver.database.dao.impl.DaoTestCaseImpl.java
@Deprecated @Override// ww w .j a va 2 s . com public File getScreenShotFromDB(int dbPrimaryKey) { try { List l = getJdbcTemplate().query("select id, screenshot from sahi_cases where id=" + dbPrimaryKey, new RowMapper() { public Object mapRow(ResultSet rs, int i) throws SQLException { Map results = new HashMap(); InputStream blobBytes = lobHandler.getBlobAsBinaryStream(rs, "screenshot"); results.put("BLOB", blobBytes); return results; } }); HashMap<String, InputStream> map = (HashMap<String, InputStream>) l.get(0); //ByteArrayInputStream in = new ByteArrayInputStream(map.get("BLOB")); BufferedImage picBuffer = ImageIO.read(map.get("BLOB")); File png = new File(testSuite.getAbsolutePathOfTestSuiteFile().substring(0, testSuite.getAbsolutePathOfTestSuiteFile().lastIndexOf(File.separator)) + File.separator + "temp_junit_test.png"); png.createNewFile(); ImageIO.write(picBuffer, "png", png); png.deleteOnExit(); return png; } catch (IOException e) { throw new RuntimeException(e); } }
From source file:net.solarnetwork.node.dao.jdbc.consumption.JdbcConsumptionDatumDao.java
@Override @Transactional(readOnly = true, propagation = Propagation.REQUIRED) public List<ConsumptionDatum> getDatumNotUploaded(String destination) { return findDatumNotUploaded(new RowMapper<ConsumptionDatum>() { @Override//from w ww . j av a 2 s .co m public ConsumptionDatum mapRow(ResultSet rs, int rowNum) throws SQLException { if (log.isTraceEnabled()) { log.trace("Handling result row " + rowNum); } ConsumptionDatum datum = new ConsumptionDatum(); 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.setWattHourReading(val == null ? null : val.longValue()); return datum; } }); }