Search in sources :

Example 1 with TrackPlayCount

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);
        }
    }
}
Also used : TrackPlayCount(com.github.hakko.musiccabinet.domain.model.library.TrackPlayCount) Test(org.junit.Test)

Example 2 with TrackPlayCount

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);
}
Also used : ResourceUtil(com.github.hakko.musiccabinet.util.ResourceUtil) TrackPlayCount(com.github.hakko.musiccabinet.domain.model.library.TrackPlayCount) Test(org.junit.Test)

Example 3 with TrackPlayCount

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();
}
Also used : SqlParameter(org.springframework.jdbc.core.SqlParameter) BatchSqlUpdate(org.springframework.jdbc.object.BatchSqlUpdate) TrackPlayCount(com.github.hakko.musiccabinet.domain.model.library.TrackPlayCount)

Example 4 with TrackPlayCount

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;
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) TrackPlayCount(com.github.hakko.musiccabinet.domain.model.library.TrackPlayCount)

Example 5 with TrackPlayCount

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));
    }
}
Also used : TrackPlayCount(com.github.hakko.musiccabinet.domain.model.library.TrackPlayCount) Test(org.junit.Test)

Aggregations

TrackPlayCount (com.github.hakko.musiccabinet.domain.model.library.TrackPlayCount)6 Test (org.junit.Test)3 ResourceUtil (com.github.hakko.musiccabinet.util.ResourceUtil)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 SqlParameter (org.springframework.jdbc.core.SqlParameter)1 BatchSqlUpdate (org.springframework.jdbc.object.BatchSqlUpdate)1