Search in sources :

Example 1 with RowMapper

use of org.springframework.jdbc.core.RowMapper in project perun by CESNET.

the class MailManagerImpl method getApplicationMails.

@Override
public List<ApplicationMail> getApplicationMails(PerunSession sess, ApplicationForm form) throws PerunException {
    List<ApplicationMail> mails = new ArrayList<ApplicationMail>();
    mails = jdbc.query(MAILS_SELECT_BY_FORM_ID, new RowMapper<ApplicationMail>() {

        @Override
        public ApplicationMail mapRow(ResultSet rs, int arg1) throws SQLException {
            return new ApplicationMail(rs.getInt("id"), AppType.valueOf(rs.getString("app_type")), rs.getInt("form_id"), MailType.valueOf(rs.getString("mail_type")), rs.getBoolean("send"));
        }
    }, form.getId());
    for (ApplicationMail mail : mails) {
        List<MailText> texts = new ArrayList<MailText>();
        texts = jdbc.query(MAIL_TEXTS_SELECT_BY_MAIL_ID, new RowMapper<MailText>() {

            @Override
            public MailText mapRow(ResultSet rs, int arg1) throws SQLException {
                return new MailText(new Locale(rs.getString("locale")), rs.getString("subject"), rs.getString("text"));
            }
        }, mail.getId());
        for (MailText text : texts) {
            // fil localized messages
            mail.getMessage().put(text.getLocale(), text);
        }
    }
    return mails;
}
Also used : ResultSet(java.sql.ResultSet) MailText(cz.metacentrum.perun.registrar.model.ApplicationMail.MailText) ApplicationMail(cz.metacentrum.perun.registrar.model.ApplicationMail) RowMapper(org.springframework.jdbc.core.RowMapper)

Example 2 with RowMapper

use of org.springframework.jdbc.core.RowMapper in project spring-security-oauth by spring-projects.

the class JdbcTokenStore method getAccessToken.

public OAuth2AccessToken getAccessToken(OAuth2Authentication authentication) {
    OAuth2AccessToken accessToken = null;
    String key = authenticationKeyGenerator.extractKey(authentication);
    try {
        accessToken = jdbcTemplate.queryForObject(selectAccessTokenFromAuthenticationSql, new RowMapper<OAuth2AccessToken>() {

            public OAuth2AccessToken mapRow(ResultSet rs, int rowNum) throws SQLException {
                return deserializeAccessToken(rs.getBytes(2));
            }
        }, key);
    } catch (EmptyResultDataAccessException e) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Failed to find access token for authentication " + authentication);
        }
    } catch (IllegalArgumentException e) {
        LOG.error("Could not extract access token for authentication " + authentication, e);
    }
    if (accessToken != null && !key.equals(authenticationKeyGenerator.extractKey(readAuthentication(accessToken.getValue())))) {
        removeAccessToken(accessToken.getValue());
        // Keep the store consistent (maybe the same user is represented by this authentication but the details have
        // changed)
        storeAccessToken(accessToken, authentication);
    }
    return accessToken;
}
Also used : OAuth2AccessToken(org.springframework.security.oauth2.common.OAuth2AccessToken) ResultSet(java.sql.ResultSet) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) RowMapper(org.springframework.jdbc.core.RowMapper)

Example 3 with RowMapper

use of org.springframework.jdbc.core.RowMapper in project camel by apache.

the class DefaultSqlEndpoint method queryForStreamList.

@SuppressWarnings("unchecked")
public ResultSetIterator queryForStreamList(Connection connection, Statement statement, ResultSet rs) throws SQLException {
    if (outputClass == null) {
        RowMapper rowMapper = new ColumnMapRowMapper();
        return new ResultSetIterator(connection, statement, rs, rowMapper);
    } else {
        Class<?> outputClzz = getCamelContext().getClassResolver().resolveClass(outputClass);
        RowMapper rowMapper = new BeanPropertyRowMapper(outputClzz);
        return new ResultSetIterator(connection, statement, rs, rowMapper);
    }
}
Also used : BeanPropertyRowMapper(org.springframework.jdbc.core.BeanPropertyRowMapper) ColumnMapRowMapper(org.springframework.jdbc.core.ColumnMapRowMapper) BeanPropertyRowMapper(org.springframework.jdbc.core.BeanPropertyRowMapper) RowMapper(org.springframework.jdbc.core.RowMapper) ColumnMapRowMapper(org.springframework.jdbc.core.ColumnMapRowMapper)

Example 4 with RowMapper

use of org.springframework.jdbc.core.RowMapper in project Gargoyle by callakrsos.

the class SqlPane method applySelectScript.

/**
	 * 테이블의 SELECT문을 리턴.
	 *
	 * @param e
	 */
public void applySelectScript(ActionEvent e) {
    TreeItem<K> selectedItem = schemaTree.getSelectionModel().getSelectedItem();
    String tableName = this.getSelectedTreeByTableName(selectedItem);
    SqlTab selectedTab = getSelectedSqlTab();
    TreeItem<K> schemaTreeItem = selectedItem.getParent();
    String schema = schemaTreeItem.getValue().toString();
    try (Connection connection = connectionSupplier.get()) {
        List<String> columns = DbUtil.columns(connection, tableName);
        if (columns == null || columns.isEmpty()) {
            String driver = DbUtil.getDriverNameByConnection(connection);
            String sql = ConfigResourceLoader.getInstance().get(ConfigResourceLoader.SQL_TABLE_COLUMNS_WRAPPER, driver);
            Map<String, Object> map = new HashMap<>(2);
            map.put("databaseName", schema);
            map.put("tableName", tableName);
            sql = ValueUtil.getVelocityToText(sql, map, true);
            columns = DbUtil.select(connection, sql, 10, (RowMapper<String>) (rs, rowNum) -> rs.getString(1));
        }
        redueceAction(columns, ",\n", v -> selectedTab.appendTextSql(String.format("select\n%s \nfrom %s ", v.substring(0, v.length()), tableName)));
    } catch (Exception e1) {
        LOGGER.error(ValueUtil.toString(e1));
    }
}
Also used : HashMap(java.util.HashMap) Connection(java.sql.Connection) SqlTab(com.kyj.fx.voeditor.visual.component.sql.tab.SqlTab) RowMapper(org.springframework.jdbc.core.RowMapper)

Example 5 with RowMapper

use of org.springframework.jdbc.core.RowMapper in project cu-kfs by CU-CommunityApps.

the class LevelOrganizationDaoJdbc method getDLevelOrganizations.

/**
 * This overridden method ...
 *
 * @see edu.cornell.kfs.module.purap.dataaccess.LevelOrganizationDao#getDLevelOrganizations(java.lang.String)
 */
public List<LevelOrganization> getDLevelOrganizations(String cLevelOrg) {
    if (StringUtils.isNotEmpty(cLevelOrg) && cLevelOrg.contains("-")) {
        String chart = cLevelOrg.substring(0, cLevelOrg.lastIndexOf("-"));
        String cOrg = cLevelOrg.substring(cLevelOrg.lastIndexOf("-") + 1, cLevelOrg.length());
        try {
            // Build the SQL
            StringBuilder sqlBuilder = new StringBuilder(3500);
            sqlBuilder.append(" select D_Level_Code, D_Level_Name from ( select ");
            sqlBuilder.append("       org_cd,");
            sqlBuilder.append("                  ( select org_cd ");
            sqlBuilder.append("                    from ca_org_t where org_typ_cd='C' and ROWNUM=1 ");
            sqlBuilder.append("              start with org_cd=t2.org_cd and fin_coa_cd= ? ");
            sqlBuilder.append("                   connect by prior rpts_to_org_cd = org_cd and rpts_to_org_cd not in ('UNIV') and fin_coa_cd=?) C_Level_Code, ");
            sqlBuilder.append("               ( select org_nm ");
            sqlBuilder.append("               from ca_org_t where org_typ_cd='C' and ROWNUM=1 ");
            sqlBuilder.append("                start with org_cd=t2.org_cd and fin_coa_cd=? ");
            sqlBuilder.append("                 connect by prior rpts_to_org_cd = org_cd and rpts_to_org_cd not in ('UNIV') and fin_coa_cd=?) C_Level_Name, ");
            sqlBuilder.append("                ( select org_cd from ca_org_t where org_typ_cd='D' and ROWNUM=1 ");
            sqlBuilder.append("              start with org_cd=t2.org_cd and fin_coa_cd=?");
            sqlBuilder.append("             connect by prior rpts_to_org_cd = org_cd and rpts_to_org_cd not in ('UNIV') and fin_coa_cd=?) D_Level_Code,");
            sqlBuilder.append("                       ( select org_nm from ca_org_t where org_typ_cd='D' and ROWNUM=1 ");
            sqlBuilder.append("                start with org_cd=t2.org_cd and fin_coa_cd=?");
            sqlBuilder.append("                connect by prior rpts_to_org_cd = org_cd and rpts_to_org_cd not in ('UNIV') and fin_coa_cd=?) D_Level_Name ");
            sqlBuilder.append("             from  ca_org_t t2 where t2.org_typ_cd = 'D' and ORG_ACTIVE_CD = 'Y' ");
            sqlBuilder.append("             ) t where t.C_Level_Code = ? order by D_Level_Name");
            String sqlString = sqlBuilder.toString();
            // Get the SIP data from the data base, map it to the object and build a result set of objects to be returned to the user.
            RowMapper<LevelOrganization> mapper = new RowMapper<LevelOrganization>() {

                public LevelOrganization mapRow(ResultSet rs, int rowNum) throws SQLException {
                    LevelOrganization cLevelOrganization = new LevelOrganization();
                    cLevelOrganization.setCode(rs.getString("D_Level_Code"));
                    cLevelOrganization.setName(rs.getString("D_Level_Name"));
                    return cLevelOrganization;
                }
            };
            return this.getJdbcTemplate().query(sqlString, mapper, chart, chart, chart, chart, chart, chart, chart, chart, cOrg);
        } catch (Exception ex) {
            LOG.info("LevelOrganizationDaoJdbc Exception: " + ex.getMessage());
            return null;
        }
    } else
        return null;
}
Also used : LevelOrganization(edu.cornell.kfs.module.purap.businessobject.LevelOrganization) ResultSet(java.sql.ResultSet) SQLException(java.sql.SQLException) RowMapper(org.springframework.jdbc.core.RowMapper)

Aggregations

RowMapper (org.springframework.jdbc.core.RowMapper)45 ResultSet (java.sql.ResultSet)23 SQLException (java.sql.SQLException)13 List (java.util.List)11 Named (javax.inject.Named)8 Singleton (javax.inject.Singleton)8 Test (org.junit.jupiter.api.Test)8 MapSqlParameterSource (org.springframework.jdbc.core.namedparam.MapSqlParameterSource)8 Guid (org.ovirt.engine.core.compat.Guid)7 QueryMappingConfiguration (org.springframework.data.jdbc.repository.QueryMappingConfiguration)7 Map (java.util.Map)6 Tags (org.ovirt.engine.core.common.businessentities.Tags)6 TagsTemplateMap (org.ovirt.engine.core.common.businessentities.TagsTemplateMap)6 TagsType (org.ovirt.engine.core.common.businessentities.TagsType)6 TagsUserGroupMap (org.ovirt.engine.core.common.businessentities.TagsUserGroupMap)6 TagsUserMap (org.ovirt.engine.core.common.businessentities.TagsUserMap)6 TagsVdsMap (org.ovirt.engine.core.common.businessentities.TagsVdsMap)6 TagsVmMap (org.ovirt.engine.core.common.businessentities.TagsVmMap)6 HashMap (java.util.HashMap)5 Test (org.junit.Test)4