Search in sources :

Example 16 with BatchSqlUpdate

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

the class JdbcGroupWeeklyArtistChartDao method batchInsert.

private void batchInsert(GroupWeeklyArtistChart artistChart) {
    String sql = "insert into music.groupweeklyartistchart_import (lastfmgroup_name, artist_name, playcount) values (?,?,?)";
    BatchSqlUpdate batchUpdate = new BatchSqlUpdate(jdbcTemplate.getDataSource(), sql);
    batchUpdate.setBatchSize(1000);
    batchUpdate.declareParameter(new SqlParameter("lastfmgroup_name", Types.VARCHAR));
    batchUpdate.declareParameter(new SqlParameter("artist_name", Types.VARCHAR));
    batchUpdate.declareParameter(new SqlParameter("playcount", Types.INTEGER));
    for (ArtistPlayCount apc : artistChart.getArtistPlayCounts()) {
        batchUpdate.update(new Object[] { artistChart.getGroupName(), apc.getArtist().getName(), apc.getPlayCount() });
    }
    batchUpdate.flush();
}
Also used : ArtistPlayCount(com.github.hakko.musiccabinet.domain.model.music.ArtistPlayCount) SqlParameter(org.springframework.jdbc.core.SqlParameter) BatchSqlUpdate(org.springframework.jdbc.object.BatchSqlUpdate)

Example 17 with BatchSqlUpdate

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

the class JdbcLibraryAdditionDao method addFiles.

@Override
public void addFiles(String directory, Set<File> files) {
    String sql = "insert into library.file_import (path, filename, modified, size) values (?,?,?,?)";
    BatchSqlUpdate batchUpdate = new BatchSqlUpdate(jdbcTemplate.getDataSource(), sql);
    batchUpdate.declareParameter(new SqlParameter("path", Types.VARCHAR));
    batchUpdate.declareParameter(new SqlParameter("filename", Types.VARCHAR));
    batchUpdate.declareParameter(new SqlParameter("modified", Types.TIMESTAMP));
    batchUpdate.declareParameter(new SqlParameter("size", Types.INTEGER));
    for (File file : files) {
        batchUpdate.update(new Object[] { file.getDirectory(), file.getFilename(), file.getModified().toDate(), file.getSize() });
    }
    batchUpdate.flush();
    addMetadata(files);
}
Also used : SqlParameter(org.springframework.jdbc.core.SqlParameter) BatchSqlUpdate(org.springframework.jdbc.object.BatchSqlUpdate) File(com.github.hakko.musiccabinet.domain.model.library.File)

Example 18 with BatchSqlUpdate

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

the class JdbcLibraryAdditionDao method addMetadata.

private void addMetadata(Set<File> files) {
    String sql = "insert into library.file_headertag_import (path, filename, extension," + "bitrate, vbr, duration, artist_name, album_artist_name, composer_name," + "album_name, track_name, track_nr, track_nrs, disc_nr, disc_nrs, year," + "tag_name, lyrics, coverart, artistsort_name, albumartistsort_name) values" + "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
    BatchSqlUpdate batch = new BatchSqlUpdate(jdbcTemplate.getDataSource(), sql);
    batch.declareParameter(new SqlParameter("path", Types.VARCHAR));
    batch.declareParameter(new SqlParameter("filename", Types.VARCHAR));
    batch.declareParameter(new SqlParameter("extension", Types.VARCHAR));
    batch.declareParameter(new SqlParameter("bitrate", Types.SMALLINT));
    batch.declareParameter(new SqlParameter("vbr", Types.BOOLEAN));
    batch.declareParameter(new SqlParameter("duration", Types.SMALLINT));
    batch.declareParameter(new SqlParameter("artist_name", Types.VARCHAR));
    batch.declareParameter(new SqlParameter("album_artist_name", Types.VARCHAR));
    batch.declareParameter(new SqlParameter("composer_name", Types.VARCHAR));
    batch.declareParameter(new SqlParameter("album_name", Types.VARCHAR));
    batch.declareParameter(new SqlParameter("track_name", Types.VARCHAR));
    batch.declareParameter(new SqlParameter("track_nr", Types.SMALLINT));
    batch.declareParameter(new SqlParameter("track_nrs", Types.SMALLINT));
    batch.declareParameter(new SqlParameter("disc_nr", Types.SMALLINT));
    batch.declareParameter(new SqlParameter("disc_nrs", Types.SMALLINT));
    batch.declareParameter(new SqlParameter("year", Types.SMALLINT));
    batch.declareParameter(new SqlParameter("tag_name", Types.VARCHAR));
    batch.declareParameter(new SqlParameter("lyrics", Types.VARCHAR));
    batch.declareParameter(new SqlParameter("coverart", Types.BOOLEAN));
    batch.declareParameter(new SqlParameter("artistsort_name", Types.VARCHAR));
    batch.declareParameter(new SqlParameter("albumartistsort_name", Types.VARCHAR));
    for (File file : files) {
        MetaData md = file.getMetadata();
        if (md != null) {
            batch.update(new Object[] { file.getDirectory(), file.getFilename(), md.getMediaType().getFilesuffix(), md.getBitrate(), md.isVbr(), md.getDuration(), md.getArtist(), md.getAlbumArtist(), md.getComposer(), md.getAlbum(), md.getTitle(), md.getTrackNr(), md.getTrackNrs(), md.getDiscNr(), md.getDiscNrs(), md.getYear(), md.getGenre(), md.getLyrics(), md.isCoverArtEmbedded(), md.getArtistSort(), md.getAlbumArtistSort() });
        }
    }
    batch.flush();
}
Also used : SqlParameter(org.springframework.jdbc.core.SqlParameter) MetaData(com.github.hakko.musiccabinet.domain.model.library.MetaData) BatchSqlUpdate(org.springframework.jdbc.object.BatchSqlUpdate) File(com.github.hakko.musiccabinet.domain.model.library.File)

Example 19 with BatchSqlUpdate

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

the class JdbcArtistTopTracksDao method batchInsert.

private void batchInsert(Artist artist, List<Track> topTracks) {
    int sourceArtistId = jdbcTemplate.queryForInt("select * from music.get_artist_id(?)", artist.getName());
    String sql = "insert into music.artisttoptrack_import (artist_id, track_name, rank) values (?,?,?)";
    BatchSqlUpdate batchUpdate = new BatchSqlUpdate(jdbcTemplate.getDataSource(), sql);
    batchUpdate.setBatchSize(1000);
    batchUpdate.declareParameter(new SqlParameter("artist_id", Types.INTEGER));
    batchUpdate.declareParameter(new SqlParameter("track_name", Types.VARCHAR));
    batchUpdate.declareParameter(new SqlParameter("rank", Types.SMALLINT));
    short rank = 0;
    for (Track t : topTracks) {
        batchUpdate.update(new Object[] { sourceArtistId, t.getName(), ++rank });
    }
    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)

Example 20 with BatchSqlUpdate

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

the class JdbcAlbumInfoDao method batchInsert.

private void batchInsert(List<AlbumInfo> albumInfos) {
    String sql = "insert into music.albuminfo_import (artist_name, album_name, smallimageurl, mediumimageurl, largeimageurl, extraLargeimageurl, listeners, playcount) values (?,?,?,?,?,?,?,?)";
    BatchSqlUpdate batchUpdate = new BatchSqlUpdate(jdbcTemplate.getDataSource(), sql);
    batchUpdate.setBatchSize(1000);
    batchUpdate.declareParameter(new SqlParameter("artist_name", Types.VARCHAR));
    batchUpdate.declareParameter(new SqlParameter("album_name", Types.VARCHAR));
    batchUpdate.declareParameter(new SqlParameter("smallimageurl", Types.VARCHAR));
    batchUpdate.declareParameter(new SqlParameter("mediumimageurl", Types.VARCHAR));
    batchUpdate.declareParameter(new SqlParameter("largeimageurl", Types.VARCHAR));
    batchUpdate.declareParameter(new SqlParameter("extraLargeimageurl", Types.VARCHAR));
    batchUpdate.declareParameter(new SqlParameter("listeners", Types.INTEGER));
    batchUpdate.declareParameter(new SqlParameter("playcount", Types.INTEGER));
    for (AlbumInfo ai : albumInfos) {
        batchUpdate.update(new Object[] { ai.getAlbum().getArtist().getName(), ai.getAlbum().getName(), ai.getSmallImageUrl(), ai.getMediumImageUrl(), ai.getLargeImageUrl(), ai.getExtraLargeImageUrl(), ai.getListeners(), ai.getPlayCount() });
    }
    batchUpdate.flush();
}
Also used : SqlParameter(org.springframework.jdbc.core.SqlParameter) AlbumInfo(com.github.hakko.musiccabinet.domain.model.music.AlbumInfo) 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