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