Search in sources :

Example 6 with AlbumInfo

use of com.github.hakko.musiccabinet.domain.model.music.AlbumInfo in project musiccabinet by hakko.

the class JdbcAlbumInfoDao method getAlbumInfo.

@Override
public AlbumInfo getAlbumInfo(final Album album) {
    String sql = "select ai.smallimageurl, ai.mediumimageurl, ai.largeimageurl, ai.extralargeimageurl, ai.listeners, ai.playcount from music.albuminfo ai" + " inner join music.album alb on ai.album_id = alb.id" + " inner join music.artist art on alb.artist_id = art.id" + " where alb.album_name = upper(?) and art.artist_name = upper(?)";
    AlbumInfo albumInfo = jdbcTemplate.queryForObject(sql, new Object[] { album.getName(), album.getArtist().getName() }, new RowMapper<AlbumInfo>() {

        @Override
        public AlbumInfo mapRow(ResultSet rs, int rowNum) throws SQLException {
            AlbumInfo ai = new AlbumInfo();
            ai.setAlbum(album);
            ai.setSmallImageUrl(rs.getString(1));
            ai.setMediumImageUrl(rs.getString(2));
            ai.setLargeImageUrl(rs.getString(3));
            ai.setExtraLargeImageUrl(rs.getString(4));
            ai.setListeners(rs.getInt(5));
            ai.setPlayCount(rs.getInt(6));
            return ai;
        }
    });
    return albumInfo;
}
Also used : SQLException(java.sql.SQLException) AlbumInfo(com.github.hakko.musiccabinet.domain.model.music.AlbumInfo) ResultSet(java.sql.ResultSet)

Example 7 with AlbumInfo

use of com.github.hakko.musiccabinet.domain.model.music.AlbumInfo 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 8 with AlbumInfo

use of com.github.hakko.musiccabinet.domain.model.music.AlbumInfo in project musiccabinet by hakko.

the class JdbcAlbumInfoDao method batchInsert.

private void batchInsert(List<AlbumInfo> albumInfos) {
    String sql = "insert into music.albuminfo_import (artist_name, album_name, smallimageurl, mediumimageurl, largeimageurl, extraLargeimageurl, listeners, playcount) values (?,?,?,?,?,?,?,?)";
    BatchSqlUpdate batchUpdate = new BatchSqlUpdate(jdbcTemplate.getDataSource(), sql);
    batchUpdate.setBatchSize(1000);
    batchUpdate.declareParameter(new SqlParameter("artist_name", Types.VARCHAR));
    batchUpdate.declareParameter(new SqlParameter("album_name", Types.VARCHAR));
    batchUpdate.declareParameter(new SqlParameter("smallimageurl", Types.VARCHAR));
    batchUpdate.declareParameter(new SqlParameter("mediumimageurl", Types.VARCHAR));
    batchUpdate.declareParameter(new SqlParameter("largeimageurl", Types.VARCHAR));
    batchUpdate.declareParameter(new SqlParameter("extraLargeimageurl", Types.VARCHAR));
    batchUpdate.declareParameter(new SqlParameter("listeners", Types.INTEGER));
    batchUpdate.declareParameter(new SqlParameter("playcount", Types.INTEGER));
    for (AlbumInfo ai : albumInfos) {
        batchUpdate.update(new Object[] { ai.getAlbum().getArtist().getName(), ai.getAlbum().getName(), ai.getSmallImageUrl(), ai.getMediumImageUrl(), ai.getLargeImageUrl(), ai.getExtraLargeImageUrl(), ai.getListeners(), ai.getPlayCount() });
    }
    batchUpdate.flush();
}
Also used : SqlParameter(org.springframework.jdbc.core.SqlParameter) AlbumInfo(com.github.hakko.musiccabinet.domain.model.music.AlbumInfo) BatchSqlUpdate(org.springframework.jdbc.object.BatchSqlUpdate)

Example 9 with AlbumInfo

use of com.github.hakko.musiccabinet.domain.model.music.AlbumInfo in project musiccabinet by hakko.

the class JdbcAlbumInfoDao method getAlbumInfosForArtist.

@Override
public List<AlbumInfo> getAlbumInfosForArtist(final int artistId) {
    String sql = "select alb.album_name_capitalization, ai.mediumimageurl, " + " ai.largeimageurl, ai.extralargeimageurl, art.artist_name_capitalization" + " from music.albuminfo ai" + " inner join music.album alb on ai.album_id = alb.id" + " inner join music.artist art on alb.artist_id = art.id" + " where art.id = " + artistId;
    List<AlbumInfo> albums = jdbcTemplate.query(sql, new RowMapper<AlbumInfo>() {

        @Override
        public AlbumInfo mapRow(ResultSet rs, int rowNum) 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));
            String artistName = rs.getString(5);
            ai.setAlbum(new Album(artistName, albumName));
            return ai;
        }
    });
    return albums;
}
Also used : 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)

Example 10 with AlbumInfo

use of com.github.hakko.musiccabinet.domain.model.music.AlbumInfo in project musiccabinet by hakko.

the class JdbcAlbumInfoDaoTest method handlesMultipleAlbumsBySameArtist.

@Test
public void handlesMultipleAlbumsBySameArtist() {
    deleteAlbumInfos();
    deleteLibraryTracks();
    createLibraryTracks(aiNirvana, aiNirvana2, aiNirvana3);
    dao.createAlbumInfo(Arrays.asList(aiNirvana, aiNirvana2, aiNirvana3));
    List<AlbumInfo> dbInfos = dao.getAlbumInfosForArtist(aiNirvana.getAlbum().getArtist().getId());
    assertNotNull(dbInfos);
    assertEquals(3, dbInfos.size());
    Set<String> dbAlbumNames = new HashSet<>();
    for (AlbumInfo dbInfo : dbInfos) {
        assertEquals(dbInfo.getAlbum().getArtist(), aiNirvana.getAlbum().getArtist());
        dbAlbumNames.add(dbInfo.getAlbum().getName());
    }
    for (AlbumInfo ai : Arrays.asList(aiNirvana, aiNirvana2, aiNirvana3)) {
        Assert.assertTrue(dbAlbumNames.contains(ai.getAlbum().getName()));
    }
}
Also used : AlbumInfo(com.github.hakko.musiccabinet.domain.model.music.AlbumInfo) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

AlbumInfo (com.github.hakko.musiccabinet.domain.model.music.AlbumInfo)14 Test (org.junit.Test)5 Album (com.github.hakko.musiccabinet.domain.model.music.Album)4 ResultSet (java.sql.ResultSet)4 SQLException (java.sql.SQLException)3 ArrayList (java.util.ArrayList)3 Artist (com.github.hakko.musiccabinet.domain.model.music.Artist)2 AlbumInfoParserImpl (com.github.hakko.musiccabinet.parser.lastfm.AlbumInfoParserImpl)2 ResourceUtil (com.github.hakko.musiccabinet.util.ResourceUtil)2 DataAccessException (org.springframework.dao.DataAccessException)2 File (com.github.hakko.musiccabinet.domain.model.library.File)1 ApplicationException (com.github.hakko.musiccabinet.exception.ApplicationException)1 AlbumInfoParser (com.github.hakko.musiccabinet.parser.lastfm.AlbumInfoParser)1 StringUtil (com.github.hakko.musiccabinet.util.StringUtil)1 UnittestLibraryUtil.getFile (com.github.hakko.musiccabinet.util.UnittestLibraryUtil.getFile)1 WSResponse (com.github.hakko.musiccabinet.ws.lastfm.WSResponse)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Before (org.junit.Before)1 RowCallbackHandler (org.springframework.jdbc.core.RowCallbackHandler)1