List of usage examples for org.springframework.jdbc.core RowMapper RowMapper
RowMapper
From source file:shell.framework.cache.SystemCacheInitializer.java
/** * ?departmentCache?// w ww . j a v a 2s. c om * <id,> => <department_id,department> */ @SuppressWarnings("all") public void departmentInitial() { String sql = "select ID,DEPARTMENT_NAME,DEPARTMENT_TYPE,PARENT_ID,ORDER_NO from TBL_SYS_DEPARTMENT where IS_VALID='" + SystemParam.IS_VALID + "'"; List<?> departmentList = this.jdbcBaseDao.query(sql, 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 { TblSysDepartment department = new TblSysDepartment(); Map<String, String> propertyMap = new HashMap<String, String>(); propertyMap.put("departmentName", "DEPARTMENT_NAME"); propertyMap.put("departmentType", "DEPARTMENT_TYPE"); propertyMap.put("organizationID", "ORGANIZATION_ID"); propertyMap.put("parentID", "PARENT_ID"); propertyMap.put("orderID", "ORDER_NO"); propertyMap.put("isValid", "IS_VALID"); propertyMap.put("isVD", "IS_VD"); PopulateUtil.populate(department, rs, propertyMap); CacheUtil.putValue("departmentCache", department.getId(), department); return department; } }); }
From source file:com.sfs.whichdoctor.dao.ProjectDAOImpl.java
/** * Used to get a ProjectBean for a specified ProjectId. * * @param projectId the project id//from w ww.j av a 2 s .c o m * @return the project bean * @throws WhichDoctorDaoException the which doctor dao exception */ @SuppressWarnings("unchecked") public final ProjectBean load(final int projectId) throws WhichDoctorDaoException { dataLogger.info("ProjectId: " + projectId + " requested"); final String loadId = getSQL().getValue("project/load") + " WHERE project.ProjectId = ?"; ProjectBean project = null; try { project = (ProjectBean) this.getJdbcTemplateReader().queryForObject(loadId, new Object[] { projectId }, 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 project; }
From source file:org.copperengine.spring.audit.AuditTrailQueryEngine.java
@Override public List<AuditTrailInfo> getAuditTrails(String transactionId, String conversationId, String correlationId, Integer level, int maxResult) { SqlPagingQueryProviderFactoryBean factory = new SqlPagingQueryProviderFactoryBean(); String sortClause = "SEQ_ID"; String whereClause = "where 1=1 "; List<Object> args = new ArrayList<Object>(); if (level != null) { whereClause += " and LOGLEVEL <= ? "; sortClause = "LOGLEVEL"; args.add(level);/*from w w w.j av a2s . c om*/ } if (StringUtils.hasText(correlationId)) { whereClause += " and CORRELATION_ID = ? "; sortClause = "CORRELATION_ID"; args.add(correlationId); } if (StringUtils.hasText(conversationId)) { whereClause += " and CONVERSATION_ID = ? "; sortClause = "CONVERSATION_ID"; args.add(conversationId); } if (StringUtils.hasText(transactionId)) { whereClause += " and TRANSACTION_ID = ? "; sortClause = "TRANSACTION_ID"; args.add(transactionId); } String selectClause = "select " + "SEQ_ID," + "TRANSACTION_ID," + "CONVERSATION_ID," + "CORRELATION_ID," + "OCCURRENCE," + "LOGLEVEL," + "CONTEXT," + "INSTANCE_ID," + "MESSAGE_TYPE"; factory.setDataSource(getDataSource()); factory.setFromClause("from COP_AUDIT_TRAIL_EVENT "); factory.setSelectClause(selectClause); factory.setWhereClause(whereClause); factory.setSortKey(sortClause); PagingQueryProvider queryProvider = null; try { queryProvider = (PagingQueryProvider) factory.getObject(); } catch (Exception e) { logger.error(e.getMessage(), e); return null; } String query = queryProvider.generateFirstPageQuery(maxResult); // this.getJdbcTemplate().setQueryTimeout(1000); long start = System.currentTimeMillis(); RowMapper<AuditTrailInfo> rowMapper = new RowMapper<AuditTrailInfo>() { public AuditTrailInfo mapRow(ResultSet rs, int arg1) throws SQLException { return new AuditTrailInfo(rs.getLong("SEQ_ID"), rs.getString("TRANSACTION_ID"), rs.getString("CONVERSATION_ID"), rs.getString("CORRELATION_ID"), rs.getTimestamp("OCCURRENCE").getTime(), rs.getInt("LOGLEVEL"), rs.getString("CONTEXT"), rs.getString("INSTANCE_ID"), rs.getString("MESSAGE_TYPE")); } }; List<AuditTrailInfo> res = this.getJdbcTemplate().query(query, rowMapper, args.toArray()); long end = System.currentTimeMillis(); logger.info("query took: " + (end - start) + " ms : " + query); return res; }
From source file:com.nishayani.school.board.rest.dao.db.SchoolBoardDbImpl.java
/** * /*from www .j a v a 2 s . c o m*/ * method name : getStudents * @param classNo * @return * SchoolBoardDbImpl * return type : List<Student> * * purpose : * * Date : 02-Jan-2015 2:43:14 pm */ public List<Student> getStudents(String classNo) { String SQL_PROP_STUDENT_CLASS_LIST = properties.getProperty(Constants.SQL_PROP_STUDENT_CLASS_LIST); RowMapper<Student> mapper = new RowMapper<Student>() { @Override public Student mapRow(ResultSet rs, int arg1) throws SQLException { return getStudent(rs); } }; Map<String, String> paramMap = new HashMap<String, String>(); paramMap.put("paramClass", classNo); return namedParameterJdbcTemplate.query(SQL_PROP_STUDENT_CLASS_LIST, paramMap, mapper); }
From source file:db.migration.V055__UpdateECTS.java
private int getNextHibernateSequence(JdbcTemplate jdbcTemplate) { // Returns next global id List<Map> resultSet = jdbcTemplate.query("SELECT nextval('public.hibernate_sequence')", new RowMapper<Map>() { @Override//ww w. jav a 2 s. c o m public Map mapRow(ResultSet rs, int rowNum) throws SQLException { Map r = new HashMap<String, Object>(); ResultSetMetaData metadata = rs.getMetaData(); for (int i = 1; i <= metadata.getColumnCount(); i++) { String cname = metadata.getColumnName(i); int ctype = metadata.getColumnType(i); switch (ctype) { case Types.BIGINT: // id r.put(cname, rs.getInt(cname)); break; default: break; } } return r; } }); for (Map m : resultSet) { return (int) m.get("nextval"); } return 0; }
From source file:com.sfs.whichdoctor.dao.AssessmentDAOImpl.java
/** * Load the assessment bean.//from w ww . j a v a 2s. c o m * * @param assessmentId the assessment id * @param loadDetails the load details * @return the assessment bean * @throws WhichDoctorDaoException the which doctor dao exception */ @SuppressWarnings("unchecked") public AssessmentBean load(final int assessmentId, final BuilderBean loadDetails) throws WhichDoctorDaoException { AssessmentBean assessment = null; final String loadSQL = getSQL().getValue("assessment/load") + " AND assessment.AssessmentId = ?"; try { assessment = (AssessmentBean) this.getJdbcTemplateReader().queryForObject(loadSQL, new Object[] { assessmentId }, 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:com.sfs.whichdoctor.dao.IsbMessageDAOImpl.java
/** * Load the oldest unprocessed IsbMessage that needs publishing to an ISB. * * @param isbName the name of the ISB being published to * * @return the isb message bean/*from w ww .j a va2s. co m*/ * * @throws WhichDoctorDaoException the which doctor dao exception */ public final IsbMessageBean loadFirstUnprocessed(final String isbName) throws WhichDoctorDaoException { dataLogger.info("Oldest unpublished ISB message requested for '" + isbName + "'"); if (isbName == null) { throw new WhichDoctorDaoException("The ISB name cannot be null"); } IsbMessageBean isbMessage = null; try { isbMessage = (IsbMessageBean) this.getIsbJdbcTemplate().queryForObject( this.getSQL().getValue("isbmessage/loadUnprocessed"), new Object[] { isbName }, new RowMapper() { public Object mapRow(final ResultSet rs, final int rowNum) throws SQLException { return loadIsbMessageBean(rs); } }); } catch (IncorrectResultSizeDataAccessException ie) { dataLogger.debug("No results found for this search: " + ie.getMessage()); } return isbMessage; }
From source file:mylife.respository.interactionsDAO.java
/** * * @param start/* ww w . j a va2s .c o m*/ * @param total * @return */ public List<interactions> getinteractionsByPage(int start, int total) { String sql = "SELECT * FROM interactions LIMIT " + (start - 1) + "," + total; return template.query(sql, new RowMapper<interactions>() { public interactions mapRow(ResultSet rs, int row) throws SQLException { interactions i = new interactions(); i.setClients_id(rs.getInt(1)); i.setDate_of_contact(rs.getString(2)); i.setContact_name(rs.getString(3)); i.setContact_type(rs.getString(4)); i.setConversation(rs.getString(5)); return i; } }); }
From source file:com.ewcms.content.particular.dao.FrontEnterpriseArticleDAO.java
public List<EnterpriseArticle> findEnterpriseChannelArticleByPage(int channelId, int page, int row) { String sql = "Select * " + "From particular_enterprise_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<EnterpriseArticle> list = jdbcTemplate.query(sql, params, new RowMapper<EnterpriseArticle>() { @Override/*from w w w . j av a2 s. c om*/ public EnterpriseArticle mapRow(ResultSet rs, int rowNum) throws SQLException { return interactionRowMapper(rs); } }); return list; }
From source file:ru.org.linux.spring.dao.DeleteInfoDao.java
public List<DeleteInfoStat> getRecentStats() { return jdbcTemplate.query( "select * from( select reason, count(*), sum(bonus) from del_info where deldate>CURRENT_TIMESTAMP-'1 day'::interval and bonus is not null group by reason) as s where sum!=0 order by reason", new RowMapper<DeleteInfoStat>() { @Override/*from w w w . j a va2 s . c om*/ public DeleteInfoStat mapRow(ResultSet rs, int rowNum) throws SQLException { return new DeleteInfoStat(rs.getString("reason"), rs.getInt("count"), rs.getInt("sum")); } }); }