Search in sources :

Example 41 with SqlParameter

use of org.springframework.jdbc.core.SqlParameter in project musiccabinet by hakko.

the class JdbcArtistRelationDao method batchInsert.

private void batchInsert(Artist sourceArtist, List<ArtistRelation> ArtistRelations) {
    int sourceArtistId = jdbcTemplate.queryForInt("select * from music.get_artist_id(?)", sourceArtist.getName());
    String sql = "insert into music.artistrelation_import (source_id, target_artist_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("weight", Types.FLOAT));
    for (ArtistRelation ar : ArtistRelations) {
        batchUpdate.update(new Object[] { sourceArtistId, ar.getTarget().getName(), ar.getMatch() });
    }
    batchUpdate.flush();
}
Also used : ArtistRelation(com.github.hakko.musiccabinet.domain.model.music.ArtistRelation) SqlParameter(org.springframework.jdbc.core.SqlParameter) BatchSqlUpdate(org.springframework.jdbc.object.BatchSqlUpdate)

Example 42 with SqlParameter

use of org.springframework.jdbc.core.SqlParameter in project musiccabinet by hakko.

the class JdbcArtistTopTagsDao method batchInsert.

private void batchInsert(Artist artist, List<Tag> tags) {
    int sourceArtistId = jdbcTemplate.queryForInt("select * from music.get_artist_id(?)", artist.getName());
    String sql = "insert into music.artisttoptag_import (artist_id, tag_name, tag_count) values (?,?,?)";
    BatchSqlUpdate batchUpdate = new BatchSqlUpdate(jdbcTemplate.getDataSource(), sql);
    batchUpdate.setBatchSize(1000);
    batchUpdate.declareParameter(new SqlParameter("artist_id", Types.INTEGER));
    batchUpdate.declareParameter(new SqlParameter("tag_name", Types.VARCHAR));
    batchUpdate.declareParameter(new SqlParameter("tag_count", Types.SMALLINT));
    for (Tag tag : tags) {
        batchUpdate.update(new Object[] { sourceArtistId, tag.getName(), tag.getCount() });
    }
    batchUpdate.flush();
}
Also used : SqlParameter(org.springframework.jdbc.core.SqlParameter) BatchSqlUpdate(org.springframework.jdbc.object.BatchSqlUpdate) Tag(com.github.hakko.musiccabinet.domain.model.music.Tag)

Example 43 with SqlParameter

use of org.springframework.jdbc.core.SqlParameter in project musiccabinet by hakko.

the class JdbcLibraryDeletionDao method deleteSubdirectories.

@Override
public void deleteSubdirectories(String directory, Set<String> subDirectories) {
    String sql = "insert into library.directory_delete (path) values (?)";
    BatchSqlUpdate batchUpdate = new BatchSqlUpdate(jdbcTemplate.getDataSource(), sql);
    batchUpdate.declareParameter(new SqlParameter("path", Types.VARCHAR));
    for (String subDirectory : subDirectories) {
        batchUpdate.update(new Object[] { subDirectory });
    }
    batchUpdate.flush();
}
Also used : SqlParameter(org.springframework.jdbc.core.SqlParameter) BatchSqlUpdate(org.springframework.jdbc.object.BatchSqlUpdate)

Example 44 with SqlParameter

use of org.springframework.jdbc.core.SqlParameter in project musiccabinet by hakko.

the class JdbcMusicBrainzArtistDao method batchInsert.

private void batchInsert(List<MBArtist> artists) {
    String sql = "insert into music.mb_artist_import (artist_name, mbid, country_code, start_year, active) values (?,?,?,?,?)";
    BatchSqlUpdate batchUpdate = new BatchSqlUpdate(jdbcTemplate.getDataSource(), sql);
    batchUpdate.setBatchSize(1000);
    batchUpdate.declareParameter(new SqlParameter("artist_name", Types.VARCHAR));
    batchUpdate.declareParameter(new SqlParameter("mbid", Types.VARCHAR));
    batchUpdate.declareParameter(new SqlParameter("county_code", Types.VARCHAR));
    batchUpdate.declareParameter(new SqlParameter("start_year", Types.SMALLINT));
    batchUpdate.declareParameter(new SqlParameter("active", Types.BOOLEAN));
    for (MBArtist artist : artists) {
        batchUpdate.update(new Object[] { artist.getName(), artist.getMbid(), artist.getCountryCode(), artist.getStartYear(), artist.isActive() });
    }
    batchUpdate.flush();
}
Also used : MBArtist(com.github.hakko.musiccabinet.domain.model.music.MBArtist) SqlParameter(org.springframework.jdbc.core.SqlParameter) BatchSqlUpdate(org.springframework.jdbc.object.BatchSqlUpdate)

Example 45 with SqlParameter

use of org.springframework.jdbc.core.SqlParameter in project musiccabinet by hakko.

the class JdbcTagInfoDao method createTagInfo.

@Override
public void createTagInfo(List<TagInfo> tagInfos) {
    String sql = "insert into music.taginfo_import (tag_name, summary, content) values (?,?,?)";
    BatchSqlUpdate batchUpdate = new BatchSqlUpdate(jdbcTemplate.getDataSource(), sql);
    batchUpdate.setBatchSize(1000);
    batchUpdate.declareParameter(new SqlParameter("tag_name", VARCHAR));
    batchUpdate.declareParameter(new SqlParameter("summary", VARCHAR));
    batchUpdate.declareParameter(new SqlParameter("content", VARCHAR));
    for (TagInfo ti : tagInfos) {
        batchUpdate.update(new Object[] { ti.getTagName(), ti.getSummary(), ti.getContent() });
    }
    batchUpdate.flush();
    jdbcTemplate.execute("select music.update_taginfo()");
}
Also used : SqlParameter(org.springframework.jdbc.core.SqlParameter) TagInfo(com.github.hakko.musiccabinet.domain.model.music.TagInfo) BatchSqlUpdate(org.springframework.jdbc.object.BatchSqlUpdate)

Aggregations

SqlParameter (org.springframework.jdbc.core.SqlParameter)66 BatchSqlUpdate (org.springframework.jdbc.object.BatchSqlUpdate)23 Test (org.junit.Test)22 ResultSet (java.sql.ResultSet)15 DataSource (javax.sql.DataSource)15 HashMap (java.util.HashMap)12 Customer (org.springframework.jdbc.Customer)12 SqlOutParameter (org.springframework.jdbc.core.SqlOutParameter)6 LinkedHashMap (java.util.LinkedHashMap)5 ArrayList (java.util.ArrayList)4 InvalidDataAccessApiUsageException (org.springframework.dao.InvalidDataAccessApiUsageException)4 File (com.github.hakko.musiccabinet.domain.model.library.File)3 PreparedStatementCreatorFactory (org.springframework.jdbc.core.PreparedStatementCreatorFactory)3 MapSqlParameterSource (org.springframework.jdbc.core.namedparam.MapSqlParameterSource)3 Track (com.github.hakko.musiccabinet.domain.model.music.Track)2 PreparedStatement (java.sql.PreparedStatement)2 Map (java.util.Map)2 CallableStatementCreatorFactory (org.springframework.jdbc.core.CallableStatementCreatorFactory)2 SqlParameterValue (org.springframework.jdbc.core.SqlParameterValue)2 DriverManagerDataSource (org.springframework.jdbc.datasource.DriverManagerDataSource)2