Example usage for org.springframework.jdbc.core RowMapper RowMapper

List of usage examples for org.springframework.jdbc.core RowMapper RowMapper

Introduction

In this page you can find the example usage for org.springframework.jdbc.core RowMapper RowMapper.

Prototype

RowMapper

Source Link

Usage

From source file:om.edu.squ.squportal.portlet.dps.registration.dropw.db.DropWDBImpl.java

/**
 * /*from w w w  .j a va2 s  . co m*/
 * method name  : getCourseList
 * @param student
 * @param locale
 * @return
 * DropWDBImpl
 * return type  : List<DropWDTO>
 * 
 * purpose      : Get list of courses for drop
 *
 * Date          :   Mar 30, 2017 8:20:37 AM
 */
public List<DropWDTO> getCourseList(Student student, Locale locale, String studentMode,
        String isWithdrawPeriodRule) {
    String SQL_DROPW_SELECT_COURSE_DETAILS = queryDropWProps
            .getProperty(Constants.CONST_SQL_DROPW_SELECT_COURSE_DETAILS);

    RowMapper<DropWDTO> rowMapper = new RowMapper<DropWDTO>() {

        @Override
        public DropWDTO mapRow(ResultSet rs, int rowNum) throws SQLException {
            DropWDTO dropWDTO = new DropWDTO();
            dropWDTO.setlAbrCourseNo(rs.getString(Constants.CONST_COLMN_L_ABR_CRSNO));
            dropWDTO.setCourseNo(rs.getString(Constants.CONST_COLMN_COURSE_NO));
            dropWDTO.setCourseName(rs.getString(Constants.CONST_COLMN_COURSE_NAME));
            dropWDTO.setSectCode(rs.getString(Constants.CONST_COLMN_SECT_CODE));
            dropWDTO.setSectionNo(rs.getString(Constants.CONST_COLMN_SECTION_NO));
            dropWDTO.setYearSemester(rs.getString(Constants.CONST_COLMN_YEAR_SEM));
            dropWDTO.setCredits(rs.getInt(Constants.CONST_COLMN_CREDITS));
            dropWDTO.setTutionFees(rs.getFloat(Constants.CONST_COLMN_TUTION_FEE));
            dropWDTO.setStatusDesc(rs.getString(Constants.CONST_COLMN_STATUS_DESC));
            return dropWDTO;
        }
    };

    Map<String, String> paramMap = new HashMap<String, String>();
    paramMap.put("paramStdId", student.getAcademicDetail().getId());
    paramMap.put("paramLocale", locale.getLanguage());
    paramMap.put("paramMode", studentMode);
    paramMap.put("paramDropTimeApplied", isWithdrawPeriodRule);

    return nPJdbcTemplDpsDropW.query(SQL_DROPW_SELECT_COURSE_DETAILS, paramMap, rowMapper);
}

From source file:com.sfs.whichdoctor.dao.ReimbursementDAOImpl.java

/**
 * Get a ReimbursementBean for a specified reimbursementId with the supplied
 * load details. A boolean parameter identifies whether to use the default
 * reader connection or optional writer connection datasource.
 *
 * @param reimbursementId the reimbursement id
 * @param loadDetails the load details//from  w  w w .  j av a  2  s. c o  m
 * @param useWriterConn the use writer conn
 *
 * @return the reimbursement bean
 *
 * @throws WhichDoctorDaoException the which doctor dao exception
 */
private ReimbursementBean load(final int reimbursementId, final BuilderBean loadDetails,
        final boolean useWriterConn) throws WhichDoctorDaoException {

    dataLogger.info("Reimbursement Id: " + reimbursementId + " requested");

    ReimbursementBean reimbursement = null;

    final String loadSQL = this.getSQL().getValue("reimbursement/load")
            + " AND reimbursement.ReimbursementId = ? " + "GROUP BY reimbursement.ReimbursementId";

    JdbcTemplate jdbcTemplate = this.getJdbcTemplateReader();

    if (useWriterConn) {
        jdbcTemplate = this.getJdbcTemplateWriter();
    }

    try {
        reimbursement = (ReimbursementBean) jdbcTemplate.queryForObject(loadSQL,
                new Object[] { reimbursementId }, new RowMapper() {
                    public Object mapRow(final ResultSet rs, final int rowNum) throws SQLException {
                        return loadReimbursement(rs, loadDetails);
                    }
                });

    } catch (IncorrectResultSizeDataAccessException ie) {
        dataLogger.debug("No results found for search: " + ie.getMessage());
    }
    return reimbursement;
}

From source file:ru.org.linux.comment.CommentDaoImpl.java

@Override
public Comment getById(int id) throws MessageNotFoundException {
    Comment comment;/*from   ww  w  .ja  v  a 2s.  c  o  m*/
    try {
        comment = jdbcTemplate.queryForObject(queryCommentById, new RowMapper<Comment>() {
            @Override
            public Comment mapRow(ResultSet resultSet, int i) throws SQLException {
                return new Comment(resultSet);
            }
        }, id);
    } catch (EmptyResultDataAccessException exception) {
        throw new MessageNotFoundException(id);
    }
    return comment;
}

From source file:com.sfs.whichdoctor.dao.PaymentDAOImpl.java

/**
 * Used to get a Collection of PaymentBeans for a specified GUID number.
 *
 * @param guid the guid/* www  .  j  a va  2s . c  o  m*/
 * @param fullResults the full results
 *
 * @return the collection< payment bean>
 *
 * @throws WhichDoctorDaoException the which doctor dao exception
 */
@SuppressWarnings("unchecked")
public final Collection<PaymentBean> load(final int guid, final boolean fullResults)
        throws WhichDoctorDaoException {

    dataLogger.info("Payments for GUID: " + guid + " requested");

    final String loadPayment = getSQL().getValue("payment/load")
            + " WHERE payment.Active = true AND payment.ReferenceGUID = ?"
            + " AND (invoice.Active IS null OR invoice.Active = true)"
            + " ORDER BY payment.PersonId, payment.InvoiceId";

    Collection<PaymentBean> payments = new ArrayList<PaymentBean>();

    try {
        payments = this.getJdbcTemplateReader().query(loadPayment, new Object[] { guid }, new RowMapper() {
            public Object mapRow(final ResultSet rs, final int rowNum) throws SQLException {
                return loadPayment(rs);
            }
        });

    } catch (IncorrectResultSizeDataAccessException ie) {
        dataLogger.debug("No results found for this search:" + ie.getMessage());
    }
    return payments;
}

From source file:com.ewcms.component.comment.dao.CommentDAO.java

@Override
public CommentCount getCommentCount(final int articleId) {
    String sql = "Select * From component_comment_counter Where article_id=?";

    Object[] params = { articleId };
    List<CommentCount> list = jdbcTemplate.query(sql, params, new RowMapper<CommentCount>() {

        @Override/*  w w  w.  j  av a2s. c o m*/
        public CommentCount mapRow(ResultSet rs, int rowNum) throws SQLException {
            CommentCount count = new CommentCount();
            count.setArticleId(rs.getInt("article_id"));
            count.setCommentCounter(rs.getInt("comment_counter"));
            count.setPersonCounter(rs.getInt("person_counter"));
            return count;
        }
    });
    if (list.isEmpty()) {
        CommentCount count = new CommentCount();
        count.setArticleId(articleId);
        count.setCommentCounter(0);
        count.setPersonCounter(0);

        return count;
    }

    return list.get(0);
}

From source file:info.raack.appliancelabeler.service.BackupDatabase.java

public List<SecondData> getSecondDataFromBackupDatabase(String userId, Ted5000 ted, Mtu mtu,
        String datapointsBack) {/*from w w  w . j  ava2 s .c o  m*/
    List<SecondData> data = jdbcTemplate.query(queryForSecondData, new Object[] { mtu.getId() },
            new RowMapper<SecondData>() {

                public SecondData mapRow(ResultSet rs, int arg1) throws SQLException {
                    return secondDataParser.parse(new ByteArrayInputStream(rs.getString("raw").getBytes()))
                            .get(0);
                }
            });

    return data;
}

From source file:com.sfs.whichdoctor.dao.SpecialtyDAOImpl.java

/**
 * Used to get an ArrayList of SpecialtyBeans for a specified GUID.
 *
 * @param specialtyId the specialty id/*from w  w w .ja  va2s.  c o  m*/
 * @return the specialty bean
 * @throws WhichDoctorDaoException the which doctor dao exception
 */
@SuppressWarnings("unchecked")
public final SpecialtyBean load(final int specialtyId) throws WhichDoctorDaoException {

    dataLogger.info("SpecialtyId: " + specialtyId + " requested");

    final String loadSpecialtyId = getSQL().getValue("specialty/load") + " WHERE specialty.SpecialtyId = ?";

    SpecialtyBean specialty = null;

    try {
        specialty = (SpecialtyBean) this.getJdbcTemplateReader().queryForObject(loadSpecialtyId,
                new Object[] { specialtyId }, new RowMapper() {
                    public Object mapRow(final ResultSet rs, final int rowNum) throws SQLException {
                        return loadSpecialty(rs);
                    }
                });

    } catch (IncorrectResultSizeDataAccessException ie) {
        dataLogger.debug("No results found for this search: " + ie.getMessage());
    }
    return specialty;
}

From source file:org.ohmage.query.impl.CampaignClassQueries.java

@Override
public List<Campaign.Role> getDefaultCampaignRolesForCampaignClass(String campaignId, String classId,
        Clazz.Role classRole) throws DataAccessException {
    try {//from   www. j av a2 s  .  co m
        return getJdbcTemplate().query(SQL_GET_CAMPAIGN_CLASS_DEFAULT_ROLES,
                new Object[] { campaignId, classId, classRole.toString() }, new RowMapper<Campaign.Role>() {
                    @Override
                    public Campaign.Role mapRow(ResultSet rs, int rowNum) throws SQLException {
                        return Campaign.Role.getValue(rs.getString("role"));
                    }
                });
    } catch (org.springframework.dao.DataAccessException e) {
        throw new DataAccessException("Error executing SQL '" + SQL_GET_CAMPAIGN_CLASS_DEFAULT_ROLES
                + "' with parameters: " + campaignId + ", " + classId + ", " + classRole + ", ", e);
    }
}

From source file:shell.framework.organization.department.service.impl.TblSysDepartmentServiceI4JdbcImpl.java

public TblSysDepartment findDepartmentByID(Serializable id) {
    String sql = "select * from TBL_SYS_DEPARTMENT department where department.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  va2  s  .  c  om
        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);
            return department;
        }
    });
    if (resultList == null || resultList.size() == 0) {
        throw new RuntimeException("NO DATA FROM DATABASE!");
    }
    return (TblSysDepartment) resultList.get(0);
}

From source file:om.edu.squ.squportal.portlet.dps.grade.incomplete.db.IncompleteGradeDBImpl.java

@Override
public List<GradeIncompleteDTO> getCourseList(boolean isRuleGradeChangeTimingFollowed, String employeeNo,
        Locale locale) {//from w  w w  .j  a v a2 s  .c o  m
    String SQL_GRADE_SELECT_COURSE_LIST = queryIncompleteGrade
            .getProperty(Constants.CONST_SQL_INCOMPLETE_GRADE_SELECT_COURSE_LIST);
    YearSemester yearSemester = null;

    RowMapper<GradeIncompleteDTO> rowMapper = new RowMapper<GradeIncompleteDTO>() {

        @Override
        public GradeIncompleteDTO mapRow(ResultSet rs, int rowNum) throws SQLException {
            GradeIncompleteDTO gradeDTO = new GradeIncompleteDTO();
            Course course = new Course();
            course.setlAbrCourseNo(rs.getString(Constants.CONST_COLMN_L_ABR_CRSNO));
            course.setCourseNo(rs.getString(Constants.CONST_COLMN_COURSE_NO));
            course.setCourseName(rs.getString(Constants.CONST_COLMN_COURSE_NAME));
            course.setSectionNo(rs.getString(Constants.CONST_COLMN_SECTION_NO));
            course.setSectCode(rs.getString(Constants.CONST_COLMN_SECT_CODE));
            course.setCourseYear(rs.getInt(Constants.COST_COL_DPS_COURSE_YEAR));
            course.setSemester(rs.getInt(Constants.COST_COL_DPS_SEMESTER_CODE));

            gradeDTO.setCourse(course);

            return gradeDTO;
        }
    };

    yearSemester = (isRuleGradeChangeTimingFollowed) ? getRuleYearSem() : getCurrentYearSem();

    Map<String, String> namedParameterMap = new HashMap<String, String>();

    namedParameterMap.put("paramLocale", locale.getLanguage());
    namedParameterMap.put("paramYear", String.valueOf(yearSemester.getYear()));
    namedParameterMap.put("paramSemester", String.valueOf(yearSemester.getSemester()));
    namedParameterMap.put("paramEmpNo", employeeNo);

    return nPJdbcTemplDpsIncompleteGrade.query(SQL_GRADE_SELECT_COURSE_LIST, namedParameterMap, rowMapper);
}