use of com.github.hakko.musiccabinet.domain.model.library.TrackPlayCount in project musiccabinet by hakko.
the class JdbcTrackPlayCountDaoTest method createUpdatedVersionOfTrackPlayCount.
@Test
public void createUpdatedVersionOfTrackPlayCount() {
deleteTrackPlayCounts();
dao.createTrackPlayCounts(Arrays.asList(tpc1, tpc2));
tpc1.setPlayCount(tpc1.getPlayCount() - 2);
tpc2.setPlayCount(tpc2.getPlayCount() + 2);
dao.createTrackPlayCounts(Arrays.asList(tpc1, tpc2));
List<TrackPlayCount> trackPlayCounts = dao.getTrackPlayCounts();
assertEquals(trackPlayCounts.size(), 2);
for (TrackPlayCount tpc : trackPlayCounts) {
if (tpc.getTrack().equals(tpc1.getTrack())) {
assertTrue(tpc.getPlayCount() != tpc1.getPlayCount());
} else if (tpc.getTrack().equals(tpc2.getTrack())) {
assertTrue(tpc.getPlayCount() == tpc2.getPlayCount());
} else {
assertTrue("Either file1 or 2 should have been returned.", false);
}
}
}
use of com.github.hakko.musiccabinet.domain.model.library.TrackPlayCount in project musiccabinet by hakko.
the class ScrobbledTracksParserTest method resourceFileCorrectlyParsed.
@Test
public void resourceFileCorrectlyParsed() throws ApplicationException {
ScrobbledTracksParser parser = new ScrobbledTracksParserImpl(new ResourceUtil(LIBRARY_TRACKS_FILE).getInputStream());
assertNotNull(parser.getTrackPlayCounts());
assertEquals(parser.getPage(), (short) 1);
assertEquals(parser.getTotalPages(), (short) 151);
assertEquals(parser.getTrackPlayCounts().size(), 100);
for (TrackPlayCount trackPlayCount : parser.getTrackPlayCounts()) {
assertNotNull(trackPlayCount.getTrack());
assertNotNull(trackPlayCount.getTrack().getArtist());
}
verifyLibraryTrack(parser, 0, "Can", "Thief", 181);
verifyLibraryTrack(parser, 1, "Roffe Ruff", "Ormar i gräset", 144);
verifyLibraryTrack(parser, 2, "Dungen", "Du E för Fin för Mig", 143);
verifyLibraryTrack(parser, 99, "The Radio Dept.", "Gibraltar", 41);
}
use of com.github.hakko.musiccabinet.domain.model.library.TrackPlayCount in project musiccabinet by hakko.
the class JdbcTrackPlayCountDao method batchInsert.
private void batchInsert(List<TrackPlayCount> trackPlayCounts) {
String sql = "insert into library.trackplaycount_import (artist_name, track_name, play_count) values (?,?,?)";
BatchSqlUpdate batchUpdate = new BatchSqlUpdate(jdbcTemplate.getDataSource(), sql);
batchUpdate.setBatchSize(1000);
batchUpdate.declareParameter(new SqlParameter("artist_name", Types.VARCHAR));
batchUpdate.declareParameter(new SqlParameter("track_name", Types.VARCHAR));
batchUpdate.declareParameter(new SqlParameter("play_count", Types.INTEGER));
for (TrackPlayCount tpc : trackPlayCounts) {
batchUpdate.update(new Object[] { tpc.getTrack().getArtist().getName(), tpc.getTrack().getName(), tpc.getPlayCount() });
}
batchUpdate.flush();
}
use of com.github.hakko.musiccabinet.domain.model.library.TrackPlayCount in project musiccabinet by hakko.
the class JdbcTrackPlayCountDao method getTrackPlayCounts.
@Override
public List<TrackPlayCount> getTrackPlayCounts() {
String sql = "select artist_name, track_name, play_count" + " from library.trackplaycount" + " inner join music.track on library.trackplaycount.track_id = music.track.id" + " inner join music.artist on music.track.artist_id = music.artist.id";
List<TrackPlayCount> trackPlayCounts = jdbcTemplate.query(sql, new RowMapper<TrackPlayCount>() {
@Override
public TrackPlayCount mapRow(ResultSet rs, int rowNum) throws SQLException {
String artistName = rs.getString(1);
String trackName = rs.getString(2);
int playCount = rs.getInt(3);
return new TrackPlayCount(artistName, trackName, playCount);
}
});
return trackPlayCounts;
}
use of com.github.hakko.musiccabinet.domain.model.library.TrackPlayCount in project musiccabinet by hakko.
the class JdbcTrackPlayCountDaoTest method createAndValidateTrackPlayCounts.
@Test
public void createAndValidateTrackPlayCounts() {
deleteTrackPlayCounts();
List<TrackPlayCount> trackPlayCounts = Arrays.asList(tpc1, tpc2, tpc3);
dao.createTrackPlayCounts(trackPlayCounts);
List<TrackPlayCount> storedTrackPlayCounts = dao.getTrackPlayCounts();
assertNotNull(storedTrackPlayCounts);
for (TrackPlayCount tpc : storedTrackPlayCounts) {
assertTrue(trackPlayCounts.contains(tpc));
}
}
Aggregations