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;
}
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;
}
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);
}
}
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));
}
}
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;
}
Aggregations