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:info.raack.appliancelabeler.service.BackupDatabase.java

public AggregatedTeds getConfigurationsFromBackupDatabase() {
    List<Ted5000> teds = jdbcTemplate.query(queryForAggregatedTeds, new RowMapper<Ted5000>() {

        public Ted5000 mapRow(ResultSet rs, int arg1) throws SQLException {
            Ted5000 ted = new Ted5000();

            ted.setId(rs.getString("tedid"));

            LinkType link = new LinkType();
            link.setRel("owner");
            link.setHref("dummy/users/" + rs.getString("username") + ".xml");
            ted.getLink().add(link);/*  w  w w.j  a v  a2 s.co m*/

            return ted;
        }
    });

    for (Ted5000 ted : teds) {
        // get mtus
        ted.getTed5000Mtu().addAll(
                jdbcTemplate.query(queryForMtusForTed, new Object[] { ted.getId() }, new RowMapper<Mtu>() {

                    public Mtu mapRow(ResultSet rs, int arg1) throws SQLException {
                        Mtu mtu = new Mtu();

                        mtu.setId(rs.getString("mtuid"));

                        return mtu;
                    }
                }));
    }

    AggregatedTeds at = new AggregatedTeds();
    at.getTed5000().addAll(teds);

    return at;
}

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

/**
 * Used to get a OrganisationBean for a specified organisationId with the
 * load details provided. A boolean parameter identifies whether to use the
 * default reader connection or optional writer connection datasource
 *
 * @param organisationId the organisation id
 * @param loadDetails the load details//from   w w  w.j ava  2 s.c o  m
 * @param useWriterConn the use writer conn
 *
 * @return the organisation bean
 *
 * @throws WhichDoctorDaoException the which doctor dao exception
 */
private OrganisationBean load(final int organisationId, final BuilderBean loadDetails,
        final boolean useWriterConn) throws WhichDoctorDaoException {

    OrganisationBean organisation = null;

    final String loadOrganisationId = getSQL().getValue("organisation/load")
            + " AND organisation.OrganisationId = ?";

    JdbcTemplate jdbcTemplate = this.getJdbcTemplateReader();
    if (useWriterConn) {
        jdbcTemplate = this.getJdbcTemplateWriter();
    }

    try {
        organisation = (OrganisationBean) jdbcTemplate.queryForObject(loadOrganisationId,
                new Object[] { organisationId }, new RowMapper() {
                    public Object mapRow(final ResultSet rs, final int rowNum) throws SQLException {
                        return loadOrganisation(rs, loadDetails);
                    }
                });

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

From source file:com.bleum.canton.jms.dao.impl.JMSTaskDao.java

@Override
public List<JMSTask> findTaskForProcessing(int type, int limit) {
    return this.jdbcTemplate.query(QUERY_TASK_FOR_PROCESSING, new Object[] { type, limit },
            new RowMapper<JMSTask>() {
                public JMSTask mapRow(ResultSet rs, int rowNum) throws SQLException {
                    JMSTask task = new JMSTask();
                    task.setId(rs.getLong("id"));
                    task.setContentId(rs.getString("content_id"));
                    task.setType(rs.getInt("type"));
                    task.setStatus(rs.getInt("status"));
                    task.setCreatedDate(rs.getDate("created_time"));
                    task.setOperatedDate(rs.getDate("operated_time"));
                    if (rs.getClob("message") != null) {
                        task.setMessage(CantonStringUtils.convertToString(rs.getClob("message")));
                    }/* w w w  . ja v a 2 s  . c om*/
                    task.setRetry(rs.getInt("retry"));
                    task.setLastError(rs.getString("last_error"));
                    return task;
                }
            });
}

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

/**
 * Load an EmailBean based on its id./*  ww w.  j  a  v  a 2s .co m*/
 *
 * @param emailId the email id
 * @return the email bean
 * @throws WhichDoctorDaoException the which doctor dao exception
 */
public final EmailBean load(final int emailId) throws WhichDoctorDaoException {

    dataLogger.info("Getting emailId:" + emailId);

    final String loadId = getSQL().getValue("email/load") + " " + getSQL().getValue("email/whereId");

    EmailBean email = null;
    try {
        email = (EmailBean) this.getJdbcTemplateReader().queryForObject(loadId, new Object[] { emailId },
                new RowMapper() {
                    public Object mapRow(final ResultSet rs, final int rowNum) throws SQLException {
                        return loadEmail(rs);
                    }
                });

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

From source file:de.langmi.spring.batch.examples.readers.support.CompositeCursorItemReaderTest.java

/**
 * Helpermethod to create a JdbcCursorItemReader, sets the name too, to make restart
 * scenario possible - otherwise one reader would overwrite the restart data from
 * the other./*from w ww  .  ja  v  a2 s. c om*/
 * 
 * @param dataSource
 * @param name for restart
 * @return
 * @throws Exception 
 */
private AbstractCursorItemReader<String> createJdbcCursorItemReader(DataSource dataSource, String name)
        throws Exception {
    JdbcCursorItemReader<String> jcir = new JdbcCursorItemReader<String>();
    jcir.setDataSource(dataSource);
    jcir.setSql(SELECT);
    jcir.setRowMapper(new RowMapper() {

        @Override
        public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
            return rs.getString(1);
        }
    });
    jcir.setName(name);
    jcir.setSaveState(true);
    // jcir.afterPropertiesSet(); not mandatory yet, just checks dataSource

    return jcir;
}

From source file:org.zenoss.zep.dao.impl.EventDetailsConfigDaoImpl.java

@Override
@TransactionalReadOnly//from  www  . j a  v a  2  s.  co m
public Map<String, EventDetailItem> getEventDetailItemsByName() throws ZepException {
    final String sql = "SELECT proto_json FROM event_detail_index_config";
    final Map<String, EventDetailItem> itemsByName = new HashMap<String, EventDetailItem>();
    this.template.query(sql, new RowMapper<Object>() {
        @Override
        public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
            EventDetailItem item = DaoUtils.protobufFromJson(rs.getString(COLUMN_PROTO_JSON),
                    EventDetailItem.getDefaultInstance());
            itemsByName.put(item.getKey(), item);
            return null;
        }
    });
    return itemsByName;
}

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

/**
 * List<Interactions> getInteractionsByPage method and SQL Query
 * @param start//from   www.j av a  2 s .c o  m
 * @param total
 * @return
 */
public List<Interactions> getInteractionssByPage(int start, int total) {
    String sql = "SELECT interactions.InteractionId, interactions.ClientId, interactions.OccuredOn, interactions.ContactPerson, interactions.ContactType, interactions.Notes, client.ClientId "
            + "FROM Interactions AS interactions "
            + "INNER JOIN Client AS client ON client.ClientId = interactions.ClientId "
            + "ORDER BY client.ClientId, interactions.OccuredOn " + "LIMIT " + (start - 1) + "," + total;
    return template.query(sql, new RowMapper<Interactions>() {
        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.getString(3));
            i.setContactPerson(rs.getString(4));
            i.setContactType(rs.getString(5));
            i.setNotes(rs.getString(6));

            Client client = new Client();
            client.setClientid(rs.getInt(1));
            client.setFirstName(rs.getString(2));

            i.setClient(client);

            return i;
        }
    });
}

From source file:om.edu.squ.squportal.portlet.dps.grade.gradechange.db.GradeChangeDBImpl.java

/**
 * //w w  w. j a  v a2s. c om
 * method name  : getStudentGrades
 * @param employeeNo
 * @param locale
 * @return
 * GradeChangeDBImpl
 * return type  : List<GradeDTO>
 * 
 * purpose      :   Grade list of a student for a particular year, semester, instructor
 *
 * Date          :   Nov 15, 2017 10:08:43 AM
 */
public List<GradeDTO> getStudentGrades(boolean isRuleGradeChangeTimingFollowed, GradeDTO gradeDTO,
        String employeeNo, final Locale locale) throws NoDBRecordException {

    String SQL_GRADE_CHANGE_STUDENT_LIST_OF_EXISTING_GRADE = queryGradeChange
            .getProperty(Constants.CONST_SQL_GRADE_CHANGE_STUDENT_LIST_OF_EXISTING_GRADE);
    YearSemester yearSemester = null;

    RowMapper<GradeDTO> rowMapper = new RowMapper<GradeDTO>() {

        @Override
        public GradeDTO mapRow(ResultSet rs, int rowNum) throws SQLException {
            GradeDTO gradeDTO = new GradeDTO();
            Course course = new Course();
            Grade grade = new Grade();
            List<Grade> grades = null;

            grades = getGrades(rs.getString(Constants.CONST_COLMN_L_ABR_CRSNO), locale);
            gradeDTO.setGrades(grades);

            gradeDTO.setSectCode(rs.getString(Constants.CONST_COLMN_SECT_CODE));
            course.setCourseNo(rs.getString(Constants.CONST_COLMN_COURSE_NO));
            course.setlAbrCourseNo(rs.getString(Constants.CONST_COLMN_L_ABR_CRSNO));
            course.setCourseName(rs.getString(Constants.CONST_COLMN_COURSE_NAME));

            grade.setGradeCode(rs.getInt(Constants.CONST_COLMN_GRADE_CODE));
            grade.setGradeVal(rs.getString(Constants.CONST_COLMN_GRADE_VAL));

            if (rs.getString(Constants.CONST_COLMN_GRADE_IS_INCOMPLETE_GRADE).equals(Constants.CONST_YES)) {
                gradeDTO.setIncompleteGrade(true);
            } else {
                gradeDTO.setIncompleteGrade(false);
            }

            gradeDTO.setStudentId(rs.getString(Constants.CONST_COLMN_STUDENT_ID));
            gradeDTO.setStudentName(rs.getString(Constants.CONST_COLMN_STUDENT_NAME));
            gradeDTO.setStudentNo(rs.getString(Constants.CONST_COLMN_STUDENT_NO));
            gradeDTO.setStdStatCode(rs.getString(Constants.CONST_COLMN_STDSTATCD));
            gradeDTO.setCourseYear(rs.getString(Constants.COST_COL_DPS_COURSE_YEAR));
            gradeDTO.setSemester(rs.getString(Constants.COST_COL_DPS_SEMESTER_CODE));

            gradeDTO.setSectionNo(rs.getString(Constants.CONST_COLMN_SECTION_NO));

            gradeDTO.setUpdatable(
                    rs.getString(Constants.CONST_COLMN_POSTPONE_GRADE_IS_UPDATABLE).equals(Constants.CONST_YES)
                            ? true
                            : false);

            if (rs.getString(Constants.CONST_COLMN_IS_CHANGE_ALLOWED).equals(Constants.CONST_YES)) {
                gradeDTO.setChangable(true);
            } else {
                gradeDTO.setChangable(false);
            }

            gradeDTO.setCourse(course);
            gradeDTO.setGrade(grade);

            return gradeDTO;
        }
    };

    yearSemester = (isRuleGradeChangeTimingFollowed) ? getRuleYearSem() : getCurrentYearSem();

    Map<String, String> namedParameterMap = new HashMap<String, String>();
    namedParameterMap.put("paramStdId", gradeDTO.getStudentId());
    namedParameterMap.put("paramYear", String.valueOf(yearSemester.getYear()));
    namedParameterMap.put("paramSem", String.valueOf(yearSemester.getSemester()));
    namedParameterMap.put("paramEmpNo", employeeNo);
    if (null == gradeDTO.getCourse().getlAbrCourseNo()
            || gradeDTO.getCourse().getlAbrCourseNo().trim().equals("")) {
        namedParameterMap.put("paramLAbrCrsNo", null);
    } else {
        namedParameterMap.put("paramLAbrCrsNo", gradeDTO.getCourse().getlAbrCourseNo());
    }
    namedParameterMap.put("paramLocale", locale.getLanguage());

    try {
        return nPJdbcTemplDpsGradeChange.query(SQL_GRADE_CHANGE_STUDENT_LIST_OF_EXISTING_GRADE,
                namedParameterMap, rowMapper);
    } catch (UncategorizedSQLException sqlEx) {
        logger.error("Error occur to find to find grade records for student id:  {} and instructor: {} ",
                gradeDTO.getStudentId(), employeeNo);
        throw new NoDBRecordException(sqlEx.getMessage());
    }

}

From source file:com.rockagen.gnext.service.spring.security.extension.JdbcFilterInvocationSecurityMetadataSourceFactoryBean.java

/**
 * Load all resource//from   ww  w . ja v  a  2s .  c om
 * @return resource list
 */
protected List<Resource> loadAllResource() {
    return getJdbcTemplate().query(resourceQuery, new RowMapper<Resource>() {
        public Resource mapRow(ResultSet rs, int rowNum) throws SQLException {
            String url = rs.getString(1);
            String role = rs.getString(2);
            return new Resource(url, role);
        }

    });
}

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

public InputStream getBlobAsBinaryStream(final String columnName) {
    return (InputStream) getJdbcTemplate().queryForObject(getSql(), getParams(null),
            new RowMapper<InputStream>() {
                @Override/*from  w w  w  .  j  a va 2s  .  c  o  m*/
                public InputStream mapRow(ResultSet rs, int rowNum) throws SQLException {
                    return new DefaultLobHandler().getBlobAsBinaryStream(rs, columnName);
                }
            });
}