use of net.robinfriedli.aiode.persist.tasks.UpdatePlaylistItemIndicesTask in project aiode by robinfriedli.
the class VerifyPlaylistInterceptor method preFlush.
@Override
public void preFlush(Iterator entities) {
@SuppressWarnings("unchecked") Iterable<Object> iterable = () -> entities;
Set<Playlist> playlistsToUpdate = StreamSupport.stream(iterable.spliterator(), false).filter(entity -> entity instanceof PlaylistItem).map(entity -> ((PlaylistItem) entity).getPlaylist()).collect(Collectors.toSet());
if (!playlistsToUpdate.isEmpty()) {
playlistsToUpdate.forEach(this::checkPlaylistSize);
UpdatePlaylistItemIndicesTask task = new UpdatePlaylistItemIndicesTask(playlistsToUpdate, Comparator.comparing(PlaylistItem::getOrdinal));
task.perform();
}
super.preFlush(entities);
}
use of net.robinfriedli.aiode.persist.tasks.UpdatePlaylistItemIndicesTask in project aiode by robinfriedli.
the class SetPlaylistItemIndexTask method perform.
@Override
public void perform(@Nullable JDA shard) {
try (Session session = sessionFactory.openSession()) {
Query<Playlist> relevantPlaylistQuery = session.createQuery("from " + Playlist.class.getName() + " as p where " + "exists(from " + Song.class.getName() + " where item_index = null and playlist_pk = p.pk) or " + "exists(from " + Video.class.getName() + " where item_index = null and playlist_pk = p.pk) or " + "exists(from " + UrlTrack.class.getName() + " where item_index = null and playlist_pk = p.pk)", Playlist.class);
List<Playlist> relevantPlaylists = relevantPlaylistQuery.getResultList();
session.beginTransaction();
UpdatePlaylistItemIndicesTask task = new UpdatePlaylistItemIndicesTask(relevantPlaylists);
task.perform();
session.getTransaction().commit();
}
}
Aggregations