Search in sources :

Example 6 with BatchSqlUpdate

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();
}
Also used : SqlParameter(org.springframework.jdbc.core.SqlParameter) BatchSqlUpdate(org.springframework.jdbc.object.BatchSqlUpdate)

Example 7 with BatchSqlUpdate

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();
}
Also used : SqlParameter(org.springframework.jdbc.core.SqlParameter) BatchSqlUpdate(org.springframework.jdbc.object.BatchSqlUpdate)

Example 8 with BatchSqlUpdate

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

Example 9 with BatchSqlUpdate

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

Example 10 with BatchSqlUpdate

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();
}
Also used : SqlParameter(org.springframework.jdbc.core.SqlParameter) BatchSqlUpdate(org.springframework.jdbc.object.BatchSqlUpdate)

Aggregations

SqlParameter (org.springframework.jdbc.core.SqlParameter)23 BatchSqlUpdate (org.springframework.jdbc.object.BatchSqlUpdate)23 File (com.github.hakko.musiccabinet.domain.model.library.File)3 Track (com.github.hakko.musiccabinet.domain.model.music.Track)2 RecommendedArtist (com.github.hakko.musiccabinet.domain.model.aggr.UserRecommendedArtists.RecommendedArtist)1 UserStarredTrack (com.github.hakko.musiccabinet.domain.model.aggr.UserStarredTrack)1 LastFmGroup (com.github.hakko.musiccabinet.domain.model.library.LastFmGroup)1 MetaData (com.github.hakko.musiccabinet.domain.model.library.MetaData)1 TrackPlayCount (com.github.hakko.musiccabinet.domain.model.library.TrackPlayCount)1 AlbumInfo (com.github.hakko.musiccabinet.domain.model.music.AlbumInfo)1 ArtistInfo (com.github.hakko.musiccabinet.domain.model.music.ArtistInfo)1 ArtistPlayCount (com.github.hakko.musiccabinet.domain.model.music.ArtistPlayCount)1 ArtistRelation (com.github.hakko.musiccabinet.domain.model.music.ArtistRelation)1 MBArtist (com.github.hakko.musiccabinet.domain.model.music.MBArtist)1 MBRelease (com.github.hakko.musiccabinet.domain.model.music.MBRelease)1 Tag (com.github.hakko.musiccabinet.domain.model.music.Tag)1 TagInfo (com.github.hakko.musiccabinet.domain.model.music.TagInfo)1 TrackRelation (com.github.hakko.musiccabinet.domain.model.music.TrackRelation)1