use of org.springframework.jdbc.object.BatchSqlUpdate in project musiccabinet by hakko.
the class JdbcLastFmDao method setLastFmGroups.
@Override
public void setLastFmGroups(List<LastFmGroup> lastFmGroups) {
jdbcTemplate.update("truncate music.lastfmgroup_import");
String sql = "insert into music.lastfmgroup_import (group_name) values (?)";
BatchSqlUpdate batchUpdate = new BatchSqlUpdate(jdbcTemplate.getDataSource(), sql);
batchUpdate.setBatchSize(1000);
batchUpdate.declareParameter(new SqlParameter("group_name", Types.VARCHAR));
for (LastFmGroup group : lastFmGroups) {
batchUpdate.update(new Object[] { group.getName() });
}
batchUpdate.flush();
jdbcTemplate.execute("select music.update_lastfmgroup()");
}
use of org.springframework.jdbc.object.BatchSqlUpdate in project musiccabinet by hakko.
the class JdbcLibraryAdditionDao method addSubdirectories.
@Override
public void addSubdirectories(String directory, Set<String> subDirectories) {
String sql = "insert into library.directory_import (parent_path, path) values (?,?)";
BatchSqlUpdate batchUpdate = new BatchSqlUpdate(jdbcTemplate.getDataSource(), sql);
batchUpdate.declareParameter(new SqlParameter("parent_path", Types.VARCHAR));
batchUpdate.declareParameter(new SqlParameter("path", Types.VARCHAR));
for (String subDirectory : subDirectories) {
batchUpdate.update(new Object[] { directory, subDirectory });
}
batchUpdate.flush();
}
use of org.springframework.jdbc.object.BatchSqlUpdate in project musiccabinet by hakko.
the class JdbcLibraryDeletionDao method deleteFiles.
@Override
public void deleteFiles(String directory, Set<File> files) {
String sql = "insert into library.file_delete (path, filename) values (?,?)";
BatchSqlUpdate batchUpdate = new BatchSqlUpdate(jdbcTemplate.getDataSource(), sql);
batchUpdate.declareParameter(new SqlParameter("path", Types.VARCHAR));
batchUpdate.declareParameter(new SqlParameter("filename", Types.VARCHAR));
for (File file : files) {
batchUpdate.update(new Object[] { file.getDirectory(), file.getFilename() });
}
batchUpdate.flush();
}
use of org.springframework.jdbc.object.BatchSqlUpdate in project musiccabinet by hakko.
the class JdbcMusicBrainzAlbumDao method batchInsert.
private void batchInsert(List<MBRelease> releases) {
String sql = "insert into music.mb_album_import" + " (artist_id, title, type_id, release_year, label_name," + " label_mbid, format, release_group_mbid) values (?,?,?,?,?,?,?,?)";
BatchSqlUpdate batchUpdate = new BatchSqlUpdate(jdbcTemplate.getDataSource(), sql);
batchUpdate.setBatchSize(1000);
batchUpdate.declareParameter(new SqlParameter("artist_id", Types.INTEGER));
batchUpdate.declareParameter(new SqlParameter("title", Types.VARCHAR));
batchUpdate.declareParameter(new SqlParameter("type_id", Types.INTEGER));
batchUpdate.declareParameter(new SqlParameter("release_year", Types.SMALLINT));
batchUpdate.declareParameter(new SqlParameter("label_name", Types.VARCHAR));
batchUpdate.declareParameter(new SqlParameter("label_mbid", Types.VARCHAR));
batchUpdate.declareParameter(new SqlParameter("format", Types.VARCHAR));
batchUpdate.declareParameter(new SqlParameter("release_group_mbid", Types.VARCHAR));
for (MBRelease r : releases) {
if (r.isValid()) {
batchUpdate.update(new Object[] { r.getArtistId(), r.getTitle(), r.getAlbumType().ordinal(), r.getReleaseYear(), r.getLabelName(), r.getLabelMbid(), r.getFormat(), r.getReleaseGroupMbid() });
} else {
LOG.warn("Invalid MusicBrainz release ignored: " + r);
}
}
batchUpdate.flush();
}
use of org.springframework.jdbc.object.BatchSqlUpdate in project musiccabinet by hakko.
the class JdbcTagDao method createTags.
@Override
public void createTags(List<String> tags) {
String sql = "insert into music.tag (tag_name) select distinct (?)" + " where not exists (select 1 from music.tag where tag_name = ?)";
BatchSqlUpdate batchUpdate = new BatchSqlUpdate(jdbcTemplate.getDataSource(), sql);
batchUpdate.setBatchSize(1000);
batchUpdate.declareParameter(new SqlParameter("tag_name", Types.VARCHAR));
batchUpdate.declareParameter(new SqlParameter("tag_name", Types.VARCHAR));
for (String tag : tags) {
batchUpdate.update(new Object[] { tag, tag });
}
batchUpdate.flush();
}
Aggregations