use of org.springframework.jdbc.core.RowMapper in project ovirt-engine by oVirt.
the class StorageDomainStaticDaoImpl method getAllIds.
@Override
public List<Guid> getAllIds(Guid pool, StorageDomainStatus status) {
MapSqlParameterSource parameterSource = getStoragePoolIdParameterSource(pool).addValue("status", status.getValue());
RowMapper<Guid> mapper = (rs, rowNum) -> getGuidDefaultEmpty(rs, "storage_id");
return getCallsHandler().executeReadList("GetStorageDomainIdsByStoragePoolIdAndStatus", mapper, parameterSource);
}
use of org.springframework.jdbc.core.RowMapper in project musiccabinet by hakko.
the class JdbcAlbumInfoDao method getAlbumInfo.
@Override
public AlbumInfo getAlbumInfo(int albumId) {
String sql = "select ai.largeimageurl, ai.extralargeimageurl from music.albuminfo ai" + " where ai.album_id = " + albumId;
AlbumInfo albumInfo = null;
try {
albumInfo = jdbcTemplate.queryForObject(sql, new RowMapper<AlbumInfo>() {
@Override
public AlbumInfo mapRow(ResultSet rs, int rowNum) throws SQLException {
AlbumInfo ai = new AlbumInfo();
ai.setLargeImageUrl(rs.getString(1));
ai.setExtraLargeImageUrl(rs.getString(2));
return ai;
}
});
} catch (DataAccessException e) {
LOG.warn("There's no album info for album " + albumId, e);
}
return albumInfo;
}
use of org.springframework.jdbc.core.RowMapper in project perun by CESNET.
the class GroupsManagerImpl method getName.
public String getName(int id) {
List name;
try {
name = jdbc.query("group.name as (with temp (name, id, parent_group_id) as ((select name, id, parent_group_id from GROUPS where parent_group_id is null) union all (select cast((temp.name + ':' + groups.name) as varchar(128)), " + "groups.id, groups.parent_group_id from groups inner join temp on temp.id = groups.parent_group_id )) select name from temp where group.id = ?", (RowMapper) (resultSet, i) -> resultSet.getString(1), id);
} catch (RuntimeException e) {
throw new InternalErrorException(e);
}
String result = (String) name.get(0);
return result;
}
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