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.arcane.dao.Impl.UserDaoImpl.java

@Override
public List<User> list() {
    //return all users
    LOG.info("Returning all the users");
    JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
    String sql = "SELECT * from user";
    List<User> listUser = jdbcTemplate.query(sql, new RowMapper<User>() {

        @Override//from ww  w .  j ava  2  s  .  c  o  m
        public User mapRow(ResultSet rs, int rowNumber) throws SQLException {
            User user = new User();
            user.setUserid(rs.getInt("userid"));
            user.setUsername(rs.getString("username"));
            user.setPassword(rs.getString("password"));
            return user;
        }

    });
    return listUser;
}

From source file:com.pagodalabs.institute.dao.impl.CourseDAOImpl.java

@Override
public List<Course> getAll() {
    String sql = "SELECT * FROM courses";
    List<Course> courseList = jdbcTemplate.query(sql, new RowMapper<Course>() {

        @Override/*from   w w w . jav  a  2s .co  m*/
        public Course mapRow(ResultSet rs, int i) throws SQLException {
            Course course = new Course();
            course.setId(rs.getInt("course_id"));
            course.setName(rs.getString("course_name"));
            course.setDescription(rs.getString("course_description"));
            course.setStatus(rs.getBoolean("status"));
            return course;
        }
    });
    return courseList;
}

From source file:com.jaxio.celerio.configuration.database.mysql.MysqlMetaAttributesExtension.java

private void processYearTypes(JdbcTemplate jdbcTemplate, final Metadata metadata, final Table table) {
    jdbcTemplate.query("show columns from " + table.getName(), new RowMapper<Void>() {
        @Override/*from ww w.j  av a 2s . co  m*/
        public Void mapRow(ResultSet rs, int rowNum) throws SQLException {
            Column column = table.getColumnByName(rs.getString("Field"));
            column.addMetaAttribute(new MetaAttribute("type", rs.getString("Type")));
            String extra = rs.getString("Extra");
            if (isNotBlank(extra)) {
                column.addMetaAttribute(new MetaAttribute("extra", trim(extra)));
            }
            return null;
        }
    });
}

From source file:com.neupane.springJDBC.DAO.Impl.CustomerDAOImpl.java

@Override
public List<Customer> getAll() throws ClassNotFoundException, SQLException {
    String sql = "SELECT * FROM customer";
    return jdbcTemplet.query(sql, new RowMapper<Customer>() {

        @Override/*w w  w  .java2  s .  co m*/
        public Customer mapRow(ResultSet rs, int i) throws SQLException {
            Customer cust = new Customer();
            cust.setCustomerId(rs.getInt("id"));
            cust.setFirstName(rs.getString("first_name"));
            cust.setLastName(rs.getString("last_name"));
            cust.setAddress(rs.getString("address"));
            cust.setEmail(rs.getString("email"));
            cust.setContact(rs.getInt("contact"));
            cust.setStatus(Boolean.parseBoolean(rs.getString("status")));
            return cust;
        }
    });
}

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

private List<ArchiveDTO> getArchiveInternal(final Section section, final Group group, int limit) {
    RowMapper<ArchiveDTO> mapper = new RowMapper<ArchiveDTO>() {
        @Override//from  w w  w . j av a2  s . com
        public ArchiveDTO mapRow(ResultSet rs, int rowNum) throws SQLException {
            ArchiveDTO dto = new ArchiveDTO();
            dto.setYear(rs.getInt("year"));
            dto.setMonth(rs.getInt("month"));
            dto.setCount(rs.getInt("c"));
            dto.setSection(section);
            dto.setGroup(group);
            return dto;
        }
    };

    if (limit > 0) {
        return jdbcTemplate.query("select year, month, c from monthly_stats where section=? and groupid is null"
                + " order by year desc, month desc limit ?", mapper, section.getId(), limit);
    } else {
        if (group == null) {
            return jdbcTemplate
                    .query("select year, month, c from monthly_stats where section=? and groupid is null"
                            + " order by year, month", mapper, section.getId());
        } else {
            return jdbcTemplate.query(
                    "select year, month, c from monthly_stats where section=? and groupid=? order by year, month",
                    mapper, section.getId(), group.getId());
        }
    }
}

From source file:com.javacodegags.waterflooding.model.ThermImplemented.java

@Override
public List<Therm> getList() {
    String sql = "SELECT therm_set.id,therm_set.name " + "FROM therm_set ;";
    List<Therm> listTherm = jdbcTemplate.query(sql, new RowMapper<Therm>() {
        @Override//from  w  w  w.  j  a v a 2 s.  c o m
        public Therm mapRow(ResultSet rs, int i) throws SQLException {
            Therm therm = new Therm();
            therm.setId(rs.getInt("id"));
            therm.setName(rs.getString("name"));
            return therm;
        }
    });
    return listTherm;
}

From source file:com.ewcms.component.auth.dao.UserDAO.java

@Override
public User getUser(String username) {
    String sql = "Select * From component_auth_user Where username = ?";

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

        @Override/*from   w w  w.  j  a v a2s  .c  o m*/
        public User mapRow(ResultSet rs, int rowNum) throws SQLException {
            User user = new User();
            user.setUsername(rs.getString("username"));
            user.setName(rs.getString("name"));
            user.setEmail(rs.getString("email"));
            user.setPassword(rs.getString("password"));
            user.setEnabled(rs.getBoolean("enabled"));
            user.setRegisterDate(rs.getTimestamp("register_date"));

            return user;
        }
    });

    return list.isEmpty() ? null : list.get(0);
}

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

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

        @Override/*  w w  w . j a v  a  2  s .  c  om*/
        public Checkin mapRow(ResultSet rs, int i) throws SQLException {
            return mapData(rs);
        }
    });
}

From source file:com.karki.spring.dao.impl.CourseDaoImpl.java

@Override
public List<Course> getAll() throws ClassNotFoundException, SQLException {
    return jdbcTemplate.query(CourseSQL.GETALL, new RowMapper<Course>() {

        @Override//from w w  w .ja  v a2 s  . co m
        public Course mapRow(ResultSet rs, int i) throws SQLException {
            return mapData(rs);
        }
    });
}