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:org.spirit.apps.jdbc.GenericRuntimeJDBCDao.java

/**
 * select first_name, surname from t_actor"
 * /*from  w ww .jav a2 s. c om*/
 * @param count_sql
 * @return
 */
public Collection jdbcQuerySystemFeedItems(final String sql) {
    if (this.jdbcTemplate == null) {
        return new ArrayList();
    }
    Collection feed_items = this.jdbcTemplate.query(sql, new RowMapper() {
        public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
            SystemFeedItemsType feed_item = new SystemFeedItemsType();
            feed_item.setId(new Long(rs.getLong("id")));
            feed_item.setMainUrl(rs.getString("main_url"));
            return feed_item;
        }
    });
    return feed_items;
}

From source file:nl.ordina.bag.etl.dao.AbstractBAGMutatiesDAO.java

@Override
public MutatiesFile getNexMutatiesFile() throws DAOException {
    try {/*from  w  ww. j a  v a  2  s. c om*/
        MutatiesFile file = jdbcTemplate.queryForObject(
                "select *" + " from bag_mutaties_file"
                        + " where date_from = (select (max(date_to)) from bag_mutaties_file where status = "
                        + ProcessingStatus.PROCESSED.ordinal() + ")", // + 
                //" union all" + 
                //" select *" +
                //" from bag_mutaties_file" +
                //" where date_from = (select (min(date_from)) from bag_mutaties_file where status = " + ProcessingStatus.UNPROCESSED.ordinal() + 
                //" and (select count(id) from bag_mutaties_file where status = " + ProcessingStatus.PROCESSED.ordinal() + ") = 0)",
                new RowMapper<MutatiesFile>() {
                    @Override
                    public MutatiesFile mapRow(ResultSet rs, int row) throws SQLException {
                        MutatiesFile object = new MutatiesFile();
                        object.setId(rs.getLong("id"));
                        object.setDateFrom(rs.getDate("date_from"));
                        object.setDateTo(rs.getDate("date_to"));
                        object.setContent(rs.getBytes("content"));
                        object.setStatus(ProcessingStatus.values()[rs.getInt("status")]);
                        return object;
                    }
                });
        return file;
    } catch (IncorrectResultSizeDataAccessException e) {
        return null;
    } catch (DataAccessException e) {
        throw new DAOException(e);
    }
}

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

public List<Working> getChildren(Integer id) {
    String sql = "Select t1.id As t1_id,t1.name As t1_name,t3.id As t3_id,t3.name As t3_name "
            + "From plugin_workingbody t1 "
            + "LEFT JOIN plugin_workingbody_organ t2 ON  t1.id = t2.workingbody_id "
            + "LEFT JOIN site_organ t3 ON  t2.organ_id = t3.id " + "Where t1.parent_id=? "
            + "Order By sort Asc";

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

        @Override/*from   w  w w  . j  a v a 2 s. co m*/
        public Working mapRow(ResultSet rs, int rowNum) throws SQLException {
            Working working = new Working();
            working.setId(rs.getInt("t1_id"));
            working.setName(rs.getString("t1_name"));
            working.setOrgan(new Organ(rs.getInt("t3_id"), rs.getString("t3_name")));
            return working;
        }
    });
}

From source file:com.nortal.petit.orm.statement.LoadStatement.java

public byte[] getBlobAsBytes() {
    return (byte[]) getJdbcTemplate().queryForObject(getSql(), getParams(null), new RowMapper<byte[]>() {
        @Override//w w  w  .  ja v  a2 s  . com
        public byte[] mapRow(ResultSet rs, int rowNum) throws SQLException {
            return new DefaultLobHandler().getBlobAsBytes(rs, 1);
        }
    });
}

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

/**
 * Used to get a Collection of RelationshipBeans for a specified GUID.
 *
 * @param guid the guid/*w w w  .  j  ava 2 s.com*/
 * @param loadDetails the load details
 * @return the collection of relationship beans
 * @throws WhichDoctorDaoException the which doctor dao exception
 */
@SuppressWarnings("unchecked")
public final Collection<RelationshipBean> load(final int guid, final BuilderBean loadDetails)
        throws WhichDoctorDaoException {

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

    final String loadRelationships = this.getSQL().getValue("relationship/load")
            + " AND relationships.GUID = ?";

    Collection<RelationshipBean> relationships = new ArrayList<RelationshipBean>();

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

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

From source file:com.github.dbourdette.glass.log.execution.jdbc.JdbcJobExecutions.java

private Page<JobExecution> getLogs(String sqlBase, SqlParameterSource params, Query query) {
    String sql = query.applySqlLimit("select * " + sqlBase + " order by startDate desc");

    List<JobExecution> executions = jdbcTemplate.query(sql, params, new RowMapper<JobExecution>() {
        @Override//from w w w  . j ava2 s.c o m
        public JobExecution mapRow(ResultSet rs, int rowNum) throws SQLException {
            JobExecution execution = new JobExecution();

            execution.setId(rs.getLong("id"));
            execution.setStartDate(rs.getTimestamp("startDate"));
            execution.setEndDate(rs.getTimestamp("endDate"));
            execution.setEnded(rs.getBoolean("ended"));
            execution.setJobGroup(rs.getString("jobGroup"));
            execution.setJobName(rs.getString("jobName"));
            execution.setTriggerGroup(rs.getString("triggerGroup"));
            execution.setTriggerName(rs.getString("triggerName"));
            execution.setJobClass(rs.getString("jobClass"));
            execution.setDataMap(rs.getString("dataMap"));
            execution.setResult(JobExecutionResult.valueOf(rs.getString("result")));

            return execution;
        }
    });

    String countSql = "select count(*) " + sqlBase;

    Page<JobExecution> page = Page.fromQuery(query);

    page.setItems(executions);
    page.setTotalCount(jdbcTemplate.queryForInt(countSql, params));

    return page;
}

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

/**
 * Load a FinancialTypeBean for the supplied parameters.
 *
 * @param object the object//from  w  w  w .  ja  v  a2  s.  com
 * @param financialType the financial type
 * @param objectClass the object class
 *
 * @return the financial type bean
 *
 * @throws SFSDaoException the SFS dao exception
 */
public final FinancialTypeBean load(final String object, final String financialType, final String objectClass)
        throws SFSDaoException {
    if (object == null) {
        throw new SFSDaoException("Finance Object definition cannot be null");
    }
    if (financialType == null) {
        throw new SFSDaoException("Finance Type cannot be null");
    }
    if (objectClass == null) {
        throw new SFSDaoException("Finance Class canot be null");
    }

    FinancialTypeBean financialTypeBean = null;

    try {
        financialTypeBean = (FinancialTypeBean) this.getJdbcTemplateReader().queryForObject(
                this.getSQL().getValue("financialType/loadType"),
                new Object[] { object, financialType, objectClass }, new RowMapper() {
                    public Object mapRow(final ResultSet rs, final int rowNum) throws SQLException {
                        return loadDetails(rs);
                    }
                });

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

From source file:com.expedia.seiso.domain.repo.impl.ServiceInstanceRepoImpl.java

@Override
public NodeSummary getServiceInstanceNodeSummary(@NonNull Long id) {
    val mapper = new RowMapper<NodeSummary>() {
        @Override/*  w  ww . j  a v a2s .c o m*/
        public NodeSummary mapRow(ResultSet rs, int rowNum) throws SQLException {
            return new NodeSummary(rs.getInt(1), rs.getInt(2), rs.getInt(3), rs.getInt(4));
        }
    };
    return jdbcTemplate.query(NODE_SUMMARY_SQL, args(id), mapper).get(0);
}

From source file:com.ewcms.component.interaction.dao.InteractionDAO.java

@Override
public List<Organ> getOrganChildren(Integer id) {
    String sql = "Select id,name From site_organ Where parent_id = ? Order By id asc";
    return jdbcTemplate.query(sql, new Object[] { id }, new RowMapper<Organ>() {

        @Override/*www.  j av  a2 s.c o  m*/
        public Organ mapRow(ResultSet rs, int rowNum) throws SQLException {
            return organRowMapper(rs);
        }
    });
}