Search in sources :

Example 21 with BatchSqlUpdate

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

the class JdbcArtistInfoDao method batchInsert.

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

Example 22 with BatchSqlUpdate

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

the class JdbcArtistRelationDao method batchInsert.

private void batchInsert(Artist sourceArtist, List<ArtistRelation> ArtistRelations) {
    int sourceArtistId = jdbcTemplate.queryForInt("select * from music.get_artist_id(?)", sourceArtist.getName());
    String sql = "insert into music.artistrelation_import (source_id, target_artist_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("weight", Types.FLOAT));
    for (ArtistRelation ar : ArtistRelations) {
        batchUpdate.update(new Object[] { sourceArtistId, ar.getTarget().getName(), ar.getMatch() });
    }
    batchUpdate.flush();
}
Also used : ArtistRelation(com.github.hakko.musiccabinet.domain.model.music.ArtistRelation) SqlParameter(org.springframework.jdbc.core.SqlParameter) BatchSqlUpdate(org.springframework.jdbc.object.BatchSqlUpdate)

Example 23 with BatchSqlUpdate

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

the class JdbcArtistTopTagsDao method batchInsert.

private void batchInsert(Artist artist, List<Tag> tags) {
    int sourceArtistId = jdbcTemplate.queryForInt("select * from music.get_artist_id(?)", artist.getName());
    String sql = "insert into music.artisttoptag_import (artist_id, tag_name, tag_count) values (?,?,?)";
    BatchSqlUpdate batchUpdate = new BatchSqlUpdate(jdbcTemplate.getDataSource(), sql);
    batchUpdate.setBatchSize(1000);
    batchUpdate.declareParameter(new SqlParameter("artist_id", Types.INTEGER));
    batchUpdate.declareParameter(new SqlParameter("tag_name", Types.VARCHAR));
    batchUpdate.declareParameter(new SqlParameter("tag_count", Types.SMALLINT));
    for (Tag tag : tags) {
        batchUpdate.update(new Object[] { sourceArtistId, tag.getName(), tag.getCount() });
    }
    batchUpdate.flush();
}
Also used : SqlParameter(org.springframework.jdbc.core.SqlParameter) BatchSqlUpdate(org.springframework.jdbc.object.BatchSqlUpdate) Tag(com.github.hakko.musiccabinet.domain.model.music.Tag)

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