use of org.springframework.dao.DataAccessException 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.dao.DataAccessException in project musiccabinet by hakko.
the class JdbcAlbumInfoDao method getAlbumInfosForIds.
@Override
public Map<Integer, AlbumInfo> getAlbumInfosForIds(List<Integer> paths) {
String sql = "select alb.album_name_capitalization, ai.mediumimageurl," + " ai.largeimageurl, ai.extralargeimageurl, alb.id from music.albuminfo ai" + " inner join music.album alb on ai.album_id = alb.id" + " where alb.id in (" + getParameters(paths.size()) + ")";
final Map<Integer, AlbumInfo> albumInfos = new HashMap<>();
try {
jdbcTemplate.query(sql, paths.toArray(), new RowCallbackHandler() {
@Override
public void processRow(ResultSet rs) throws SQLException {
AlbumInfo ai = new AlbumInfo();
String albumName = rs.getString(1);
ai.setMediumImageUrl(rs.getString(2));
ai.setLargeImageUrl(rs.getString(3));
ai.setExtraLargeImageUrl(rs.getString(4));
int albumId = rs.getInt(5);
ai.setAlbum(new Album(albumName));
albumInfos.put(albumId, ai);
}
});
} catch (DataAccessException e) {
LOG.warn("Could not fetch album infos for paths " + paths + "!", e);
}
return albumInfos;
}
use of org.springframework.dao.DataAccessException in project gocd by gocd.
the class PipelineRepositoryTest method stubPipelineInstancesInDb.
private void stubPipelineInstancesInDb(Object[]... rows) {
pipelineRepository.setHibernateTemplate(new HibernateTemplate() {
@Override
public <T> T execute(HibernateCallback<T> action) throws DataAccessException {
try {
return action.doInHibernate(session);
} catch (SQLException e) {
throw new RuntimeException();
}
}
});
when(session.createSQLQuery(anyString())).thenReturn(sqlQuery);
when(sqlQuery.list()).thenReturn(Arrays.asList(rows));
}
use of org.springframework.dao.DataAccessException in project libresonic by Libresonic.
the class DBController method handleRequestInternal.
@RequestMapping(method = { RequestMethod.GET, RequestMethod.POST })
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
Map<String, Object> map = new HashMap<String, Object>();
String query = request.getParameter("query");
if (query != null) {
map.put("query", query);
try {
List<?> result = daoHelper.getJdbcTemplate().query(query, new ColumnMapRowMapper());
map.put("result", result);
} catch (DataAccessException x) {
map.put("error", ExceptionUtils.getRootCause(x).getMessage());
}
}
return new ModelAndView("db", "model", map);
}
use of org.springframework.dao.DataAccessException in project ORCID-Source by ORCID.
the class T2OrcidApiServiceDelegatorImpl method addExternalIdentifiers.
/**
* Add new external identifiers to the profile. As with all calls, if the
* message contains any other elements, a 400 Bad Request will be returned.
*
* @param orcidMessage
* the message congtaining the external ids
* @return If successful, returns a 200 OK with the updated content.
*/
@Override
@AccessControl(requiredScope = ScopePathType.ORCID_BIO_EXTERNAL_IDENTIFIERS_CREATE)
public Response addExternalIdentifiers(UriInfo uriInfo, String orcid, OrcidMessage orcidMessage) {
OrcidProfile orcidProfile = orcidMessage.getOrcidProfile();
try {
ExternalIdentifiers updatedExternalIdentifiers = orcidProfile.getOrcidBio().getExternalIdentifiers();
// Get the client profile information
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
String clientId = null;
if (OAuth2Authentication.class.isAssignableFrom(authentication.getClass())) {
OAuth2Request authorizationRequest = ((OAuth2Authentication) authentication).getOAuth2Request();
clientId = authorizationRequest.getClientId();
}
for (ExternalIdentifier ei : updatedExternalIdentifiers.getExternalIdentifier()) {
// Set the client profile to each external identifier
if (ei.getSource() == null) {
Source source = new Source();
source.setSourceClientId(new SourceClientId(clientId));
ei.setSource(source);
} else {
// Check if the provided external orcid exists
Source source = ei.getSource();
String sourceOrcid = source.retrieveSourcePath();
if (sourceOrcid != null) {
if (StringUtils.isBlank(sourceOrcid) || (!profileEntityManager.orcidExists(sourceOrcid) && !clientDetailsManager.exists(sourceOrcid))) {
Map<String, String> params = new HashMap<String, String>();
params.put("orcid", sourceOrcid);
throw new OrcidNotFoundException(params);
}
}
}
}
orcidProfile = orcidProfileManager.addExternalIdentifiers(orcidProfile);
return getOrcidMessageResponse(orcidProfile, orcid);
} catch (DataAccessException e) {
throw new OrcidBadRequestException(localeManager.resolveMessage("apiError.badrequest_createorcid.exception"));
}
}
Aggregations