use of com.github.hakko.musiccabinet.domain.model.music.MBRelease 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 com.github.hakko.musiccabinet.domain.model.music.MBRelease in project musiccabinet by hakko.
the class JdbcMusicBrainzAlbumDaoTest method prepareTestData.
@Before
public void prepareTestData() throws ApplicationException {
PostgreSQLUtil.loadFunction(albumDao, UPDATE_MB_ALBUM);
additionDao.getJdbcTemplate().execute("truncate music.artist cascade");
additionDao.getJdbcTemplate().execute("truncate library.file cascade");
artist = new Artist(ARTIST);
musicDao.setArtistId(artist);
album1 = new MBRelease(MBID1, null, null, TITLE1, TYPE1, YEAR1, null);
album2 = new MBRelease(MBID2, null, null, TITLE2, TYPE2, YEAR2, null);
album1.setArtistId(artist.getId());
album2.setArtistId(artist.getId());
albumDao.createAlbums(Arrays.asList(album1, album2));
}
use of com.github.hakko.musiccabinet.domain.model.music.MBRelease in project musiccabinet by hakko.
the class MusicBrainzService method updateArtistDiscographies.
protected void updateArtistDiscographies() {
List<MBArtist> outdatedArtists = artistDao.getOutdatedArtists();
List<MBRelease> mbReleases = new ArrayList<>();
ReleaseParser parser;
discographies = outdatedArtists.size();
for (MBArtist artist : outdatedArtists) {
try {
int offset = 0;
do {
StringUtil response = new StringUtil(releaseClient.get(artist.getName(), artist.getMbid(), offset));
parser = new ReleaseParserImpl(response.getInputStream());
for (MBRelease album : parser.getReleases()) {
album.setArtistId(artist.getId());
}
mbReleases.addAll(parser.getReleases());
offset += 100;
} while (offset < parser.getTotalReleases());
++discography;
if (mbReleases.size() > 1000) {
albumDao.createAlbums(mbReleases);
mbReleases.clear();
}
} catch (ApplicationException e) {
LOG.warn("Couldn't read discography for " + artist.getName(), e);
}
}
albumDao.createAlbums(mbReleases);
}
use of com.github.hakko.musiccabinet.domain.model.music.MBRelease in project musiccabinet by hakko.
the class ReleaseHandler method startElement.
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
if (TAG_RELEASE_LIST.equals(qName)) {
totalAlbums = toInt(attributes.getValue(ATTR_COUNT));
} else if (TAG_RELEASE.equals(qName)) {
releases.add(currentRelease = new MBRelease());
} else if (TAG_RELEASE_GROUP.equals(qName)) {
currentRelease.setReleaseGroupMbid(attributes.getValue(ATTR_ID));
currentRelease.setAlbumType(attributes.getValue(ATTR_TYPE));
} else if (TAG_LABEL.equals(qName)) {
currentRelease.setLabelMbid(attributes.getValue(ATTR_ID));
label = true;
}
characterData = new StringBuilder();
}
Aggregations