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();
}
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);
}
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();
}
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();
}
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();
}
Aggregations