List of usage examples for org.springframework.jdbc.core RowMapper RowMapper
RowMapper
From source file:shell.framework.organization.agentcode.service.impl.TblSysAgentCodeService4JdbcImpl.java
public VOResult findByPagination(int currentPage, int pageSize, TblSysAgentCodeVO agentCodeVO) { StringBuffer sql = new StringBuffer("select * from TBL_SYS_AGENTCODE agentcode"); sql.append(" where agentcode.IS_VALID='" + SystemParam.IS_VALID + "'"); //? // w w w . ja v a 2 s.c o m if (agentCodeVO.getSysAgentCode() != null && agentCodeVO.getSysAgentCode().getAgentCode() != null && !"".equals(agentCodeVO.getSysAgentCode().getAgentCode())) { sql.append(" and agentcode.AGENTCODE like '%" + agentCodeVO.getSysAgentCode().getAgentCode().trim() + "%'"); } return jdbcBaseDao.query(sql.toString(), new RowMapper<Object>() { /* (non-Javadoc) * @see org.springframework.jdbc.core.RowMapper#mapRow(java.sql.ResultSet, int) */ public Object mapRow(ResultSet rs, int rowNum) throws SQLException { TblSysAgentCode agentCode = new TblSysAgentCode(); Map<String, String> propertyMap = new HashMap<String, String>(); propertyMap.put("isValid", "IS_VALID"); propertyMap.put("isVac", "IS_VAC"); PopulateUtil.populate(agentCode, rs, propertyMap); return agentCode; } }, currentPage, pageSize); }
From source file:ru.org.linux.spring.dao.DeleteInfoDao.java
/** * , ?//from w w w.j ava2 s . c om * @param id id ? ?? * @param forUpdate ? (SELECT ... FOR UPDATE) * @return ? ? */ public DeleteInfo getDeleteInfo(int id, boolean forUpdate) { List<DeleteInfo> list = jdbcTemplate.query(forUpdate ? QUERY_DELETE_INFO_FOR_UPDATE : QUERY_DELETE_INFO, new RowMapper<DeleteInfo>() { @Override public DeleteInfo mapRow(ResultSet resultSet, int i) throws SQLException { Integer bonus = resultSet.getInt("bonus"); if (resultSet.wasNull()) { bonus = null; } return new DeleteInfo(resultSet.getInt("userid"), resultSet.getString("reason"), resultSet.getTimestamp("deldate"), bonus); } }, id); if (list.isEmpty()) { return null; } else { return list.get(0); } }
From source file:com.leapfrog.inventorymanagementsystem.dao.impl.ProductDAOImpl.java
@Override public Product getById(int id) throws SQLException, ClassNotFoundException { String sql = "SELECT * FROM tbl_product WHERE product_id =?"; return jdbcTemplate.queryForObject(sql, new Object[] { id }, new RowMapper<Product>() { @Override//from w w w. j ava 2 s .co m public Product mapRow(ResultSet rs, int i) throws SQLException { Product p = new Product(); p.setId(rs.getInt("product_id")); p.setProductName(rs.getString("product_name")); p.setCostPrice(rs.getInt("cost_price")); p.setSellingPrice(rs.getInt("selling_price")); p.setDiscount(rs.getBigDecimal("discount")); p.setQuantity(rs.getInt("quantity")); p.setCategoryName(rs.getString("category_name")); p.setSupplierId(rs.getInt("supplier_id")); p.setAddedDate(rs.getDate("added_date")); p.setModifiedDate(rs.getDate("modified_date")); p.setStatus(rs.getBoolean("status")); return p; } }); }
From source file:com.leapfrog.inventorymanagementsystem.dao.impl.PurchaseDAOImpl.java
@Override public Purchase getById(int id) throws SQLException, ClassNotFoundException { String sql = "SELECT * FROM tbl_purchase WHERE purchase_id =?"; return jdbcTemplate.queryForObject(sql, new Object[] { id }, new RowMapper<Purchase>() { @Override/*www . jav a2 s .c om*/ public Purchase mapRow(ResultSet rs, int i) throws SQLException { Purchase p = new Purchase(); p.setId(rs.getInt("purchase_id")); p.setProductName(rs.getString("product_name")); p.setCostPrice(rs.getInt("cost_price")); p.setDiscount(rs.getBigDecimal("discount")); p.setQuantity(rs.getInt("quantity")); p.setTotalCost(rs.getInt("total_cost")); p.setSupplierId(rs.getInt("supplier_id")); p.setPurchaseDate(rs.getDate("purchase_date")); p.setPaymentMethod(rs.getString("payment_method")); p.setStatus(rs.getBoolean("status")); return p; } }); }
From source file:com.sfs.whichdoctor.dao.ProjectDAOImpl.java
/** * Used to get an Collection of ProjectBeans for a specified GUID number. * * @param guid the guid/*from w ww . j av a 2 s .c o m*/ * @param fullResults the full results * @return the collection * @throws WhichDoctorDaoException the which doctor dao exception */ @SuppressWarnings("unchecked") public final Collection<ProjectBean> load(final int guid, final boolean fullResults) throws WhichDoctorDaoException { dataLogger.info("Projects for GUID: " + guid + " requested"); final String loadProject = getSQL().getValue("project/load") + " WHERE project.Active = true AND project.ReferenceGUID = ?" + " ORDER BY project.Year, guid.CreatedDate"; Collection<ProjectBean> projects = new ArrayList<ProjectBean>(); try { projects = this.getJdbcTemplateReader().query(loadProject, new Object[] { guid }, new RowMapper() { public Object mapRow(final ResultSet rs, final int rowNum) throws SQLException { return loadProject(rs); } }); } catch (IncorrectResultSizeDataAccessException ie) { dataLogger.debug("No results found for this search: " + ie.getMessage()); } return projects; }
From source file:com.arcane.dao.Impl.PatternDaoImpl.java
@Override public List<Pattern> patternList() { //return all available (occured) patterns LOG.info("Returning all available (occured) patterns"); JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); String sql = "SELECT * from pattern"; List<Pattern> listPattern = jdbcTemplate.query(sql, new RowMapper<Pattern>() { @Override//from w w w. j a v a 2 s . c om public Pattern mapRow(ResultSet rs, int rowNumber) throws SQLException { Pattern pattern = new Pattern(); pattern.setId(rs.getInt("id")); pattern.setName(rs.getString("name")); return pattern; } }); return listPattern; }
From source file:com.googlecode.starflow.engine.repository.impl.ProcessInstanceRepositoryImpl.java
public ProcessInstance findProcessInstance(long processInstId) { return this.getJdbcTemplate().queryForObject(findProcessInstanceSQL, new RowMapper<ProcessInstance>() { @Override/*from w w w . j a va 2 s .c o m*/ public ProcessInstance mapRow(ResultSet resultSet, int index) throws SQLException { ProcessInstance processInstance = new ProcessInstance(); processInstance.setProcessInstId(resultSet.getLong("processInstId")); processInstance.setProcessDefId(resultSet.getLong("processDefId")); processInstance.setProcessInstName(resultSet.getString("processInstName")); processInstance.setCreator(resultSet.getString("creator")); processInstance.setCreateTime(resultSet.getDate("createTime")); processInstance.setSubFlow(resultSet.getString("subFlow")); processInstance.setLimitNum(resultSet.getLong("limitNum")); processInstance.setCurrentState(resultSet.getInt("currentState")); processInstance.setMainProcInstId(resultSet.getLong("mainProcInstId")); processInstance.setParentProcInstId(resultSet.getLong("parentProcInstId")); processInstance.setActivityInstId(resultSet.getLong("activityInstId")); return processInstance; } }, processInstId); }
From source file:com.sfs.whichdoctor.dao.AssessmentDAOImpl.java
/** * Load the assessment bean.//from www .j ava 2 s . c o m * * @param guid the guid * @return the collection * @throws WhichDoctorDaoException the which doctor dao exception */ @SuppressWarnings("unchecked") public Collection<AssessmentBean> load(final int guid) throws WhichDoctorDaoException { Collection<AssessmentBean> assessment = new ArrayList<AssessmentBean>(); final String loadSQL = this.getSQL().getValue("assessment/load") + " AND assessment.Active = true AND assessment.ReferenceGUID = ? " + "ORDER BY assessmenttype.Abbreviation, assessment.SpecialtyType"; final BuilderBean loadDetails = new BuilderBean(); try { assessment = this.getJdbcTemplateReader().query(loadSQL, new Object[] { guid }, new RowMapper() { public Object mapRow(ResultSet rs, int rowNum) throws SQLException { return loadAssessmentBean(rs, loadDetails); } }); } catch (IncorrectResultSizeDataAccessException ie) { // No results found for this search } return assessment; }
From source file:architecture.common.adaptor.connector.jdbc.AbstractJdbcConnector.java
protected List<Map<String, Object>> pull(final String queryString, final List<ParameterMapping> parameterMappings, final Object[] args) { // log.debug("pulling..." ); return getJdbcTemplate().query(queryString, args, new RowMapper<Map<String, Object>>() { public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException { ResultSetMetaData rsmd = rs.getMetaData(); int columnCount = rsmd.getColumnCount(); Map<String, Object> mapOfColValues = createColumnMap(columnCount); for (int i = 1; i <= columnCount; i++) { String key = getColumnKey(lookupColumnName(rsmd, i)); Object obj = getColumnValue(rs, i); mapOfColValues.put(key, obj); }/*from w w w. j a va 2s .co m*/ return mapOfColValues; } protected Map<String, Object> createColumnMap(int columnCount) { return new LinkedHashMap<String, Object>(columnCount); } protected String getColumnKey(String columnName) { return columnName; } protected Object getColumnValue(ResultSet rs, int index) throws SQLException { for (ParameterMapping mapping : parameterMappings) { // LOG.debug( index + " mapping match :" + // mapping.getIndex()); if (index == mapping.getIndex()) { if (String.class == mapping.getJavaType()) { String value = rs.getString(index); if (StringUtils.isEmpty(value)) value = ""; if (!StringUtils.isEmpty(mapping.getCipher())) { try { Cipher cipher = Cipher.getInstance(mapping.getCipher()); SecretKeySpec skeySpec = new SecretKeySpec( Hex.decodeHex(mapping.getCipherKey().toCharArray()), mapping.getCipherKeyAlg()); cipher.init(Cipher.DECRYPT_MODE, skeySpec); byte raw[]; if (!StringUtils.isEmpty(mapping.getEncoding())) { String enc = mapping.getEncoding(); if (enc.toUpperCase().equals("BASE64")) { raw = Base64.decodeBase64(value); // BASE64Decoder decoder = new // BASE64Decoder(); // raw = // decoder.decodeBuffer(value); } else { raw = value.getBytes(); } } else { raw = value.getBytes(); } byte stringBytes[] = cipher.doFinal(raw); return new String(stringBytes); } catch (Exception e) { LOG.error(e); } return value; } if (!StringUtils.isEmpty(mapping.getEncoding())) { String[] encoding = StringUtils.split(mapping.getEncoding(), ">"); try { if (encoding.length == 2) return new String(value.getBytes(encoding[0]), encoding[1]); else if (encoding.length == 1) { return new String(value.getBytes(), encoding[0]); } } catch (UnsupportedEncodingException e) { LOG.error(e); return value; } } } else if (Long.class == mapping.getJavaType()) { String value = rs.getString(index); if (StringUtils.isEmpty(value)) value = "0"; return new Long(value); } else if (Integer.class == mapping.getJavaType()) { String value = rs.getString(index); if (StringUtils.isEmpty(value)) value = "0"; return new Integer(value); } else if (Double.class == mapping.getJavaType()) { String value = rs.getString(index); if (StringUtils.isEmpty(value)) value = "0"; return new Double(value); } } } return JdbcUtils.getResultSetValue(rs, index); } }); }
From source file:com.sktelecom.cep.notebook.repo.JDBCNotebookRepo.java
@Override public List<NoteInfo> list() throws IOException { StringBuffer sb = new StringBuffer(); sb.append("select nb.note_id, nb.note_name, nb.note_content, wo.own_user_id as user_id "); sb.append(" from notebook nb "); sb.append(//from w w w . ja va2 s. c om " inner join workspace_object wo ON wo.wrkspc_obj_id = nb.wrkspc_obj_id AND wo.obj_status != 'DROPPED' "); List<NoteInfo> infos = jdbcTemplate.query(sb.toString(), new RowMapper<NoteInfo>() { public NoteInfo mapRow(ResultSet rs, int rowNum) throws SQLException { NoteInfo info = null; try { info = getNoteInfo(rs.getString("note_content")); info.setUserId(rs.getString("user_id")); info.setName(rs.getString("note_name")); } catch (IOException e) { e.printStackTrace(); } return info; } }); return infos; }