use of org.springframework.jdbc.object.BatchSqlUpdate in project musiccabinet by hakko.
the class JdbcTagDao method createTagCorrections.
/*
* tagCorrection is a map of <original tag name> -> <corrected tag name>
*/
@Override
public void createTagCorrections(Map<String, String> tagCorrections) {
String sql = "update music.tag t set corrected_id = null where corrected_id is not null";
jdbcTemplate.execute(sql);
if (tagCorrections.size() == 0)
return;
sql = getCreateMissingTagsSql(tagCorrections.size());
jdbcTemplate.update(sql, (Object[]) tagCorrections.keySet().toArray(new String[tagCorrections.size()]));
jdbcTemplate.update(sql, (Object[]) tagCorrections.values().toArray(new String[tagCorrections.size()]));
sql = "update music.tag t set corrected_id = tc.id" + " from music.tag tc where t.tag_name = ? and tc.tag_name = ?";
BatchSqlUpdate batchUpdate = new BatchSqlUpdate(jdbcTemplate.getDataSource(), sql);
batchUpdate.setBatchSize(1000);
batchUpdate.declareParameter(new SqlParameter("t.tag_name", Types.VARCHAR));
batchUpdate.declareParameter(new SqlParameter("tc.tag_name", Types.VARCHAR));
for (String tag : tagCorrections.keySet()) {
batchUpdate.update(new Object[] { tag, tagCorrections.get(tag) });
}
batchUpdate.flush();
}
use of org.springframework.jdbc.object.BatchSqlUpdate in project musiccabinet by hakko.
the class JdbcTagDao method batchInsert.
private void batchInsert(String tagName, List<Artist> artists) {
String sql = "insert into music.tagtopartist_import (tag_name, artist_name, rank) values (?,?,?)";
BatchSqlUpdate batchUpdate = new BatchSqlUpdate(jdbcTemplate.getDataSource(), sql);
batchUpdate.setBatchSize(1000);
batchUpdate.declareParameter(new SqlParameter("tag_name", Types.VARCHAR));
batchUpdate.declareParameter(new SqlParameter("artist_name", Types.VARCHAR));
batchUpdate.declareParameter(new SqlParameter("rank", Types.INTEGER));
for (int i = 0; i < artists.size(); i++) {
batchUpdate.update(new Object[] { tagName, artists.get(i).getName(), i });
}
batchUpdate.flush();
}
use of org.springframework.jdbc.object.BatchSqlUpdate 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 org.springframework.jdbc.object.BatchSqlUpdate 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 org.springframework.jdbc.object.BatchSqlUpdate in project musiccabinet by hakko.
the class JdbcUserTopArtistsDao method batchInsert.
private void batchInsert(List<Artist> artists, LastFmUser user, Period period) {
String sql = "insert into music.usertopartist_import (lastfm_user, artist_name, rank, days) values (?,?,?,?)";
BatchSqlUpdate batchUpdate = new BatchSqlUpdate(jdbcTemplate.getDataSource(), sql);
batchUpdate.setBatchSize(1000);
batchUpdate.declareParameter(new SqlParameter("lastfm_user", Types.VARCHAR));
batchUpdate.declareParameter(new SqlParameter("artist_name", Types.VARCHAR));
batchUpdate.declareParameter(new SqlParameter("rank", Types.INTEGER));
batchUpdate.declareParameter(new SqlParameter("days", Types.INTEGER));
for (int i = 0; i < artists.size(); i++) {
batchUpdate.update(new Object[] { user.getLastFmUsername(), artists.get(i).getName(), i, period.getDays() });
}
batchUpdate.flush();
}
Aggregations