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 perun by CESNET.
the class MailManagerImpl method getMailById.
@Override
public ApplicationMail getMailById(PerunSession sess, Integer id) throws InternalErrorException, PrivilegeException {
// TODO authz
ApplicationMail mail = null;
// get mail def
try {
List<ApplicationMail> mails = jdbc.query("select id,app_type,form_id,mail_type,send from application_mails where 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"));
}
}, id);
// set
if (mails.size() != 1) {
log.error("[MAIL MANAGER] Wrong number of mail definitions returned by unique params, expected 1 but was: " + mails.size());
throw new InternalErrorException("Wrong number of mail definitions returned by unique params, expected 1 but was: " + mails.size());
}
mail = mails.get(0);
} catch (EmptyResultDataAccessException ex) {
throw new InternalErrorException("Mail definition with ID=" + id + " doesn't exists.");
}
List<MailText> texts = new ArrayList<MailText>();
try {
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());
} catch (EmptyResultDataAccessException ex) {
// if no texts it's error
log.error("[MAIL MANAGER] Mail do not contains any text message: {}", ex);
return mail;
}
for (MailText text : texts) {
// fill localized messages
mail.getMessage().put(text.getLocale(), text);
}
return mail;
}
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 camel by apache.
the class DefaultSqlEndpoint method queryForObject.
@SuppressWarnings("unchecked")
public Object queryForObject(ResultSet rs) throws SQLException {
Object result = null;
if (outputClass == null) {
RowMapper rowMapper = new ColumnMapRowMapper();
RowMapperResultSetExtractor<Map<String, Object>> mapper = new RowMapperResultSetExtractor<Map<String, Object>>(rowMapper);
List<Map<String, Object>> data = mapper.extractData(rs);
if (data.size() > 1) {
throw new SQLDataException("Query result not unique for outputType=SelectOne. Got " + data.size() + " count instead.");
} else if (data.size() == 1) {
// Set content depend on number of column from query result
Map<String, Object> row = data.get(0);
if (row.size() == 1) {
result = row.values().iterator().next();
} else {
result = row;
}
}
} else {
Class<?> outputClzz = getCamelContext().getClassResolver().resolveClass(outputClass);
RowMapper rowMapper = new BeanPropertyRowMapper(outputClzz);
RowMapperResultSetExtractor<?> mapper = new RowMapperResultSetExtractor(rowMapper);
List<?> data = mapper.extractData(rs);
if (data.size() > 1) {
throw new SQLDataException("Query result not unique for outputType=SelectOne. Got " + data.size() + " count instead.");
} else if (data.size() == 1) {
result = data.get(0);
}
}
// If data.size is zero, let result be null.
return result;
}
use of org.springframework.jdbc.core.RowMapper in project camel by apache.
the class DefaultSqlEndpoint method queryForList.
@SuppressWarnings("unchecked")
public List<?> queryForList(ResultSet rs, boolean allowMapToClass) throws SQLException {
if (allowMapToClass && outputClass != null) {
Class<?> outputClazz = getCamelContext().getClassResolver().resolveClass(outputClass);
RowMapper rowMapper = new BeanPropertyRowMapper(outputClazz);
RowMapperResultSetExtractor<?> mapper = new RowMapperResultSetExtractor(rowMapper);
List<?> data = mapper.extractData(rs);
return data;
} else {
ColumnMapRowMapper rowMapper = new ColumnMapRowMapper();
RowMapperResultSetExtractor<Map<String, Object>> mapper = new RowMapperResultSetExtractor<Map<String, Object>>(rowMapper);
List<Map<String, Object>> data = mapper.extractData(rs);
return data;
}
}
Aggregations