Search in sources :

Example 1 with TrackRelation

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

the class JdbcTrackRelationDao method batchInsert.

private void batchInsert(Track sourceTrack, List<TrackRelation> trackRelations) {
    int sourceTrackId = jdbcTemplate.queryForInt("select * from music.get_track_id(?,?)", sourceTrack.getArtist().getName(), sourceTrack.getName());
    String sql = "insert into music.trackrelation_import (source_id, target_artist_name, target_track_name, weight) values (?,?,?,?)";
    BatchSqlUpdate batchUpdate = new BatchSqlUpdate(jdbcTemplate.getDataSource(), sql);
    batchUpdate.setBatchSize(1000);
    batchUpdate.declareParameter(new SqlParameter("source_id", Types.INTEGER));
    batchUpdate.declareParameter(new SqlParameter("target_artist_name", Types.VARCHAR));
    batchUpdate.declareParameter(new SqlParameter("target_track_name", Types.VARCHAR));
    batchUpdate.declareParameter(new SqlParameter("weight", Types.FLOAT));
    for (TrackRelation tr : trackRelations) {
        batchUpdate.update(new Object[] { sourceTrackId, tr.getTarget().getArtist().getName(), tr.getTarget().getName(), tr.getMatch() });
    }
    batchUpdate.flush();
}
Also used : SqlParameter(org.springframework.jdbc.core.SqlParameter) TrackRelation(com.github.hakko.musiccabinet.domain.model.music.TrackRelation) BatchSqlUpdate(org.springframework.jdbc.object.BatchSqlUpdate)

Example 2 with TrackRelation

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

the class JdbcTrackRelationDaoTest method createAndValidateUpdatedTrackRelation.

@Test
public void createAndValidateUpdatedTrackRelation() {
    deletePreviousTestdata();
    dao.createTrackRelations(sourceTrack1, Arrays.asList(tr1, tr2, tr3, tr4));
    dao.createTrackRelations(sourceTrack2, Arrays.asList(tr5, tr6, tr7));
    tr3.setMatch(0.55f);
    tr7.setMatch(0.44f);
    dao.createTrackRelations(sourceTrack2, Arrays.asList(tr5, tr7));
    List<TrackRelation> cherRelations = dao.getTrackRelations(sourceTrack1);
    List<TrackRelation> madonnaRelations = dao.getTrackRelations(sourceTrack2);
    assertNotNull(cherRelations);
    assertNotNull(madonnaRelations);
    Assert.assertEquals(4, cherRelations.size());
    Assert.assertEquals(3, madonnaRelations.size());
    for (TrackRelation tr : Arrays.asList(tr1, tr2, tr4)) {
        assertTrue(cherRelations.contains(tr));
    }
    assertFalse(cherRelations.contains(tr3));
    for (TrackRelation tr : Arrays.asList(tr5, tr6, tr7)) {
        assertTrue(madonnaRelations.contains(tr));
    }
}
Also used : TrackRelation(com.github.hakko.musiccabinet.domain.model.music.TrackRelation) Test(org.junit.Test)

Example 3 with TrackRelation

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

the class TrackSimilarityParserTest method verifyTrackRelation.

private void verifyTrackRelation(TrackSimilarityParser parser, int trackRelationIndex, String artistName, String trackName, float match) {
    TrackRelation relation = parser.getTrackRelations().get(trackRelationIndex);
    assertTrue(relation.getTarget().getArtist().getName().equals(artistName));
    assertTrue(relation.getTarget().getName().equals(trackName));
    assertEquals(relation.getMatch(), match);
}
Also used : TrackRelation(com.github.hakko.musiccabinet.domain.model.music.TrackRelation)

Example 4 with TrackRelation

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

the class TrackSimilarityParserTest method resourceFileCorrectlyParsed.

@Test
public void resourceFileCorrectlyParsed() throws ApplicationException {
    TrackSimilarityParser parser = new TrackSimilarityParserImpl(new ResourceUtil(TRACK_SIMILARITY_FILE).getInputStream());
    assertNotNull(parser.getTrack());
    assertNotNull(parser.getTrackRelations());
    assertTrue(parser.getTrack().getArtist().getName().equals("Cher"));
    assertTrue(parser.getTrack().getName().equals("Believe"));
    assertEquals(parser.getTrackRelations().size(), 250);
    for (TrackRelation tr : parser.getTrackRelations()) {
        assertNotNull(tr.getTarget());
        assertNotNull(tr.getTarget().getArtist());
    }
    verifyTrackRelation(parser, 0, "Cher", "Strong Enough", 1.0f);
    verifyTrackRelation(parser, 1, "Cher", "All Or Nothing", 0.961879f);
    verifyTrackRelation(parser, 2, "Madonna", "Vogue", 0.291088f);
}
Also used : ResourceUtil(com.github.hakko.musiccabinet.util.ResourceUtil) TrackRelation(com.github.hakko.musiccabinet.domain.model.music.TrackRelation) Test(org.junit.Test)

Example 5 with TrackRelation

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

the class JdbcTrackRelationDao method getTrackRelations.

@Override
public List<TrackRelation> getTrackRelations(Track sourceTrack) {
    final int sourceTrackId = jdbcTemplate.queryForInt("select * from music.get_track_id(?,?)", sourceTrack.getArtist().getName(), sourceTrack.getName());
    String sql = "select artist_name_capitalization, track_name_capitalization, weight" + " from music.trackrelation" + " inner join music.track on music.trackrelation.target_id = music.track.id" + " inner join music.artist on music.track.artist_id = music.artist.id" + " where music.trackrelation.source_id = ?";
    List<TrackRelation> trackRelations = jdbcTemplate.query(sql, new Object[] { sourceTrackId }, new RowMapper<TrackRelation>() {

        @Override
        public TrackRelation mapRow(ResultSet rs, int rowNum) throws SQLException {
            String artistName = rs.getString(1);
            String trackName = rs.getString(2);
            float weight = rs.getFloat(3);
            return new TrackRelation(new Track(artistName, trackName), weight);
        }
    });
    return trackRelations;
}
Also used : SQLException(java.sql.SQLException) TrackRelation(com.github.hakko.musiccabinet.domain.model.music.TrackRelation) ResultSet(java.sql.ResultSet) Track(com.github.hakko.musiccabinet.domain.model.music.Track)

Aggregations

TrackRelation (com.github.hakko.musiccabinet.domain.model.music.TrackRelation)8 Test (org.junit.Test)4 Track (com.github.hakko.musiccabinet.domain.model.music.Track)2 ResourceUtil (com.github.hakko.musiccabinet.util.ResourceUtil)2 PlaylistItem (com.github.hakko.musiccabinet.domain.model.aggr.PlaylistItem)1 File (com.github.hakko.musiccabinet.domain.model.library.File)1 TrackSimilarityParser (com.github.hakko.musiccabinet.parser.lastfm.TrackSimilarityParser)1 TrackSimilarityParserImpl (com.github.hakko.musiccabinet.parser.lastfm.TrackSimilarityParserImpl)1 UnittestLibraryUtil.getFile (com.github.hakko.musiccabinet.util.UnittestLibraryUtil.getFile)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 SqlParameter (org.springframework.jdbc.core.SqlParameter)1 BatchSqlUpdate (org.springframework.jdbc.object.BatchSqlUpdate)1