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;
}
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;
}
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();
}
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;
}
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()));
}
}
Aggregations