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:bd.gov.forms.dao.ListDaoImpl.java

public String getListDataSysId(int id) {
    return (String) jdbcTemplate.queryForObject("SELECT sys_id FROM list_data WHERE id = ?",
            new Object[] { id }, new RowMapper() {

                public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
                    return rs.getString("sys_id");
                }/*from ww w.j  a  va2  s .  c  o  m*/
            });
}

From source file:com.rakesh.rp3599.repository.ApplicationRepository.java

public List<Application> findAll() {
    return jdbcTemplate.query(ApplicationUtil.SELECT_AGENCY, new RowMapper<Application>() {
        public Application mapRow(ResultSet rs, int rownumber) throws SQLException {
            Application e = new Application();
            e.setId(rs.getInt("id"));
            e.setCompanyName(rs.getString("company_name"));
            return e;
        }/*from w  ww  . j a  va2s  .c o m*/
    });
}

From source file:com.ewcms.component.online.dao.WorkingDAO.java

public Working get(Integer id) {
    String sql = "Select id,name,parent_id From plugin_workingbody " + "Where id=?";

    List<Working> list = jdbcTemplate.query(sql, new Object[] { id }, new RowMapper<Working>() {

        @Override/*from  w  w  w .  j a v a  2 s .c  om*/
        public Working mapRow(ResultSet rs, int rowNum) throws SQLException {
            Working working = new Working();
            working.setId(rs.getInt("id"));
            working.setName(rs.getString("name"));
            working.setParentId(rs.getInt("parent_id"));
            Integer matterId = getMatterId(working.getId());
            if (matterId == null) {
                working.setMatter(null);
            } else {
                working.setMatter(matterDAO.get(matterId));
            }
            working.setChildren(getChildren(working.getId()));
            return working;
        }
    });
    if (list.isEmpty()) {
        return null;
    }
    Working working = list.get(0);

    return working;
}

From source file:com.sfs.dao.SettingsDAOImpl.java

/**
 * Loads a menu xml document from the database and returns it within a
 * SettingsBean./*  w w  w  .  j  ava  2  s. c  om*/
 *
 * @param type the type
 *
 * @return the settings bean
 *
 * @throws SFSDaoException the SFS dao exception
 */
public final SettingsBean loadSettings(final String type) throws SFSDaoException {

    if (type == null) {
        throw new SFSDaoException("The settings type cannot be null");
    }

    SettingsBean settingsBean = null;

    try {
        settingsBean = (SettingsBean) this.getJdbcTemplateReader().queryForObject(
                this.getSQL().getValue("settings/load"), new Object[] { type }, new RowMapper() {
                    public Object mapRow(final ResultSet rs, final int rowNum) throws SQLException {

                        SettingsBean loadedSettings = new SettingsBean();
                        loadedSettings.setType(type);

                        Reader settingsStream = rs.getCharacterStream("Settings");
                        SAXBuilder builder = new SAXBuilder();
                        try {
                            loadedSettings.setXmlDocument(builder.build(settingsStream));
                            dataLogger.info("XML settings file parsed " + "successfully");
                        } catch (JDOMException jde) {
                            dataLogger.fatal("Error parsing XML settings: " + jde.getMessage());
                        } catch (IOException ioe) {
                            dataLogger.fatal("Error reading XML character " + "stream: " + ioe.getMessage());
                        }
                        return loadedSettings;
                    }
                });

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

From source file:com.havoc.hotel.admin.dao.impl.CheckoutDAOImpl.java

@Override
public List<Checkout> getALL() throws SQLException {
    return jdbcTemplate.query(SQLConstant.CHECKOUT_GETALL, new RowMapper<Checkout>() {

        @Override// w ww. jav a  2 s .  co m
        public Checkout mapRow(ResultSet rs, int i) throws SQLException {
            return mapData(rs);
        }
    });
}

From source file:ru.org.linux.topic.LastMiniNewsDao.java

public List<LastMiniNews> getTopics(final int perPage) {
    String sql = "select topics.id as msgid, groups.urlname, groups.section, topics.title, lastmod, topics.stat1 as c  "
            + "from topics " + "join groups on groups.id = topics.groupid" + " where "
            + "  topics.postdate>(CURRENT_TIMESTAMP-'1 month 1 day'::interval) and " + //  ? ??
            "  not deleted and " + // ?
            "  groups.section = 1 and topics.moderate and commitdate is not null and not draft " + // ??
            "  and minor order by topics.commitdate desc limit 10"; // 10 

    return jdbcTemplate.query(sql, new RowMapper<LastMiniNews>() {
        @Override//from   www.j ava 2 s  . com
        public LastMiniNews mapRow(ResultSet rs, int i) throws SQLException {
            final int answers = rs.getInt("c");
            final int answers0 = (answers == 0) ? 1 : answers;
            final int tmp = answers0 / perPage;
            final int pages = (answers0 % perPage > 0) ? tmp + 1 : tmp;
            LastMiniNews result = new LastMiniNews(
                    sectionService.getSection(rs.getInt("section")).getSectionLink() + rs.getString("urlname")
                            + '/' + rs.getInt("msgid"),
                    rs.getTimestamp("lastmod"), rs.getString("title"), answers, pages);
            return result;
        }
    });

}

From source file:org.openmrs.module.bahmniexports.example.domain.trade.internal.JdbcCustomerDao.java

@Override
public CustomerCredit getCustomerByName(String name) {

    List<CustomerCredit> customers = getJdbcTemplate().query(GET_CUSTOMER_BY_NAME, new Object[] { name },

            new RowMapper<CustomerCredit>() {

                @Override/*from w w  w  .  j  av a  2 s  . c  o  m*/
                public CustomerCredit mapRow(ResultSet rs, int rowNum) throws SQLException {
                    CustomerCredit customer = new CustomerCredit();
                    customer.setName(rs.getString("NAME"));
                    customer.setId(rs.getInt("ID"));
                    customer.setCredit(rs.getBigDecimal("CREDIT"));
                    return customer;
                }

            });

    if (customers.size() == 0) {
        return null;
    } else {
        return customers.get(0);
    }

}

From source file:CRM.repository.UsersDAO.java

public List<users> getUsersByPage(int start, int total) {
    String sql = "SELECT * FROM users LIMIT " + (start - 1) + "," + total;
    return template.query(sql, new RowMapper<users>() {
        public users mapRow(ResultSet rs, int row) throws SQLException {
            users u = new users();
            u.setUsername(rs.getString(1));
            u.setPassword(rs.getString(2));
            u.setEnabled(rs.getInt(3));/* w w  w.j  a  v  a2  s .  c om*/
            u.setName(rs.getString(4));
            return u;
        }
    });

}

From source file:bd.gov.forms.dao.UserDaoImpl.java

public User getUser(String sysId) {
    return (User) jdbcTemplate.queryForObject("SELECT * FROM user WHERE sys_id = ?", new Object[] { sysId },
            new RowMapper() {

                public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
                    User user = new User();

                    user.setId(rs.getInt("id"));
                    user.setSysId(rs.getString("sys_id"));
                    user.setName(rs.getString("name"));
                    user.setTitle(rs.getString("title"));
                    user.setUserName(rs.getString("user"));
                    user.setPassword(rs.getString("password"));

                    user.setMobile(rs.getString("mobile"));
                    user.setEmail(rs.getString("email"));
                    user.setAdmin(rs.getInt("admin"));
                    user.setActive(rs.getInt("active"));

                    return user;
                }//from   w ww. ja v  a  2 s.c om
            });
}

From source file:nl.surfnet.coin.eb.EngineBlockImpl.java

@Override
public String getUserUUID(String identifier) {
    Assert.hasText(identifier, "Not allowed to provide a null or empty identifier");
    String sql = "SELECT user_uuid FROM saml_persistent_id WHERE persistent_id =  ?";
    LOG.debug("Executing query with identifier {}: {}", identifier, sql);
    List<String> results = ebJdbcTemplate.query(sql, new String[] { identifier }, new RowMapper<String>() {
        @Override/*  w  w w  .j a va2 s  .c  o  m*/
        public String mapRow(ResultSet rs, int rowNum) throws SQLException {
            return rs.getString(1);
        }
    });
    if (CollectionUtils.isEmpty(results)) {
        throw new RuntimeException("No persistent_id found for user_uuid(" + identifier + ")");
    }
    LOG.debug("Numer of results from query: {}", results.size());
    return results.get(0);
}