use of org.springframework.jdbc.core.SqlParameter 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.core.SqlParameter 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.core.SqlParameter 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.core.SqlParameter 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();
}
use of org.springframework.jdbc.core.SqlParameter in project musiccabinet by hakko.
the class JdbcTagDao method createTagCorrections.
/*
* tagCorrection is a map of <original tag name> -> <corrected tag name>
*/
@Override
public void createTagCorrections(Map<String, String> tagCorrections) {
String sql = "update music.tag t set corrected_id = null where corrected_id is not null";
jdbcTemplate.execute(sql);
if (tagCorrections.size() == 0)
return;
sql = getCreateMissingTagsSql(tagCorrections.size());
jdbcTemplate.update(sql, (Object[]) tagCorrections.keySet().toArray(new String[tagCorrections.size()]));
jdbcTemplate.update(sql, (Object[]) tagCorrections.values().toArray(new String[tagCorrections.size()]));
sql = "update music.tag t set corrected_id = tc.id" + " from music.tag tc where t.tag_name = ? and tc.tag_name = ?";
BatchSqlUpdate batchUpdate = new BatchSqlUpdate(jdbcTemplate.getDataSource(), sql);
batchUpdate.setBatchSize(1000);
batchUpdate.declareParameter(new SqlParameter("t.tag_name", Types.VARCHAR));
batchUpdate.declareParameter(new SqlParameter("tc.tag_name", Types.VARCHAR));
for (String tag : tagCorrections.keySet()) {
batchUpdate.update(new Object[] { tag, tagCorrections.get(tag) });
}
batchUpdate.flush();
}
Aggregations