Search in sources :

Example 1 with BatchSqlUpdate

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()");
}
Also used : SqlParameter(org.springframework.jdbc.core.SqlParameter) LastFmGroup(com.github.hakko.musiccabinet.domain.model.library.LastFmGroup) BatchSqlUpdate(org.springframework.jdbc.object.BatchSqlUpdate)

Example 2 with BatchSqlUpdate

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();
}
Also used : SqlParameter(org.springframework.jdbc.core.SqlParameter) BatchSqlUpdate(org.springframework.jdbc.object.BatchSqlUpdate)

Example 3 with BatchSqlUpdate

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();
}
Also used : SqlParameter(org.springframework.jdbc.core.SqlParameter) BatchSqlUpdate(org.springframework.jdbc.object.BatchSqlUpdate) File(com.github.hakko.musiccabinet.domain.model.library.File)

Example 4 with BatchSqlUpdate

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();
}
Also used : SqlParameter(org.springframework.jdbc.core.SqlParameter) BatchSqlUpdate(org.springframework.jdbc.object.BatchSqlUpdate) MBRelease(com.github.hakko.musiccabinet.domain.model.music.MBRelease)

Example 5 with BatchSqlUpdate

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();
}
Also used : SqlParameter(org.springframework.jdbc.core.SqlParameter) BatchSqlUpdate(org.springframework.jdbc.object.BatchSqlUpdate)

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