jdbcTemplate.execute("truncate music.albuminfo_import");
}
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();
}