Search in sources :

Example 26 with DataAccessException

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;
}
Also used : AlbumInfo(com.github.hakko.musiccabinet.domain.model.music.AlbumInfo) ResultSet(java.sql.ResultSet) DataAccessException(org.springframework.dao.DataAccessException) RowMapper(org.springframework.jdbc.core.RowMapper)

Example 27 with DataAccessException

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;
}
Also used : HashMap(java.util.HashMap) SQLException(java.sql.SQLException) AlbumInfo(com.github.hakko.musiccabinet.domain.model.music.AlbumInfo) ResultSet(java.sql.ResultSet) Album(com.github.hakko.musiccabinet.domain.model.music.Album) RowCallbackHandler(org.springframework.jdbc.core.RowCallbackHandler) DataAccessException(org.springframework.dao.DataAccessException)

Example 28 with DataAccessException

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));
}
Also used : SQLException(java.sql.SQLException) HibernateTemplate(org.springframework.orm.hibernate3.HibernateTemplate) DataAccessException(org.springframework.dao.DataAccessException)

Example 29 with DataAccessException

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);
}
Also used : HashMap(java.util.HashMap) ModelAndView(org.springframework.web.servlet.ModelAndView) ColumnMapRowMapper(org.springframework.jdbc.core.ColumnMapRowMapper) DataAccessException(org.springframework.dao.DataAccessException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 30 with DataAccessException

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"));
    }
}
Also used : ExternalIdentifier(org.orcid.jaxb.model.message.ExternalIdentifier) HashMap(java.util.HashMap) SourceClientId(org.orcid.jaxb.model.message.SourceClientId) Source(org.orcid.jaxb.model.message.Source) OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) OAuth2Request(org.springframework.security.oauth2.provider.OAuth2Request) OrcidBadRequestException(org.orcid.core.exception.OrcidBadRequestException) OAuth2Authentication(org.springframework.security.oauth2.provider.OAuth2Authentication) Authentication(org.springframework.security.core.Authentication) OAuth2Authentication(org.springframework.security.oauth2.provider.OAuth2Authentication) OrcidNotFoundException(org.orcid.core.exception.OrcidNotFoundException) ExternalIdentifiers(org.orcid.jaxb.model.message.ExternalIdentifiers) DataAccessException(org.springframework.dao.DataAccessException) AccessControl(org.orcid.core.security.visibility.aop.AccessControl)

Aggregations

DataAccessException (org.springframework.dao.DataAccessException)73 SQLException (java.sql.SQLException)40 Test (org.junit.Test)20 Connection (java.sql.Connection)17 ResultSet (java.sql.ResultSet)16 PreparedStatement (java.sql.PreparedStatement)14 TransactionStatus (org.springframework.transaction.TransactionStatus)7 HashMap (java.util.HashMap)6 DeadlockLoserDataAccessException (org.springframework.dao.DeadlockLoserDataAccessException)5 IncorrectResultSizeDataAccessException (org.springframework.dao.IncorrectResultSizeDataAccessException)5 IOException (java.io.IOException)4 EmptyResultDataAccessException (org.springframework.dao.EmptyResultDataAccessException)4 ConnectionCallback (org.springframework.jdbc.core.ConnectionCallback)4 SpringSqlParams (com.opengamma.elsql.SpringSqlParams)3 DatabaseMetaData (java.sql.DatabaseMetaData)3 Statement (java.sql.Statement)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 IJoinQueryString (org.apereo.portal.jdbc.IJoinQueryString)3 DataIntegrityViolationException (org.springframework.dao.DataIntegrityViolationException)3