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:com.epam.repository.book.BookRepository.java

public Book findByTitle(final String title) {
    return jdbcTemplate.queryForObject(FIND_BOOKS_BY_TITLE, new Object[] { title }, new RowMapper<Book>() {
        public Book mapRow(ResultSet rs, int rowNum) throws SQLException {
            Book book = new Book();
            int authorID = rs.getInt("Author");
            int genreID = rs.getInt("Genre");
            book.setId(rs.getInt("ID"));
            book.setGenre(new Genre(genreID, null));
            book.setStock(rs.getInt("Stock"));
            book.setAuthor(new Author(authorID, null, null));
            book.setTitle(title);/*from   ww w  .  j ava 2 s  .  c  om*/
            return book;
        }
    });
}

From source file:org.simbasecurity.core.audit.provider.DatabaseAuditLogProviderTest.java

private RowMapper<Object> getRowMapper(final boolean digestNull) {
    RowMapper<Object> rowMapper = new RowMapper<Object>() {
        @Override/* w ww  .j  av a  2  s. c o  m*/
        public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
            assertEquals("username", rs.getString("username"));
            assertEquals("remoteIP", rs.getString("remote_ip"));
            assertEquals(AuditLogEventCategory.SESSION.name(), rs.getString("eventcategory"));
            assertEquals("hostServerName", rs.getString("hostservername"));
            assertEquals("surname", rs.getString("name"));
            assertEquals("userAgent", rs.getString("useragent"));
            if (digestNull) {
                assertNull(rs.getString("digest"));
            } else {
                assertNotNull(rs.getString("digest"));
            }
            assertEquals("requestURL", rs.getString("requesturl"));
            assertEquals("CHAINID", rs.getString("chainid"));

            return null;
        }
    };
    return rowMapper;
}

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

/**
 * Used to get a Collection of SearchBean details for a
 * specified search filter./*from w w  w .j a va2s  . c  o m*/
 *
 * @param filter the filter
 * @param username or public saved searches
 * @param favourite load favourites or load everything
 * @return the collection
 * @throws WhichDoctorDaoException the which doctor dao exception
 */
@SuppressWarnings("unchecked")
public final Collection<SearchBean> load(final String filter, final String username, final boolean favourite)
        throws WhichDoctorDaoException {

    dataLogger.info("Searches for: " + username + " requested");

    Collection<SearchBean> savedsearches = new ArrayList<SearchBean>();

    ArrayList<Object> parameters = new ArrayList<Object>();
    parameters.add(username);

    StringBuffer loadSearch = new StringBuffer();
    loadSearch.insert(0, this.getSQL().getValue("search/loadUser"));

    if (favourite) {
        loadSearch.append(" AND favourite = true");
    }
    if (StringUtils.isNotBlank(filter)) {
        loadSearch.append(" AND (Name LIKE ? OR Description LIKE ?)");
        parameters.add("%" + filter + "%");
        parameters.add("%" + filter + "%");
    }
    loadSearch.append(" ORDER BY savedsearch.Name");

    try {
        savedsearches = this.getJdbcTemplateReader().query(loadSearch.toString(), parameters.toArray(),
                new RowMapper() {
                    public Object mapRow(final ResultSet rs, final int rowNum) throws SQLException {
                        return loadSearch(rs);
                    }
                });

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

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

@Override
public List<Comment> findCommentPage(final int articleId, final int page, final int row) {
    String sql = "Select * From component_comment Where article_id = ? Limit ? OffSet ?";
    int offset = page * row;
    Object[] params = { articleId, row, offset };
    return jdbcTemplate.query(sql, params, new RowMapper<Comment>() {

        @Override/*  w w  w.j  a v  a  2s  .c o  m*/
        public Comment mapRow(ResultSet rs, int rowNum) throws SQLException {
            Comment comment = new Comment();
            comment.setId(rs.getLong("id"));
            comment.setArticleId(rs.getInt("article_id"));
            comment.setIp(rs.getString("ip"));
            comment.setUsername(rs.getString("username"));
            comment.setDate(rs.getTimestamp("date"));
            comment.setReplies(findReply(comment.getId()));
            return comment;
        }
    });
}

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

/**
 * Used to get a Collection of ExamBeans for a specified GUID number.
 *
 * @param guid the guid//from   w w w . j  a  v  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<ExamBean> load(final int guid, final boolean fullResults)
        throws WhichDoctorDaoException {

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

    final String loadExam = getSQL().getValue("exam/load")
            + " WHERE exam.Active = true AND exam.ReferenceGUID = ?" + " ORDER BY exam.DateSat";

    Collection<ExamBean> exams = new ArrayList<ExamBean>();

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

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

From source file:om.edu.squ.squportal.portlet.dps.rule.db.RuleDbImpl.java

/**
 * //from   w ww  .  j  a v a2s .  com
 * method name  : getJoinAndCloseTime
 * @param studentNo
 * @param stdStatCode
 * @return
 * RuleDbImpl
 * return type  : StudentCompletionAndJoinTime
 * 
 * purpose      : Get Joining and estimated total number of semester to completion of the course
 *
 * Date          :   Mar 13, 2017 4:15:07 PM
 */
public StudentCompletionAndJoinTime getJoinAndCloseTime(String studentNo, String stdStatCode) {

    String SQL_RULE_STUDENT_JOIN_CLOSE_TIME = queryPropsCommonRule
            .getProperty(Constants.CONST_PROP_SQL_RULE_STUDENT_JOIN_CLOSE_TIME);
    RowMapper<StudentCompletionAndJoinTime> mapper = new RowMapper<StudentCompletionAndJoinTime>() {

        @Override
        public StudentCompletionAndJoinTime mapRow(ResultSet rs, int rowNum) throws SQLException {
            StudentCompletionAndJoinTime studentCompletionAndJoinTime = new StudentCompletionAndJoinTime();
            studentCompletionAndJoinTime.setStudentNo(rs.getString(Constants.CONST_COLMN_STUDENT_NO));
            studentCompletionAndJoinTime.setStdStatCode(rs.getString(Constants.CONST_COLMN_STDSTATCD));
            studentCompletionAndJoinTime
                    .setEstimatedSemesters(rs.getInt(Constants.CONST_COLMN_DGR_GRAD_ESTIMATE_SEM_COUNT));
            studentCompletionAndJoinTime
                    .setFromCCYrCode(rs.getInt(Constants.COST_COL_DPS_FROM_COURSE_YEAR_CODE));
            studentCompletionAndJoinTime.setFromSemCode(rs.getInt(Constants.COST_COL_DPS_FROM_SEMESTER_CODE));
            studentCompletionAndJoinTime.setCurrentYear(rs.getInt(Constants.COST_COL_DPS_CURRENT_YEAR));
            return studentCompletionAndJoinTime;
        }
    };

    Map<String, String> mapParamsRule = new HashMap<String, String>();
    mapParamsRule.put("paramStdNo", studentNo);
    mapParamsRule.put("paramStdStatCode", stdStatCode);
    return nPJdbcTemplDps.queryForObject(SQL_RULE_STUDENT_JOIN_CLOSE_TIME, mapParamsRule, mapper);
}

From source file:mylife.respository.userDAO.java

/**
 *
 * @param start//from  w  w  w  .j a  va 2 s  .co m
 * @param total
 * @return
 */
public List<user> getuserByPage(int start, int total) {
    String sql = "SELECT * FROM users LIMIT " + (start - 1) + "," + total;

    return template.query(sql, new RowMapper<user>() {
        public user mapRow(ResultSet rs, int row) throws SQLException {
            user u = new user();
            u.setUsername(rs.getString(1));
            u.setPassword(rs.getString(2));
            u.setEnabled(rs.getBoolean(3));

            return u;
        }
    });
}

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

/**
 * Load a collection of AccreditationBeans.
 *
 * @param guid the guid//from w ww.  java 2s  .  c  o m
 * @param fullResults the full results
 *
 * @return the collection< accreditation bean>
 *
 * @throws WhichDoctorDaoException the which doctor dao exception
 */
@SuppressWarnings("unchecked")
public final Collection<AccreditationBean> load(final int guid, final boolean fullResults)
        throws WhichDoctorDaoException {

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

    final String loadAccreditation = getSQL().getValue("accreditation/load")
            + " WHERE accreditation.Active = true" + " AND accreditation.ReferenceGUID = ?"
            + " ORDER BY accreditation.Core DESC," + " specialtytype.Class ASC, specialtytype.Name ASC";

    Collection<AccreditationBean> accreditations = new ArrayList<AccreditationBean>();

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

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

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

/**
 * Load the MemoBean.//from   w w w  .  j ava  2 s .  c  om
 *
 * @param memoId the memo id
 * @return the memo bean
 * @throws WhichDoctorDaoException the which doctor dao exception
 */
public final MemoBean load(final int memoId) throws WhichDoctorDaoException {

    dataLogger.info("Getting memoId:" + memoId);

    final String loadMemoId = getSQL().getValue("memo/load") + " WHERE memo.MemoId = ?";

    MemoBean memo = null;

    try {
        memo = (MemoBean) this.getJdbcTemplateReader().queryForObject(loadMemoId, new Object[] { memoId },
                new RowMapper() {
                    public Object mapRow(final ResultSet rs, final int rowNum) throws SQLException {
                        return loadMemo(rs, true);
                    }
                });

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

From source file:org.surfnet.cruncher.message.AggregatorTest.java

@Test
public void testRun() {
    aggregator.run();/*from ww  w  .j  a v  a2  s. c  om*/
    Calendar instance = Calendar.getInstance();
    instance.set(2012, 3, 21);
    String hash = aggregationRecordHash("idp2", "sp1", instance.getTime());

    long entryCount = cruncherJdbcTemplate
            .queryForLong("select entrycount from aggregated_log_logins where datespidphash = ?", hash);
    assertEquals(2, entryCount);
    long timestamp = cruncherJdbcTemplate.queryForLong("select aggregatepoint from aggregate_meta_data");
    assertEquals(20009L, timestamp);

    String userHash = aggregationRecordHash("idp2:user_1", "sp1");
    long lastlogin = cruncherJdbcTemplate.queryForObject(
            "select loginstamp from user_log_logins where usersphash = '" + userHash + "'",
            new RowMapper<Long>() {

                @Override
                public Long mapRow(ResultSet rs, int rowNum) throws SQLException {
                    return rs.getTimestamp(1).getTime();
                }

            });
    instance.setTimeInMillis(lastlogin);

    //2012-02-20 11:48:42
    assertEquals(20, instance.get(DAY_OF_MONTH));
    assertEquals(1, instance.get(MONDAY));
    assertEquals(2012, instance.get(YEAR));
}