Package org.springframework.jdbc.object

Examples of org.springframework.jdbc.object.BatchSqlUpdate


  private void batchInsert(Track sourceTrack, List<TrackRelation> trackRelations) {
    int sourceTrackId = jdbcTemplate.queryForInt("select * from music.get_track_id(?,?)",
        sourceTrack.getArtist().getName(), sourceTrack.getName());
   
    String sql = "insert into music.trackrelation_import (source_id, target_artist_name, target_track_name, weight) values (?,?,?,?)";
    BatchSqlUpdate batchUpdate = new BatchSqlUpdate(jdbcTemplate.getDataSource(), sql);
    batchUpdate.setBatchSize(1000);
    batchUpdate.declareParameter(new SqlParameter("source_id", Types.INTEGER));
    batchUpdate.declareParameter(new SqlParameter("target_artist_name", Types.VARCHAR));
    batchUpdate.declareParameter(new SqlParameter("target_track_name", Types.VARCHAR));
    batchUpdate.declareParameter(new SqlParameter("weight", Types.FLOAT));
   
    for (TrackRelation tr : trackRelations) {
      batchUpdate.update(new Object[]{
          sourceTrackId, tr.getTarget().getArtist().getName(),
          tr.getTarget().getName(), tr.getMatch()});
    }
    batchUpdate.flush();
  }
View Full Code Here


  @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();

  }
View Full Code Here

  @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);
  }
View Full Code Here

    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();
  }
View Full Code Here

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

  }
View Full Code Here

    jdbcTemplate.execute("truncate music.usertopartist_import");
  }

  private void batchInsert(List<Artist> artists, LastFmUser user, Period period) {
    String sql = "insert into music.usertopartist_import (lastfm_user, artist_name, rank, days) values (?,?,?,?)";
    BatchSqlUpdate batchUpdate = new BatchSqlUpdate(jdbcTemplate.getDataSource(), sql);
    batchUpdate.setBatchSize(1000);
    batchUpdate.declareParameter(new SqlParameter("lastfm_user", Types.VARCHAR));
    batchUpdate.declareParameter(new SqlParameter("artist_name", Types.VARCHAR));
    batchUpdate.declareParameter(new SqlParameter("rank", Types.INTEGER));
    batchUpdate.declareParameter(new SqlParameter("days", Types.INTEGER));
   
    for (int i = 0; i < artists.size(); i++) {
      batchUpdate.update(new Object[]{user.getLastFmUsername(),
          artists.get(i).getName(), i, period.getDays()});
    }
    batchUpdate.flush();
  }
View Full Code Here

  }
 
  private void batchInsert(String lastFmUsername, List<Track> lovedTracks) {
    String sql = "insert into music.lovedtrack_import"
        + " (lastfm_user, artist_name, track_name) values (?,?,?)";
    BatchSqlUpdate batchUpdate = new BatchSqlUpdate(jdbcTemplate.getDataSource(), sql);
    batchUpdate.setBatchSize(1000);
    batchUpdate.declareParameter(new SqlParameter("lastfm_user", Types.VARCHAR));
    batchUpdate.declareParameter(new SqlParameter("artist_name", Types.VARCHAR));
    batchUpdate.declareParameter(new SqlParameter("track_name", Types.VARCHAR));
   
    for (Track track : lovedTracks) {
      batchUpdate.update(new Object[]{lastFmUsername,
          track.getArtist().getName(), track.getName()});
    }
    batchUpdate.flush();
  }
View Full Code Here

  @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();
  }
View Full Code Here

        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();
  }
View Full Code Here

    jdbcTemplate.execute("truncate music.tagtopartist_import");
  }

  private void batchInsert(String tagName, List<Artist> artists) {
    String sql = "insert into music.tagtopartist_import (tag_name, artist_name, rank) values (?,?,?)";
    BatchSqlUpdate batchUpdate = new BatchSqlUpdate(jdbcTemplate.getDataSource(), sql);
    batchUpdate.setBatchSize(1000);
    batchUpdate.declareParameter(new SqlParameter("tag_name", Types.VARCHAR));
    batchUpdate.declareParameter(new SqlParameter("artist_name", Types.VARCHAR));
    batchUpdate.declareParameter(new SqlParameter("rank", Types.INTEGER));

    for (int i = 0; i < artists.size(); i++) {
      batchUpdate.update(new Object[]{tagName, artists.get(i).getName(), i});
    }
    batchUpdate.flush();
  }
View Full Code Here

TOP

Related Classes of org.springframework.jdbc.object.BatchSqlUpdate

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.