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:net.kamhon.ieagle.function.user.dao.mysql.UserDetailsSqlDaoImpl.java

public List<UserAccess> findUserAuthorizedAccess(String userId) {
    String sql = " select ra.access_code, " //
            + " sum(case when ra.create_mode then 1 else 0 end) create_mode, " //
            + " sum(case when ra.read_mode then 1 else 0 end) read_mode, " //
            + " sum(case when ra.update_mode then 1 else 0 end) update_mode, " //
            + " sum(case when ra.delete_mode then 1 else 0 end) delete_mode, " //
            + " sum(case when ra.admin_mode then 1 else 0 end) admin_mode " //
            + " from " //
            + " app_user u " //
            + " inner join app_user_in_role ur on u.user_id = ur.user_id " //
            + " inner join app_user_role r on r.role_id = ur.role_id " //
            + " inner join app_user_role_access ra on r.role_id = ra.role_id " //
            + " where u.user_id = ? and r.status=? " //
            + " group by ra.access_code " //
            + " order by ra.access_code ";

    List<Object> params = new ArrayList<Object>();
    params.add(userId);//  w  w w.j  a v a 2s. c  o m
    params.add(FrameworkConst.STATUS_APPROVED);

    List<UserAccess> userAccesses = (List<UserAccess>) query(sql, new RowMapper<UserAccess>() {
        public UserAccess mapRow(ResultSet rs, int arg1) throws SQLException {
            UserAccess userAccess = new UserAccess(false);
            userAccess.setAccessCode(rs.getString("ACCESS_CODE"));
            userAccess.setCreateMode(rs.getInt("CREATE_MODE") >= 1);
            userAccess.setReadMode(rs.getInt("READ_MODE") >= 1);
            userAccess.setUpdateMode(rs.getInt("UPDATE_MODE") >= 1);
            userAccess.setDeleteMode(rs.getInt("DELETE_MODE") >= 1);
            userAccess.setAdminMode(rs.getInt("ADMIN_MODE") >= 1);

            return userAccess;
        }
    }, params.toArray());

    return userAccesses;
}

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

/**
 * Load a collection of FinancialTypeBeans.
 *
 * @param type the type/*from  w w  w  . j av a  2 s  .  c  om*/
 *
 * @return the collection< financial type bean>
 *
 * @throws SFSDaoException the SFS dao exception
 */
@SuppressWarnings("unchecked")
public final Collection<FinancialTypeBean> load(final String type) throws SFSDaoException {
    if (type == null) {
        throw new SFSDaoException("Error: type cannot be null");
    }
    if (type.compareTo("") == 0) {
        throw new SFSDaoException("Error: type cannot be an empty string");
    }

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

    try {
        listItems = this.getJdbcTemplateReader().query(this.getSQL().getValue("financialType/load"),
                new Object[] { type }, 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 listItems;
}

From source file:eionet.transfer.dao.UserManagementServiceJdbc.java

@Override
public List<UserDetails> getAllUsers() {
    return getJdbcTemplate().query(DEF_GET_ALL_USERS_SQL, new String[] {}, new RowMapper<UserDetails>() {
        public UserDetails mapRow(ResultSet rs, int rowNum) throws SQLException {
            String username = rs.getString(1);
            String password = rs.getString(2);
            boolean enabled = rs.getBoolean(3);
            return new User(username, password, enabled, true, true, true, loadUserAuthorities(username));
        }/*from w ww. j a v a  2  s  .co  m*/

    });
}

From source file:nl.surfnet.coin.teams.service.impl.TeamExternalGroupDaoImpl.java

@Override
public ExternalGroup getExternalGroupByIdentifier(String identifier) {
    Object[] args = { identifier };

    try {/*from w w  w . j av  a2 s  .c o m*/
        return this.jdbcTemplate.queryForObject("SELECT * FROM external_groups AS eg WHERE eg.identifier = ?",
                args, new RowMapper<ExternalGroup>() {
                    @Override
                    public ExternalGroup mapRow(ResultSet rs, int rowNum) throws SQLException {

                        final ExternalGroup e = new ExternalGroup();
                        e.setId(rs.getLong("id"));
                        e.setIdentifier(rs.getString(IDENTIFIER));
                        e.setDescription(rs.getString(DESCRIPTION));
                        e.setName(rs.getString(NAME));
                        e.setGroupProviderIdentifier(rs.getString(GROUP_PROVIDER));
                        return e;
                    }
                });
    } catch (EmptyResultDataAccessException er) {
        return null;
    }
}

From source file:com.rakesh.rp3599.repository.ApplicationRepository.java

public Application findByName(String name) {
    return jdbcTemplate.queryForObject(ApplicationUtil.SELECT_AGENCY_BY_NAME, new Object[] { name },
            new RowMapper<Application>() {
                public Application mapRow(ResultSet rs, int rowNum) throws SQLException {
                    Application e = new Application();
                    e.setId(rs.getInt("id"));
                    e.setCompanyName(rs.getString("company_name"));
                    return e;
                }/*  w ww.j  a  va2  s  .c o  m*/
            });
}

From source file:dao.BankDao.java

public List<Bank> getAllBanks() {

    logger.info("run");

    return jdbc.query("SELECT * FROM banktable", new RowMapper<Bank>() {

        @Override//from  w w  w  .  ja  va2  s.co m
        public Bank mapRow(ResultSet rs, int rowNum) throws SQLException {
            return readOneBank(rs);
        }
    });
}

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

/**
 * Used to get a Collection of ExpenseClaimBean details for a specified GUID number.
 *
 * @param guid the guid//from www  . ja  va 2  s  .  co m
 * @param fullResults the full results
 * @return the collection
 * @throws WhichDoctorDaoException the which doctor dao exception
 */
@SuppressWarnings("unchecked")
public final Collection<ExpenseClaimBean> load(final int guid, final boolean fullResults)
        throws WhichDoctorDaoException {

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

    final String loadSQL = getSQL().getValue("expenseclaim/load")
            + " WHERE expenseclaim.Active = true AND expenseclaim.ReferenceGUID = ?"
            + " ORDER BY expenseclaim.ExpenseDate";

    Collection<ExpenseClaimBean> expenseClaims = new ArrayList<ExpenseClaimBean>();

    try {
        expenseClaims = this.getJdbcTemplateReader().query(loadSQL, new Object[] { guid }, new RowMapper() {
            public Object mapRow(final ResultSet rs, final int rowNum) throws SQLException {
                return loadExpenseClaim(rs);
            }
        });

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

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

public List<Advisor> findAdvisorByMatter(final Integer matterId, String title, final int limit) {
    String sql = "Select * From plugin_online_advisory "
            + "Where matter_id = ? And title Like ? And checked = true " + "Order By date Desc";
    title = (title == null || title.trim().length() == 0) ? "%" : "%" + title + "%";

    return jdbcTemplate.query(sql, new Object[] { matterId, title }, new RowMapper<Advisor>() {

        @Override// w ww  .  j  a  v a  2s . c  o m
        public Advisor mapRow(ResultSet rs, int rowNum) throws SQLException {
            Advisor advisor = new Advisor();
            advisor.setId(rs.getInt("id"));
            advisor.setTitle(rs.getString("title"));
            advisor.setName(rs.getString("name"));
            advisor.setState(rs.getInt("state"));
            advisor.setDate(rs.getDate("date"));
            return advisor;
        }
    });
}

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

@Override
public List<Course> search(String param) {
    final String parameter = param;
    PreparedStatementSetter setter = new PreparedStatementSetter() {

        @Override//w  ww .  j  a  va2  s. c  o m
        public void setValues(PreparedStatement ps) throws SQLException {
            ps.setString(1, "%" + parameter + "%");
        }
    };

    return jdbcTemplate.query(SqlConstant.COURSE_SEARCH, setter, new RowMapper<Course>() {

        @Override
        public Course mapRow(ResultSet rs, int i) throws SQLException {
            return mapData(rs);
        }
    });
}

From source file:org.ohdsi.webapi.service.TherapyPathResultsService.java

@Path("reports")
@GET//from  ww w .j  a  va  2  s . co  m
@Produces(MediaType.APPLICATION_JSON)
public List<TherapyPathReport> getReports(@PathParam("sourceKey") String sourceKey) {
    try {

        Source source = getSourceRepository().findBySourceKey(sourceKey);
        String tableQualifier = source.getTableQualifier(SourceDaimon.DaimonType.Results);

        String sql_statement = ResourceHelper
                .GetResourceAsString("/resources/therapypathresults/sql/getTherapyPathReports.sql");
        sql_statement = SqlRender.renderSql(sql_statement, new String[] { "OHDSI_schema" },
                new String[] { tableQualifier });
        sql_statement = SqlTranslate.translateSql(sql_statement, "sql server", source.getSourceDialect());
        return getSourceJdbcTemplate(source).query(sql_statement, new RowMapper<TherapyPathReport>() {
            @Override
            public TherapyPathReport mapRow(final ResultSet rs, final int arg1) throws SQLException {
                final TherapyPathReport report = new TherapyPathReport();
                report.reportId = rs.getInt(1);
                report.reportCaption = rs.getString(2);
                report.year = Integer.toString(rs.getInt(3));

                if (report.year.equals("9999")) {
                    report.year = "All Years";
                }

                report.disease = rs.getString(4);
                report.datasource = rs.getString(5);
                return report;
            }
        });
    } catch (Exception exception) {
        throw new RuntimeException("Error getting therapy path reports" + exception.getMessage());
    }
}