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.iucosoft.eavertizare.dao.impl.ConfiguratiiDaoImpl.java

@Override
public Configuratii findById(int idConfiguratie) {

    String query = "select * from configuratii_db where id = ?";
    JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);

    //using RowMapper anonymous class, we can create a separate RowMapper for reuse
    Configuratii configuratii = jdbcTemplate.queryForObject(query, new Object[] { idConfiguratie },
            new RowMapper<Configuratii>() {

                @Override//w w w .  j a v a  2 s  .c o m
                public Configuratii mapRow(ResultSet rs, int i) throws SQLException {

                    Configuratii configuratie = new Configuratii();
                    configuratie.setId(rs.getInt(1));
                    configuratie.setDriver(rs.getString(2));
                    configuratie.setUrlDb(rs.getString(3));
                    configuratie.setUsername(rs.getString(4));
                    configuratie.setPassword(rs.getString(5));
                    configuratie.setTabelaClienti(rs.getString(6));
                    return configuratie;
                }
            });

    return configuratii;
}

From source file:edu.uca.aca2016.impulse.repository.ClientDAO.java

/**
 *getClientsList method and SQL query//from w  w  w . j a v a2 s.  c o  m
 * @return
 */
public List<Client> getClientsList() {
    return template.query("SELECT * FROM client", new RowMapper<Client>() {
        @Override
        public Client mapRow(ResultSet rs, int row) throws SQLException {
            Client c = new Client();
            c.setClientid(rs.getInt("ClientId"));
            c.setFirstName(rs.getString("FirstName"));
            c.setLastName(rs.getString("LastName"));
            c.setAddress1(rs.getString("Address1"));
            c.setAddress2(rs.getString("Address2"));
            c.setCity(rs.getString("City"));
            c.setState(rs.getString("State"));
            c.setZip(rs.getString("Zip"));
            c.setEmail(rs.getString("Email"));
            c.setPhone(rs.getString("Phone"));
            c.setStatus(rs.getString("Status"));
            return c;
        }
    });
}

From source file:co.jirm.spring.SpringJdbcSqlExecutor.java

@Override
protected <T> Optional<T> doQueryForOptional(String sql, final JdbcResultSetRowMapper<T> rowMapper,
        Object[] objects) {/* w  w  w. j  a  va  2s  . c o m*/
    try {
        T object = jdbcTemplate.queryForObject(sql, new RowMapper<T>() {
            @Override
            public T mapRow(ResultSet rs, int rowNum) throws SQLException {
                return rowMapper.mapRow(rs, rowNum);
            }
        }, objects);
        return Optional.of(object);
    } catch (EmptyResultDataAccessException e) {
        return Optional.absent();
    }
}

From source file:shell.framework.organization.role.service.impl.TblSysRoleService4JdbcImpl.java

public VOResult findByPagination(int currentPage, int pageSize, TblSysRoleVO sysRoleVO) {
    VOResult voResult = new VOResult();
    StringBuffer sql = new StringBuffer();
    sql.append("select * from TBL_SYS_ROLE role where role.IS_VALID='" + SystemParam.IS_VALID + "'");
    if (sysRoleVO != null && sysRoleVO.getRole() != null && !"".equals(sysRoleVO.getRole().getName())) {
        sql.append(" and role.NAME like '%" + sysRoleVO.getRole().getName().trim() + "%'");
    }//ww  w .  j ava 2  s. c  o m

    voResult = 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 {
            TblSysRole sysRole = new TblSysRole();
            Map<String, String> propertyMap = new HashMap<String, String>();
            propertyMap.put("isValid", "IS_VALID");
            propertyMap.put("isVirtual", "IS_VIRTUAL");
            PopulateUtil.populate(sysRole, rs, propertyMap);
            return sysRole;
        }

    }, currentPage, pageSize);
    return voResult;
}

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

/**
 * Load a collection of ObjectTypeBeans.
 *
 * @param type the type//w  w  w. j  a  va  2s  .c o m
 *
 * @return the collection< object type bean>
 *
 * @throws SFSDaoException the SFS dao exception
 */
@SuppressWarnings("unchecked")
public final Collection<ObjectTypeBean> load(final String type) throws SFSDaoException {

    if (StringUtils.isBlank(type)) {
        throw new SFSDaoException("Error: type cannot be an empty string");
    }
    dataLogger.info("List items for: " + type + " requested");

    Collection<ObjectTypeBean> listItems = new ArrayList<ObjectTypeBean>();

    try {
        listItems = this.getJdbcTemplateReader().query(this.getSQL().getValue("objectType/load"),
                new Object[] { type }, new RowMapper() {
                    public Object mapRow(final ResultSet rs, final int rowNum) throws SQLException {
                        return loadObject(rs);
                    }
                });

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

From source file:com.ewcms.component.gwh.dao.GwhDAO.java

public List<ArticleVO> findGwhArticleList(String beginDate, String endDate, String searchChannel,
        String searchRange, String searchKey) {
    if (searchChannel == null || searchChannel.trim().length() == 0)
        return new ArrayList<ArticleVO>();

    if (beginDate == null || beginDate.length() == 0)
        beginDate = "1950-01-01";
    if (endDate == null || endDate.length() == 0)
        endDate = "2050-01-01";
    searchKey = "%" + searchKey + "%";
    if (searchRange.equals("1")) {
        String sql = "Select * " + "From content_article as t1,content_article_main as t2 "
                + "where t1.id=t2.article_id and t2.channel_id=? and t1.title like ? and t1.status='RELEASE' and  t1.published>=? and t1.published<=?";
        Object[] params = new Object[] { searchChannel, searchKey, beginDate, endDate };
        List<ArticleVO> list = jdbcTemplate.query(sql, params, new RowMapper<ArticleVO>() {

            @Override//from w  ww  .j a  v a 2s  . c  o  m
            public ArticleVO mapRow(ResultSet rs, int rowNum) throws SQLException {
                return articleRowMapper(rs);
            }
        });
        return list;
    }

    if (searchRange.equals("2")) {
        String sql = "Select * "
                + "From content_article as t1,content_article_main as t2 ,content_content as t3 "
                + "where t1.id=t2.article_id and t1.id=t3.article_id and t2.channel_id=? and t3.detail like ?  and t1.status='RELEASE' and  t1.published>=? and t1.published<=?";
        Object[] params = new Object[] { searchChannel, searchKey, beginDate, endDate };
        List<ArticleVO> list = jdbcTemplate.query(sql, params, new RowMapper<ArticleVO>() {
            @Override
            public ArticleVO mapRow(ResultSet rs, int rowNum) throws SQLException {
                return articleRowMapper(rs);
            }
        });
        return list;
    }
    if (searchRange.equals("3")) {
        String sql = "Select * " + "From content_article as t1,content_article_main as t2 "
                + "where t1.id=t2.article_id and t2.channel_id=? and t1.sub_title like ? and t1.status='RELEASE' and  t1.published>=? and t1.published<=?";
        Object[] params = new Object[] { searchChannel, searchKey, beginDate, endDate };
        List<ArticleVO> list = jdbcTemplate.query(sql, params, new RowMapper<ArticleVO>() {
            @Override
            public ArticleVO mapRow(ResultSet rs, int rowNum) throws SQLException {
                return articleRowMapper(rs);
            }
        });
        return list;

    }
    return null;
}

From source file:com.leapfrog.academyspring.dao.impl.CourseDAOImpl.java

@Override
public Course getById(int id) {
    return jdbcTemplate.queryForObject(SQLConstants.COURSE_GETBYID, new Object[] { id },
            new RowMapper<Course>() {

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

From source file:mylife.respository.client1DAO.java

/**
 *
 * @return//from  ww w .j  a  v  a 2  s .  c o m
 */
public List<client1> getclient1List() {
    return template.query("SELECT * FROM client1", new RowMapper<client1>() {
        public client1 mapRow(ResultSet rs, int row) throws SQLException {
            client1 c = new client1();
            c.setIdclient1(rs.getInt("client1Id"));
            c.setFirstname(rs.getString(" First_Name"));
            c.setLastname(rs.getString("Last_Name"));
            c.setAddressline1(rs.getString("Address_Line1"));
            c.setAddressline2(rs.getString("Address_Line2"));
            c.setCity(rs.getString("City"));
            c.setState(rs.getString("State"));
            c.setZip(rs.getString("Zip"));
            c.setEmail(rs.getString("Email"));
            c.setCurrent_status(rs.getString("Current_status"));
            c.setPhone_number(rs.getString("Phone_number"));
            return c;
        }
    });
}

From source file:edu.uca.aca2016.impulse.repository.InteractionsDAO.java

/**
 *List<Interactions> getInteractionsList method and SQL Query
 * @param id//from  ww  w.j  a  va2 s . com
 * @return
 */
public List<Interactions> getInteractionsList(int id) {
    return template.query("SELECT * FROM Interactions WHERE ClientId = " + id, new RowMapper<Interactions>() {
        @Override
        public Interactions mapRow(ResultSet rs, int row) throws SQLException {
            Interactions i = new Interactions();
            i.setInteractionId(rs.getInt(1));
            i.setClientid(rs.getInt(2));
            i.setOccurredOn(rs.getNString(3));
            i.setContactPerson(rs.getString(4));
            i.setContactType(rs.getString(5));
            i.setNotes(rs.getString(6));
            return i;
        }
    });

}

From source file:org.tibetjungle.demo.dao.ContactDaoImpl.java

public List<Contact> findAll() {
    return getJdbcTemplate().query("select id, contact_name, email from contacts order by id",
            new RowMapper<Contact>() {
                public Contact mapRow(ResultSet rs, int rowNum) throws SQLException {
                    return mapContact(rs);
                }// ww w .  jav a  2s . com
            });
}