Search in sources :

Example 11 with BatchSqlUpdate

use of org.springframework.jdbc.object.BatchSqlUpdate in project musiccabinet by hakko.

the class JdbcLibraryDeletionDao method deleteSubdirectories.

@Override
public void deleteSubdirectories(String directory, Set<String> subDirectories) {
    String sql = "insert into library.directory_delete (path) values (?)";
    BatchSqlUpdate batchUpdate = new BatchSqlUpdate(jdbcTemplate.getDataSource(), sql);
    batchUpdate.declareParameter(new SqlParameter("path", Types.VARCHAR));
    for (String subDirectory : subDirectories) {
        batchUpdate.update(new Object[] { subDirectory });
    }
    batchUpdate.flush();
}
Also used : SqlParameter(org.springframework.jdbc.core.SqlParameter) BatchSqlUpdate(org.springframework.jdbc.object.BatchSqlUpdate)

Example 12 with BatchSqlUpdate

use of org.springframework.jdbc.object.BatchSqlUpdate in project musiccabinet by hakko.

the class JdbcMusicBrainzArtistDao method batchInsert.

private void batchInsert(List<MBArtist> artists) {
    String sql = "insert into music.mb_artist_import (artist_name, mbid, country_code, start_year, active) values (?,?,?,?,?)";
    BatchSqlUpdate batchUpdate = new BatchSqlUpdate(jdbcTemplate.getDataSource(), sql);
    batchUpdate.setBatchSize(1000);
    batchUpdate.declareParameter(new SqlParameter("artist_name", Types.VARCHAR));
    batchUpdate.declareParameter(new SqlParameter("mbid", Types.VARCHAR));
    batchUpdate.declareParameter(new SqlParameter("county_code", Types.VARCHAR));
    batchUpdate.declareParameter(new SqlParameter("start_year", Types.SMALLINT));
    batchUpdate.declareParameter(new SqlParameter("active", Types.BOOLEAN));
    for (MBArtist artist : artists) {
        batchUpdate.update(new Object[] { artist.getName(), artist.getMbid(), artist.getCountryCode(), artist.getStartYear(), artist.isActive() });
    }
    batchUpdate.flush();
}
Also used : MBArtist(com.github.hakko.musiccabinet.domain.model.music.MBArtist) SqlParameter(org.springframework.jdbc.core.SqlParameter) BatchSqlUpdate(org.springframework.jdbc.object.BatchSqlUpdate)

Example 13 with BatchSqlUpdate

use of org.springframework.jdbc.object.BatchSqlUpdate in project musiccabinet by hakko.

the class JdbcTagInfoDao method createTagInfo.

@Override
public void createTagInfo(List<TagInfo> tagInfos) {
    String sql = "insert into music.taginfo_import (tag_name, summary, content) values (?,?,?)";
    BatchSqlUpdate batchUpdate = new BatchSqlUpdate(jdbcTemplate.getDataSource(), sql);
    batchUpdate.setBatchSize(1000);
    batchUpdate.declareParameter(new SqlParameter("tag_name", VARCHAR));
    batchUpdate.declareParameter(new SqlParameter("summary", VARCHAR));
    batchUpdate.declareParameter(new SqlParameter("content", VARCHAR));
    for (TagInfo ti : tagInfos) {
        batchUpdate.update(new Object[] { ti.getTagName(), ti.getSummary(), ti.getContent() });
    }
    batchUpdate.flush();
    jdbcTemplate.execute("select music.update_taginfo()");
}
Also used : SqlParameter(org.springframework.jdbc.core.SqlParameter) TagInfo(com.github.hakko.musiccabinet.domain.model.music.TagInfo) BatchSqlUpdate(org.springframework.jdbc.object.BatchSqlUpdate)

Example 14 with BatchSqlUpdate

use of org.springframework.jdbc.object.BatchSqlUpdate in project musiccabinet by hakko.

the class JdbcUserLovedTracksDao method batchInsert.

private void batchInsert(String lastFmUsername, List<Track> lovedTracks) {
    String sql = "insert into music.lovedtrack_import" + " (lastfm_user, artist_name, track_name) 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("track_name", Types.VARCHAR));
    for (Track track : lovedTracks) {
        batchUpdate.update(new Object[] { lastFmUsername, track.getArtist().getName(), track.getName() });
    }
    batchUpdate.flush();
}
Also used : SqlParameter(org.springframework.jdbc.core.SqlParameter) BatchSqlUpdate(org.springframework.jdbc.object.BatchSqlUpdate) Track(com.github.hakko.musiccabinet.domain.model.music.Track) UserStarredTrack(com.github.hakko.musiccabinet.domain.model.aggr.UserStarredTrack)

Example 15 with BatchSqlUpdate

use of org.springframework.jdbc.object.BatchSqlUpdate in project musiccabinet by hakko.

the class JdbcUserRecommendedArtistsDao method batchInsert.

private void batchInsert(List<RecommendedArtist> artists, LastFmUser user) {
    String sql = "insert into music.userrecommendedartist_import" + " (lastfm_user, artist_name, rank, contextartist1_name, contextartist2_name)" + " 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("contextartist1_name", Types.VARCHAR));
    batchUpdate.declareParameter(new SqlParameter("contextartist2_name", Types.VARCHAR));
    for (int i = 0; i < artists.size(); i++) {
        RecommendedArtist rec = artists.get(i);
        batchUpdate.update(new Object[] { user.getLastFmUsername(), rec.getArtist().getName(), i, name(rec.getContextArtist1()), name(rec.getContextArtist2()) });
    }
    batchUpdate.flush();
}
Also used : SqlParameter(org.springframework.jdbc.core.SqlParameter) BatchSqlUpdate(org.springframework.jdbc.object.BatchSqlUpdate) RecommendedArtist(com.github.hakko.musiccabinet.domain.model.aggr.UserRecommendedArtists.RecommendedArtist)

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