List of usage examples for org.springframework.jdbc.core RowMapper RowMapper
RowMapper
From source file:nl.surfnet.coin.teams.service.impl.GroupProviderServiceSQLImpl.java
private String getUserIdPreCondition(Long id) { Object[] args = { id, GroupProviderPreconditionTypes.USER_ID_REGEX.getStringValue() }; try {// w w w . j a v a 2s . co m return this.jdbcTemplate.queryForObject("SELECT gppo.value " + "FROM group_provider_precondition gpp " + "LEFT JOIN group_provider_precondition_option gppo ON gpp.id = gppo.group_provider_precondition_id " + "WHERE gpp.group_provider_id = ? AND gpp.className = ?;", args, new RowMapper<String>() { @Override public String mapRow(ResultSet resultSet, int i) throws SQLException { return resultSet.getString("value"); } }); } catch (EmptyResultDataAccessException e) { return null; } }
From source file:net.duckling.falcon.api.orm.DAOUtils.java
/*** * rowMapper?map??/* w ww . j av a2 s . com*/ * * @param Class * objClass * @param map * Map<,?>,???map * @return RowMapper * */ public RowMapper<T> getRowMapper(final Map<String, String> map) { return new RowMapper<T>() { @SuppressWarnings("unchecked") @Override public T mapRow(ResultSet rs, int index) throws SQLException { Object obj = null; try { obj = objClass.newInstance(); for (int i = 0; i < fields.length; i++) { Field field = fields[i]; field.getName(); setValueToObj(field, obj, rs); } } catch (InstantiationException e) { LOG.debug(e.getMessage(), e); } catch (IllegalAccessException e) { LOG.debug(e.getMessage(), e); } revertMapping(map, obj, rs); return (T) obj; } }; }
From source file:org.tradex.jdbc.JDBCHelper.java
/** * Issues a named parameter query using numerical binds, starting at 0. * @param sql The SQL/*from w w w . j ava 2 s. c om*/ * @param binds The bind values * @return an Object array of the results */ public Object[][] templateQuery(CharSequence sql, Object... binds) { NamedParameterJdbcTemplate template = new NamedParameterJdbcTemplate(ds); final List<Object[]> results = template.query(sql.toString(), getBinds(sql.toString().trim().toUpperCase(), binds), new RowMapper<Object[]>() { int columnCount = -1; @Override public Object[] mapRow(ResultSet rs, int rowNum) throws SQLException { if (columnCount == -1) columnCount = rs.getMetaData().getColumnCount(); Object[] row = new Object[columnCount]; for (int i = 0; i < columnCount; i++) { row[i] = rs.getObject(i + 1); } return row; } }); Object[][] ret = new Object[results.size()][]; int cnt = 0; for (Object[] arr : results) { ret[cnt] = arr; cnt++; } return ret; }
From source file:com.sfs.whichdoctor.dao.BulkEmailDAOImpl.java
/** * Used to get a BulkEmailBean for a specified GUID. * * @param guid the guid//from ww w . j a va 2 s .c om * @param loadDetails the load details * @return the bulk email bean * @throws WhichDoctorDaoException the which doctor dao exception */ public final BulkEmailBean loadGUID(final int guid, final BuilderBean loadDetails) throws WhichDoctorDaoException { dataLogger.info("GUID: " + guid + " requested"); final String loadId = getSQL().getValue("bulkEmail/load") + " WHERE bulk_email.GUID = ? GROUP BY bulk_email.GUID"; BulkEmailBean bulkEmail = null; try { bulkEmail = (BulkEmailBean) this.getJdbcTemplateReader().queryForObject(loadId, new Object[] { guid }, new RowMapper() { public Object mapRow(final ResultSet rs, final int rowNum) throws SQLException { return loadBulkEmail(rs, loadDetails); } }); } catch (IncorrectResultSizeDataAccessException ie) { // No results found for this search dataLogger.error("No result found for BulkEmailBean search"); } return bulkEmail; }
From source file:com.ewcms.component.online.dao.WorkingDAO.java
public List<Working> findWorkingByCitizen(int citizenId) { String sql = "Select DISTINCT t1.id As t1_id,t1.name As t1_name,t3.id As t3_id,t3.name As t3_name " + "From plugin_workingbody t1 " + "LEFT JOIN plugin_workingbody_organ t2 ON t1.id = t2.workingbody_id " + "LEFT JOIN site_organ t3 ON t2.organ_id = t3.id " + "INNER JOIN plugin_workingbody_matter t4 ON t1.id = t4.workingbody_id " + "Where t4.matter_id IN (Select matter_id From plugin_matter_citizen Where citizen_id = ?) " + "Order By t1.id Asc"; return jdbcTemplate.query(sql, new Object[] { citizenId }, new RowMapper<Working>() { @Override//w w w .j a va2 s . c o m public Working mapRow(ResultSet rs, int rowNum) throws SQLException { Working working = new Working(); working.setId(rs.getInt("t1_id")); working.setName(rs.getString("t1_name")); working.setOrgan(new Organ(rs.getInt("t3_id"), rs.getString("t3_name"))); Integer matterId = getMatterId(working.getId()); if (matterId == null) { working.setMatter(null); } else { working.setMatter(matterDAO.get(matterId)); } working.setChildren(getChildren(working.getId())); return working; } }); }
From source file:bd.gov.forms.dao.FormDaoImpl.java
public byte[] getTemplateContent(String formId) { Form form = (Form) jdbcTemplate.queryForObject("SELECT template_file FROM form WHERE form_id = ?", new Object[] { formId }, new RowMapper() { public Object mapRow(ResultSet resultSet, int rowNum) throws SQLException { Form form = new Form(); form.setPdfTemplate(resultSet.getBytes("template_file")); return form; }// w w w . j av a2 s. co m }); return form.getPdfTemplate(); }
From source file:com.springsource.greenhouse.events.load.JdbcEventLoaderRepositoryTest.java
@Test public void loadLeaderData() throws SQLException { long leaderId = eventLoaderRepository.loadLeader(new LeaderData("Craig Walls", "Craig is the Spring Social project lead", "http://www.habuma.com", "habuma", "NFJS", 1234)); assertEquals(1L, leaderId);//from w w w . j av a 2 s . c o m jdbcTemplate.queryForObject("select id, name, bio, personalUrl, twitterUsername from Leader where id=?", new RowMapper<ResultSet>() { public ResultSet mapRow(ResultSet rs, int rowNum) throws SQLException { assertEquals(1L, rs.getLong("id")); assertEquals("Craig Walls", rs.getString("name")); assertEquals("Craig is the Spring Social project lead", rs.getString("bio")); assertEquals("http://www.habuma.com", rs.getString("personalUrl")); assertEquals("habuma", rs.getString("twitterUsername")); return null; } }, leaderId); jdbcTemplate.queryForObject("select leader, sourceId, source from ExternalLeader where leader=?", new RowMapper<ResultSet>() { public ResultSet mapRow(ResultSet rs, int rowNum) throws SQLException { assertEquals(1L, rs.getLong("leader")); assertEquals(1234L, rs.getLong("sourceId")); assertEquals("NFJS", rs.getString("source")); return null; } }, leaderId); }
From source file:shell.framework.organization.user.service.impl.TblSysUserService4JdbcImpl.java
public List<?> findAllUser() { String sql = "select * from TBL_SYS_USER"; List<?> resultList = jdbcBaseDao.query(sql, new RowMapper<Object>() { /* (non-Javadoc) * @see org.springframework.jdbc.core.RowMapper#mapRow(java.sql.ResultSet, int) *///from w w w . j av a 2 s . c om 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; } }); return resultList; }
From source file:org.pegadi.server.sources.SourceServerImpl.java
public Source getSourceByID(int ID) { return template.queryForObject( "SELECT ID,name,email,url,address,postnumber,postaddress,position,notes,organization FROM Source_person WHERE ID=?", new RowMapper<Source>() { @Override// w ww. j av a2 s.c om public Source mapRow(ResultSet rs, int rowNum) throws SQLException { return getSourceFromResultSet(rs); } }, ID); }
From source file:com.rockagen.gnext.service.spring.security.extension.BasicJdbcDaoImpl.java
/** * Executes the SQL <tt>usersByUsernameQuery</tt> and returns a list of * UserDetails objects. There should normally only be one matching user. *//*from w w w . j ava 2 s. co m*/ protected List<BasicSecurityUser> loadUsersByUsername(String username) { return getJdbcTemplate().query(usersByUsernameQuery, new String[] { username }, new RowMapper<BasicSecurityUser>() { public BasicSecurityUser mapRow(ResultSet rs, int rowNum) throws SQLException { String username = rs.getString(1); String password = rs.getString(2); boolean enabled = rs.getBoolean(3); String mername = rs.getString(4); String email = rs.getString(5); String latestIp = rs.getString(6); return new BasicSecurityUser(username, password, enabled, true, true, true, AuthorityUtils.NO_AUTHORITIES, mername, email, latestIp); } }); }