List of usage examples for org.springframework.jdbc.core RowMapper RowMapper
RowMapper
From source file:com.javacodegags.waterflooding.model.CriteriaImplemented.java
@Override public List<Criteria> getAll() { String sql = "SELECT criteria.id, criteria.criteria_value,criteria.weight_factor, criteria.formula, caption.argument " + " FROM intermediate " + " INNER JOIN caption " + " ON intermediate.foreign_to_caption=caption.Id " + " INNER JOIN criteria " + " ON intermediate.foreign_to_criteria=criteria.Id"; List<Criteria> listCriteria = jdbcTemplate.query(sql, new RowMapper<Criteria>() { @Override/*from w w w . j a v a 2 s . co m*/ public Criteria mapRow(ResultSet rs, int rowNum) throws SQLException { Criteria criteria = new Criteria(); criteria.setId(rs.getInt("id")); criteria.setValue(rs.getDouble("criteria_value")); criteria.setArgument(rs.getDouble("argument")); criteria.setFormula(rs.getString("formula")); criteria.setWeighFactor(rs.getDouble("weight_factor")); return criteria; } }); return listCriteria; }
From source file:shell.framework.organization.user.service.impl.TblSysUserService4JdbcImpl.java
public TblSysUser findUserByID(Serializable id) { String sql = "select * from TBL_SYS_USER user where user.ID = ?"; List<?> resultList = jdbcBaseDao.query(sql, new Object[] { id }, new RowMapper<Object>() { /* (non-Javadoc) * @see org.springframework.jdbc.core.RowMapper#mapRow(java.sql.ResultSet, int) *//* w w w .j a v a 2s.co m*/ public Object mapRow(ResultSet rs, int rowNum) throws SQLException { TblSysUser user = new TblSysUser(); Map<String, String> propertyMap = new HashMap<String, String>(); propertyMap.put("createdTime", "CREATE_TIME"); propertyMap.put("updatedTime", "UPDATE_TIME"); PopulateUtil.populate(user, rs, propertyMap); return user; } }); if (resultList == null || resultList.size() == 0) { throw new RuntimeException("NO DATA FROM DATABASE!"); } return (TblSysUser) resultList.get(0); }
From source file:com.ex.Dao.impl.GroupDaoImpl.java
@Override public List<Group> listAllGroups() { String sql = "SELECT * FROM " + dbName + " ORDER BY GROUP_NAME"; List<Group> groupsList = jdbcTemplate.query(sql, new RowMapper<Group>() { @Override/* w w w .j a v a 2 s.c om*/ public Group mapRow(ResultSet rs, int rowNum) throws SQLException { Group group = new Group(); group.setId(rs.getString("group_id")); group.setVersion(rs.getLong("version")); group.setXml(rs.getString("xml")); group.setGroupName(rs.getString("GROUP_NAME")); group.setCreatedBy(rs.getString("created_by")); group.setUpdatedAt(rs.getTimestamp("updated_at")); return group; } }); return groupsList; }
From source file:dk.nsi.haiba.lprimporter.dao.impl.HAIBADAOImpl.java
@Override public Collection<ShakRegionValues> getShakRegionValuesForSygehusNumre(Collection<String> sygehusNumre) { List<ShakRegionValues> returnValue = new ArrayList<ShakRegionValues>(); for (String nummer : sygehusNumre) { // 3800-sygehuse has an extra sygehus extension that doesn't exist in the shak table String truncatedSygehusNummer = nummer.length() > 4 ? nummer.substring(0, 4) : nummer; RowMapper<ShakRegionValues> rowMapper = new RowMapper<ShakRegionValues>() { @Override/*from ww w . ja va2 s. c o m*/ public ShakRegionValues mapRow(ResultSet rs, int rowNum) throws SQLException { ShakRegionValues returnValue = new ShakRegionValues(); returnValue.setEjerForhold(rs.getString("Ejerforhold")); returnValue.setInstitutionsArt(rs.getString("Institutionsart")); returnValue.setRegionsKode(rs.getString("Regionskode")); return returnValue; } }; String sql = "SELECT DISTINCT Ejerforhold,Institutionsart,Regionskode FROM " + fgrtableprefix + "Class_SHAK WHERE nummer = ?"; try { ShakRegionValues shakRegionValues = jdbc.queryForObject(sql, rowMapper, truncatedSygehusNummer); // but keep the original nummer here shakRegionValues.setNummer(nummer); returnValue.add(shakRegionValues); } catch (RuntimeException e) { log.error("Error fetching shakregion values from truncatedSygehusNummer " + truncatedSygehusNummer + ", sql=" + sql, e); } } return returnValue; }
From source file:dk.nsi.haiba.lprimporter.dao.impl.ClassificationCheckDAOImpl.java
private Collection<Codes> getKoder(String sql, final String f1, final String f2) { Collection<Codes> returnValue = new ArrayList<Codes>(); try {/*from w ww .j a v a 2s.com*/ returnValue = aClassificationJdbc.query(sql, new RowMapper<Codes>() { @Override public Codes mapRow(ResultSet rs, int rowNum) throws SQLException { String code = rs.getString(f1); String secondaryCode = rs.getString(f2); return new CodesImpl(code, secondaryCode); } }); } catch (EmptyResultDataAccessException e) { } catch (RuntimeException e) { throw new DAOException("Error fetching for sql " + sql, e); } return returnValue; }
From source file:org.ohdsi.webapi.service.TherapyPathResultsService.java
@Path("report/{id}") @GET/*w w w . j a v a2 s. c om*/ @Produces(MediaType.APPLICATION_JSON) public List<TherapyPathVector> getTherapyPathVectors(@PathParam("id") String id, @PathParam("sourceKey") String sourceKey) { try { Source source = getSourceRepository().findBySourceKey(sourceKey); String tableQualifier = source.getTableQualifier(SourceDaimon.DaimonType.Results); String sql_statement = ResourceHelper .GetResourceAsString("/resources/therapypathresults/sql/getTherapyPathVectors.sql"); sql_statement = SqlRender.renderSql(sql_statement, new String[] { "id" }, new String[] { id }); sql_statement = SqlTranslate.translateSql(sql_statement, "sql server", source.getSourceDialect()); return getSourceJdbcTemplate(source).query(sql_statement, new RowMapper<TherapyPathVector>() { @Override public TherapyPathVector mapRow(final ResultSet rs, final int arg1) throws SQLException { final TherapyPathVector vector = new TherapyPathVector(); vector.key = rs.getString("ResultKey"); vector.count = rs.getInt("ResultCount"); return vector; } }); } catch (Exception exception) { throw new RuntimeException("Error getting therapy path vectors - " + exception.getMessage()); } }
From source file:mylife.respository.client1DAO.java
/** * * @param start// ww w . jav a 2 s . c o m * @param total * @return */ public List<client1> getclient1ByPage(int start, int total) { String sql = "SELECT * FROM client1 LIMIT " + (start - 1) + "," + total; return template.query(sql, new RowMapper<client1>() { public client1 mapRow(ResultSet rs, int row) throws SQLException { client1 c = new client1(); c.setIdclient1(rs.getInt(1)); c.setFirstname(rs.getString(2)); c.setLastname(rs.getString(3)); c.setAddressline1(rs.getString(4)); c.setAddressline2(rs.getString(5)); c.setCity(rs.getString(6)); c.setState(rs.getString(7)); c.setZip(rs.getString(8)); c.setEmail(rs.getString(9)); c.setCurrent_status(rs.getString(10)); c.setPhone_number(rs.getString(11)); return c; } }); }
From source file:com.sfs.whichdoctor.dao.OnlineApplicationDAOImpl.java
/** * Used to get a OnlineApplicationBean for the the specified online application id. * Returns null if no online application found * * @param onlineApplicationId the online application id * * @return the online application bean/*from w w w. j a v a2 s . com*/ * * @throws WhichDoctorDaoException the which doctor dao exception */ public final OnlineApplicationBean load(final int onlineApplicationId) throws WhichDoctorDaoException { dataLogger.info("Online application id: " + onlineApplicationId + " requested"); OnlineApplicationBean onlineApplication = null; try { onlineApplication = (OnlineApplicationBean) this.getJdbcTemplateReader().queryForObject( this.getSQL().getValue("onlineapplication/loadId"), new Object[] { onlineApplicationId }, new RowMapper() { public Object mapRow(final ResultSet rs, final int rowNum) throws SQLException { return loadOnlineApplicationBean(rs); } }); } catch (IncorrectResultSizeDataAccessException ie) { dataLogger.debug("No results found for this search: " + ie.getMessage()); } return onlineApplication; }
From source file:io.lavagna.service.NotificationService.java
/** * Return a list of user id to notify.//from w ww. jav a 2 s.c o m * * @param upTo * @return */ public Set<Integer> check(Date upTo) { final List<Integer> userWithChanges = new ArrayList<>(); List<SqlParameterSource> res = jdbc.query(queries.countNewForUsersId(), new RowMapper<SqlParameterSource>() { @Override public SqlParameterSource mapRow(ResultSet rs, int rowNum) throws SQLException { int userId = rs.getInt("USER_ID"); userWithChanges.add(userId); return new MapSqlParameterSource("count", rs.getInt("COUNT_EVENT_ID")).addValue("userId", userId); } }); if (!res.isEmpty()) { jdbc.batchUpdate(queries.updateCount(), res.toArray(new SqlParameterSource[res.size()])); } queries.updateCheckDate(upTo); // select users that have pending notifications that were not present in this check round MapSqlParameterSource userWithChangesParam = new MapSqlParameterSource("userWithChanges", userWithChanges); // List<Integer> usersToNotify = jdbc.queryForList( queries.usersToNotify() + " " + (userWithChanges.isEmpty() ? "" : queries.notIn()), userWithChangesParam, Integer.class); // jdbc.update(queries.reset() + " " + (userWithChanges.isEmpty() ? "" : queries.notIn()), userWithChangesParam); // return new TreeSet<>(usersToNotify); }
From source file:com.suntek.gztpb.dao.VehicleLicenseDao.java
public List getAttachs(final String id) { String sql = "select ID,Blob from itms_test where id =? "; return getJdbcTemplate().query(sql, new Object[] { id }, new RowMapper() { public byte[] mapRow(ResultSet rs, int rowNum) throws SQLException { // ?? BLOB ? byte[] attach = lobHandler.getBlobAsBytes(rs, 2); return attach; }//from ww w . j a va 2s .co m }); }