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.sfs.whichdoctor.dao.IsbPayloadDAOImpl.java

/**
 * Used to get a IsbPayloadBean for the the specified ISB Payload Id.
 * Returns null if no isb message found/*from   w w  w .ja v a2s.c o m*/
 *
 * @param isbPayloadId the isb payload id
 *
 * @return the isb payload bean
 *
 * @throws WhichDoctorDaoException the which doctor dao exception
 */
public final IsbPayloadBean load(final int isbPayloadId) throws WhichDoctorDaoException {
    dataLogger.info("ISB payload id: " + isbPayloadId + " requested");

    IsbPayloadBean isbPayload = null;

    try {
        isbPayload = (IsbPayloadBean) this.getIsbJdbcTemplate().queryForObject(
                this.getSQL().getValue("isbpayload/loadId"), new Object[] { isbPayloadId }, new RowMapper() {
                    public Object mapRow(final ResultSet rs, final int rowNum) throws SQLException {
                        return loadIsbPayloadBean(rs);
                    }
                });

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

From source file:com.leapfrog.inventorymanagementsystem.dao.impl.CategoryDAOImpl.java

@Override
public Category getById(int id) throws SQLException, ClassNotFoundException {
    String sql = "SELECT * FROM tbl_category WHERE category_id =?";
    return jdbcTemplate.queryForObject(sql, new Object[] { id }, new RowMapper<Category>() {

        @Override/* w ww.  j  a v  a 2s  . c o  m*/
        public Category mapRow(ResultSet rs, int i) throws SQLException {
            Category c = new Category();
            c.setId(rs.getInt("category_id"));
            c.setCategoryName(rs.getString("category_name"));

            return c;
        }
    });
}

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

public List<TopTenMessageDTO> getMessages() {
    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 notop is null "
            + " and groupid!=8404 and groupid!=4068 order by c desc, msgid limit 10";

    return jdbcTemplate.query(sql, new RowMapper<TopTenMessageDTO>() {
        @Override//from www.j a va  2s  .  c  o m
        public TopTenMessageDTO mapRow(ResultSet rs, int i) throws SQLException {
            TopTenMessageDTO result = new TopTenMessageDTO();
            result.setUrl(sectionService.getSection(rs.getInt("section")).getSectionLink()
                    + rs.getString("urlname") + '/' + rs.getInt("msgid"));
            result.setTitle(rs.getString("title"));
            result.setLastmod(rs.getTimestamp("lastmod"));
            result.setAnswers(rs.getInt("c"));
            return result;
        }
    });
}

From source file:com.abcd.employeemaven.dao.impl.EmployeeDaoImpl.java

@Override
public List<Employee> getByDepartmentId(int id) {
    return jdbcTemplate.query(EmployeeSQL.GETDEPAARTMENTID, new Object[] { id }, new RowMapper<Employee>() {

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

From source file:org.smigo.species.JdbcRuleDao.java

@Override
public List<Rule> getRules() {
    final Map<Integer, List<Integer>> impacts = getImpacts();
    return jdbcTemplate.query(SELECT, new RowMapper<Rule>() {
        @Override//from w w  w.j a  v a2 s  .  c  o m
        public Rule mapRow(ResultSet rs, int rowNum) throws SQLException {
            final int id = rs.getInt("id");
            final int host = rs.getInt("host");
            final int type = rs.getInt("type");
            final int causerSpecies = rs.getInt("causer"); //todo rename to causerspecies
            final int causerFamily = rs.getInt("causerfamily");
            final int gap = rs.getInt("gap"); //todo should return null if not set
            return Rule.create(id, host, type, causerSpecies, causerFamily, gap, impacts.get(id));
        }
    });
}

From source file:nl.surfnet.coin.db.InMemoryDatabaseTest.java

@Test
public void testDatabaseTemplate() throws Exception {
    List<String> result = getJdbcTemplate().query("select user_id from example_table", new RowMapper<String>() {
        @Override//  ww  w . j a  va2s .  co m
        public String mapRow(ResultSet rs, int rowNum) throws SQLException {
            return rs.getString(1);
        }
    });
    assertEquals(1, result.size());
    assertEquals("whatever", result.get(0));
}

From source file:com.ineunet.knife.security.SysParams.java

public static String getValue(String key) {
    Asserts.notBlank(key);//from www.  jav a  2 s . c  o  m
    SysParam param = cache.get(key);
    if (param != null)
        return param.getValue();
    else {
        List<SysParam> params = PersistUtils.getJdbcTemplate()
                .query("select id,value from knife_sys_param where id=?", new RowMapper<SysParam>() {
                    @Override
                    public SysParam mapRow(ResultSet rs, int rowNum) throws SQLException {
                        SysParam sp = new SysParam();
                        sp.setId(rs.getString("id"));
                        sp.setValue(rs.getString("value"));
                        return sp;
                    }
                }, key);
        if (params.isEmpty())
            return null;
        param = params.get(0);
        cache.put(key, param);
        return param.getValue();
    }
}

From source file:de.swm.nis.logicaldecoding.dataaccess.ChangeSetFetcher.java

public List<ChangeSetDAO> fetch(String slotname, int maxRows) {

    RowMapper<ChangeSetDAO> changeSetRowMapper = new RowMapper<ChangeSetDAO>() {

        @Override/*from   w ww .j  a va2s  .c  o  m*/
        public ChangeSetDAO mapRow(ResultSet rs, int rowNum) throws SQLException {
            ChangeSetDAO changeset = new ChangeSetDAO();
            changeset.setData(rs.getString("data"));
            changeset.setLocation(rs.getString("location"));
            changeset.setTransactionId(rs.getLong("xid"));
            return changeset;
        }
    };

    //Parameter 1: replication Slot name
    //Parameter 2: upto_n_changes
    String sql = "SELECT * from pg_logical_slot_get_changes(?, NULL, ?, 'include-timestamp', 'on')";
    List<ChangeSetDAO> changes = template.query(sql, new Object[] { slotname, maxRows }, changeSetRowMapper);
    return changes;
}

From source file:database.ExerciseDAOImpl.java

public List<List> listRecentExercises() {

    // get all exercise dates
    String SQL1 = "SELECT DISTINCT date FROM exercise ORDER BY date DESC";
    List<Date> dates = template.query(SQL1, new RowMapper<Date>() {

        @Override//from   www .  jav a 2  s.com
        public Date mapRow(ResultSet rs, int rowNum) throws SQLException {
            Date dates;
            dates = rs.getDate("date");
            return dates;
        }
    });

    List<ExerciseWithParticipants> ewpList = new ArrayList<>();
    List<List> listaa = new ArrayList<>();

    // get all users and hours from exercises
    for (int i = 0; i < dates.size(); i++) {
        Date date = dates.get(i);
        String SQL = "SELECT users.firstname, users.lastname, exercise.hours, exercise.date FROM exercise INNER JOIN users ON exercise.userid=users.id WHERE exercise.date = '"
                + date + "' ORDER BY firstname ASC";
        ewpList = template.query(SQL, new EWPMapper());
        listaa.add(ewpList);
    }

    return listaa;
}

From source file:com.butler.service.ProductDao.java

public List<Product> getCompeteProducts() {
    String sql = "select name,display_name,display_position,market_price,selling_price,size,type,visible,booking_only from product  order by display_position";
    return this.getJdbcTemplate().query(sql, new RowMapper() {

        @Override/*  www . j  a v a  2s  . co  m*/
        public Object mapRow(ResultSet rs, int i) throws SQLException {
            Product product = new Product();
            product.setName(rs.getString("name"));
            product.setDisplayName(rs.getString("display_name"));
            product.setSellingPrice(rs.getFloat("selling_price"));
            product.setMarketPrice(rs.getFloat("market_price"));
            product.setSizeSpecification(rs.getString("size"));
            product.setType(rs.getString("type"));
            product.setVisible(rs.getBoolean("visible"));
            product.setDisplayPosition(rs.getInt("display_position"));
            product.setBookingOnly(rs.getBoolean("booking_only"));
            return product;
        }
    });
}