From 41408bc2c32ac8c19c2dd0415ffe33aef955e0ab Mon Sep 17 00:00:00 2001 From: jvoisin Date: Thu, 25 Apr 2019 22:32:45 +0200 Subject: [PATCH] Replace the double-mustache anti-pattern Because Double Brace Initialization (DBI) creates an anonymous class with a reference to the instance of the owning object, its use can lead to memory leaks if the anonymous inner class is returned and held by other objects. Even when there's no leak, DBI is so obscure that it's bound to confuse most maintainers. --- .../org/airsonic/player/dao/AlbumDao.java | 78 +++---- .../org/airsonic/player/dao/ArtistDao.java | 27 +-- .../org/airsonic/player/dao/MediaFileDao.java | 209 ++++++++---------- .../org/airsonic/player/dao/RatingDao.java | 20 +- .../org/airsonic/player/dao/ShareDao.java | 7 +- 5 files changed, 155 insertions(+), 186 deletions(-) diff --git a/airsonic-main/src/main/java/org/airsonic/player/dao/AlbumDao.java b/airsonic-main/src/main/java/org/airsonic/player/dao/AlbumDao.java index 2fd823d6..71b73cc0 100644 --- a/airsonic-main/src/main/java/org/airsonic/player/dao/AlbumDao.java +++ b/airsonic-main/src/main/java/org/airsonic/player/dao/AlbumDao.java @@ -98,10 +98,9 @@ public class AlbumDao extends AbstractDao { if (musicFolders.isEmpty()) { return Collections.emptyList(); } - Map args = new HashMap() {{ - put("artist", artist); - put("folders", MusicFolder.toIdList(musicFolders)); - }}; + Map args = new HashMap<>(); + args.put("artist", artist); + args.put("folders", MusicFolder.toIdList(musicFolders)); return namedQuery("select " + QUERY_COLUMNS + " from album where artist = :artist and present and folder_id in (:folders) " + "order by name", @@ -176,11 +175,10 @@ public class AlbumDao extends AbstractDao { if (musicFolders.isEmpty()) { return Collections.emptyList(); } - Map args = new HashMap() {{ - put("folders", MusicFolder.toIdList(musicFolders)); - put("count", count); - put("offset", offset); - }}; + Map args = new HashMap<>(); + args.put("folders", MusicFolder.toIdList(musicFolders)); + args.put("count", count); + args.put("offset", offset); String orderBy; if (ignoreCase) { orderBy = byArtist ? "LOWER(artist), LOWER(name)" : "LOWER(name)"; @@ -221,11 +219,10 @@ public class AlbumDao extends AbstractDao { if (musicFolders.isEmpty()) { return Collections.emptyList(); } - Map args = new HashMap() {{ - put("folders", MusicFolder.toIdList(musicFolders)); - put("count", count); - put("offset", offset); - }}; + Map args = new HashMap<>(); + args.put("folders", MusicFolder.toIdList(musicFolders)); + args.put("count", count); + args.put("offset", offset); return namedQuery("select " + QUERY_COLUMNS + " from album where play_count > 0 and present and folder_id in (:folders) " + "order by play_count desc limit :count offset :offset", rowMapper, args); @@ -243,11 +240,10 @@ public class AlbumDao extends AbstractDao { if (musicFolders.isEmpty()) { return Collections.emptyList(); } - Map args = new HashMap() {{ - put("folders", MusicFolder.toIdList(musicFolders)); - put("count", count); - put("offset", offset); - }}; + Map args = new HashMap<>(); + args.put("folders", MusicFolder.toIdList(musicFolders)); + args.put("count", count); + args.put("offset", offset); return namedQuery("select " + QUERY_COLUMNS + " from album where last_played is not null and present and folder_id in (:folders) " + "order by last_played desc limit :count offset :offset", rowMapper, args); @@ -265,11 +261,10 @@ public class AlbumDao extends AbstractDao { if (musicFolders.isEmpty()) { return Collections.emptyList(); } - Map args = new HashMap() {{ - put("folders", MusicFolder.toIdList(musicFolders)); - put("count", count); - put("offset", offset); - }}; + Map args = new HashMap<>(); + args.put("folders", MusicFolder.toIdList(musicFolders)); + args.put("count", count); + args.put("offset", offset); return namedQuery("select " + QUERY_COLUMNS + " from album where present and folder_id in (:folders) " + "order by created desc limit :count offset :offset", rowMapper, args); } @@ -287,12 +282,11 @@ public class AlbumDao extends AbstractDao { if (musicFolders.isEmpty()) { return Collections.emptyList(); } - Map args = new HashMap() {{ - put("folders", MusicFolder.toIdList(musicFolders)); - put("count", count); - put("offset", offset); - put("username", username); - }}; + Map args = new HashMap<>(); + args.put("folders", MusicFolder.toIdList(musicFolders)); + args.put("count", count); + args.put("offset", offset); + args.put("username", username); return namedQuery("select " + prefix(QUERY_COLUMNS, "album") + " from starred_album, album where album.id = starred_album.album_id and " + "album.present and album.folder_id in (:folders) and starred_album.username = :username " + "order by starred_album.created desc limit :count offset :offset", @@ -312,12 +306,11 @@ public class AlbumDao extends AbstractDao { if (musicFolders.isEmpty()) { return Collections.emptyList(); } - Map args = new HashMap() {{ - put("folders", MusicFolder.toIdList(musicFolders)); - put("count", count); - put("offset", offset); - put("genre", genre); - }}; + Map args = new HashMap<>(); + args.put("folders", MusicFolder.toIdList(musicFolders)); + args.put("count", count); + args.put("offset", offset); + args.put("genre", genre); return namedQuery("select " + QUERY_COLUMNS + " from album where present and folder_id in (:folders) " + "and genre = :genre limit :count offset :offset", rowMapper, args); } @@ -337,13 +330,12 @@ public class AlbumDao extends AbstractDao { if (musicFolders.isEmpty()) { return Collections.emptyList(); } - Map args = new HashMap() {{ - put("folders", MusicFolder.toIdList(musicFolders)); - put("count", count); - put("offset", offset); - put("fromYear", fromYear); - put("toYear", toYear); - }}; + Map args = new HashMap<>(); + args.put("folders", MusicFolder.toIdList(musicFolders)); + args.put("count", count); + args.put("offset", offset); + args.put("fromYear", fromYear); + args.put("toYear", toYear); if (fromYear <= toYear) { return namedQuery("select " + QUERY_COLUMNS + " from album where present and folder_id in (:folders) " + "and year between :fromYear and :toYear order by year limit :count offset :offset", diff --git a/airsonic-main/src/main/java/org/airsonic/player/dao/ArtistDao.java b/airsonic-main/src/main/java/org/airsonic/player/dao/ArtistDao.java index f479a4d6..dd051711 100644 --- a/airsonic-main/src/main/java/org/airsonic/player/dao/ArtistDao.java +++ b/airsonic-main/src/main/java/org/airsonic/player/dao/ArtistDao.java @@ -66,10 +66,9 @@ public class ArtistDao extends AbstractDao { if (musicFolders.isEmpty()) { return null; } - Map args = new HashMap() {{ - put("name", artistName); - put("folders", MusicFolder.toIdList(musicFolders)); - }}; + Map args = new HashMap<>(); + args.put("name", artistName); + args.put("folders", MusicFolder.toIdList(musicFolders)); return namedQueryOne("select " + QUERY_COLUMNS + " from artist where name = :name and folder_id in (:folders)", rowMapper, args); @@ -123,11 +122,10 @@ public class ArtistDao extends AbstractDao { if (musicFolders.isEmpty()) { return Collections.emptyList(); } - Map args = new HashMap() {{ - put("folders", MusicFolder.toIdList(musicFolders)); - put("count", count); - put("offset", offset); - }}; + Map args = new HashMap<>(); + args.put("folders", MusicFolder.toIdList(musicFolders)); + args.put("count", count); + args.put("offset", offset); return namedQuery("select " + QUERY_COLUMNS + " from artist where present and folder_id in (:folders) " + "order by name limit :count offset :offset", rowMapper, args); @@ -147,12 +145,11 @@ public class ArtistDao extends AbstractDao { if (musicFolders.isEmpty()) { return Collections.emptyList(); } - Map args = new HashMap() {{ - put("folders", MusicFolder.toIdList(musicFolders)); - put("username", username); - put("count", count); - put("offset", offset); - }}; + Map args = new HashMap<>(); + args.put("folders", MusicFolder.toIdList(musicFolders)); + args.put("username", username); + args.put("count", count); + args.put("offset", offset); return namedQuery("select " + prefix(QUERY_COLUMNS, "artist") + " from starred_artist, artist " + "where artist.id = starred_artist.artist_id and " + diff --git a/airsonic-main/src/main/java/org/airsonic/player/dao/MediaFileDao.java b/airsonic-main/src/main/java/org/airsonic/player/dao/MediaFileDao.java index c9e7e6f1..67b9a65f 100644 --- a/airsonic-main/src/main/java/org/airsonic/player/dao/MediaFileDao.java +++ b/airsonic-main/src/main/java/org/airsonic/player/dao/MediaFileDao.java @@ -104,12 +104,11 @@ public class MediaFileDao extends AbstractDao { if (musicFolders.isEmpty()) { return Collections.emptyList(); } - Map args = new HashMap() {{ - put("type", MediaFile.MediaType.VIDEO.name()); - put("folders", MusicFolder.toPathList(musicFolders)); - put("count", count); - put("offset", offset); - }}; + Map args = new HashMap<>(); + args.put("type", MediaFile.MediaType.VIDEO.name()); + args.put("folders", MusicFolder.toPathList(musicFolders)); + args.put("count", count); + args.put("offset", offset); return namedQuery("select " + QUERY_COLUMNS + " from media_file where type = :type and present and folder in (:folders) " + "order by title limit :count offset :offset", rowMapper, args); @@ -119,11 +118,10 @@ public class MediaFileDao extends AbstractDao { if (musicFolders.isEmpty()) { return null; } - Map args = new HashMap() {{ - put("type", MediaFile.MediaType.DIRECTORY.name()); - put("name", name); - put("folders", MusicFolder.toPathList(musicFolders)); - }}; + Map args = new HashMap<>(); + args.put("type", MediaFile.MediaType.DIRECTORY.name()); + args.put("name", name); + args.put("folders", MusicFolder.toPathList(musicFolders)); return namedQueryOne("select " + QUERY_COLUMNS + " from media_file where type = :type and artist = :name " + "and present and folder in (:folders)", rowMapper, args); } @@ -233,12 +231,11 @@ public class MediaFileDao extends AbstractDao { if (musicFolders.isEmpty()) { return Collections.emptyList(); } - Map args = new HashMap() {{ - put("type", MediaFile.MediaType.ALBUM.name()); - put("folders", MusicFolder.toPathList(musicFolders)); - put("count", count); - put("offset", offset); - }}; + Map args = new HashMap<>(); + args.put("type", MediaFile.MediaType.ALBUM.name()); + args.put("folders", MusicFolder.toPathList(musicFolders)); + args.put("count", count); + args.put("offset", offset); return namedQuery("select " + QUERY_COLUMNS + " from media_file where type = :type and play_count > 0 and present and folder in (:folders) " + @@ -257,12 +254,11 @@ public class MediaFileDao extends AbstractDao { if (musicFolders.isEmpty()) { return Collections.emptyList(); } - Map args = new HashMap() {{ - put("type", MediaFile.MediaType.ALBUM.name()); - put("folders", MusicFolder.toPathList(musicFolders)); - put("count", count); - put("offset", offset); - }}; + Map args = new HashMap<>(); + args.put("type", MediaFile.MediaType.ALBUM.name()); + args.put("folders", MusicFolder.toPathList(musicFolders)); + args.put("count", count); + args.put("offset", offset); return namedQuery("select " + QUERY_COLUMNS + " from media_file where type = :type and last_played is not null and present " + "and folder in (:folders) order by last_played desc limit :count offset :offset", rowMapper, args); @@ -280,12 +276,11 @@ public class MediaFileDao extends AbstractDao { if (musicFolders.isEmpty()) { return Collections.emptyList(); } - Map args = new HashMap() {{ - put("type", MediaFile.MediaType.ALBUM.name()); - put("folders", MusicFolder.toPathList(musicFolders)); - put("count", count); - put("offset", offset); - }}; + Map args = new HashMap<>(); + args.put("type", MediaFile.MediaType.ALBUM.name()); + args.put("folders", MusicFolder.toPathList(musicFolders)); + args.put("count", count); + args.put("offset", offset); return namedQuery("select " + QUERY_COLUMNS + " from media_file where type = :type and folder in (:folders) and present " + @@ -305,12 +300,11 @@ public class MediaFileDao extends AbstractDao { if (musicFolders.isEmpty()) { return Collections.emptyList(); } - Map args = new HashMap() {{ - put("type", MediaFile.MediaType.ALBUM.name()); - put("folders", MusicFolder.toPathList(musicFolders)); - put("count", count); - put("offset", offset); - }}; + Map args = new HashMap<>(); + args.put("type", MediaFile.MediaType.ALBUM.name()); + args.put("folders", MusicFolder.toPathList(musicFolders)); + args.put("count", count); + args.put("offset", offset); String orderBy = byArtist ? "artist, album" : "album"; return namedQuery("select " + QUERY_COLUMNS @@ -333,14 +327,13 @@ public class MediaFileDao extends AbstractDao { if (musicFolders.isEmpty()) { return Collections.emptyList(); } - Map args = new HashMap() {{ - put("type", MediaFile.MediaType.ALBUM.name()); - put("folders", MusicFolder.toPathList(musicFolders)); - put("fromYear", fromYear); - put("toYear", toYear); - put("count", count); - put("offset", offset); - }}; + Map args = new HashMap<>(); + args.put("type", MediaFile.MediaType.ALBUM.name()); + args.put("folders", MusicFolder.toPathList(musicFolders)); + args.put("fromYear", fromYear); + args.put("toYear", toYear); + args.put("count", count); + args.put("offset", offset); if (fromYear <= toYear) { return namedQuery("select " + QUERY_COLUMNS @@ -369,13 +362,12 @@ public class MediaFileDao extends AbstractDao { if (musicFolders.isEmpty()) { return Collections.emptyList(); } - Map args = new HashMap() {{ - put("type", MediaFile.MediaType.ALBUM.name()); - put("genre", genre); - put("folders", MusicFolder.toPathList(musicFolders)); - put("count", count); - put("offset", offset); - }}; + Map args = new HashMap<>(); + args.put("type", MediaFile.MediaType.ALBUM.name()); + args.put("genre", genre); + args.put("folders", MusicFolder.toPathList(musicFolders)); + args.put("count", count); + args.put("offset", offset); return namedQuery("select " + QUERY_COLUMNS + " from media_file where type = :type and folder in (:folders) " + "and present and genre = :genre limit :count offset :offset", rowMapper, args); } @@ -384,13 +376,12 @@ public class MediaFileDao extends AbstractDao { if (musicFolders.isEmpty()) { return Collections.emptyList(); } - Map args = new HashMap() {{ - put("types", Arrays.asList(MediaFile.MediaType.MUSIC.name(), MediaFile.MediaType.PODCAST.name(), MediaFile.MediaType.AUDIOBOOK.name())); - put("genre", genre); - put("count", count); - put("offset", offset); - put("folders", MusicFolder.toPathList(musicFolders)); - }}; + Map args = new HashMap<>(); + args.put("types", Arrays.asList(MediaFile.MediaType.MUSIC.name(), MediaFile.MediaType.PODCAST.name(), MediaFile.MediaType.AUDIOBOOK.name())); + args.put("genre", genre); + args.put("count", count); + args.put("offset", offset); + args.put("folders", MusicFolder.toPathList(musicFolders)); return namedQuery("select " + QUERY_COLUMNS + " from media_file where type in (:types) and genre = :genre " + "and present and folder in (:folders) limit :count offset :offset", rowMapper, args); @@ -406,12 +397,11 @@ public class MediaFileDao extends AbstractDao { if (musicFolders.isEmpty() || StringUtils.isBlank(title) || StringUtils.isBlank(artist)) { return null; } - Map args = new HashMap() {{ - put("artist", artist); - put("title", title); - put("type", MediaFile.MediaType.MUSIC.name()); - put("folders", MusicFolder.toPathList(musicFolders)); - }}; + Map args = new HashMap<>(); + args.put("artist", artist); + args.put("title", title); + args.put("type", MediaFile.MediaType.MUSIC.name()); + args.put("folders", MusicFolder.toPathList(musicFolders)); return namedQueryOne("select " + QUERY_COLUMNS + " from media_file where artist = :artist " + "and title = :title and type = :type and present and folder in (:folders)" , rowMapper, args); @@ -431,13 +421,12 @@ public class MediaFileDao extends AbstractDao { if (musicFolders.isEmpty()) { return Collections.emptyList(); } - Map args = new HashMap() {{ - put("type", MediaFile.MediaType.ALBUM.name()); - put("folders", MusicFolder.toPathList(musicFolders)); - put("username", username); - put("count", count); - put("offset", offset); - }}; + Map args = new HashMap<>(); + args.put("type", MediaFile.MediaType.ALBUM.name()); + args.put("folders", MusicFolder.toPathList(musicFolders)); + args.put("username", username); + args.put("count", count); + args.put("offset", offset); return namedQuery("select " + prefix(QUERY_COLUMNS, "media_file") + " from starred_media_file, media_file where media_file.id = starred_media_file.media_file_id and " + "media_file.present and media_file.type = :type and media_file.folder in (:folders) and starred_media_file.username = :username " + "order by starred_media_file.created desc limit :count offset :offset", @@ -458,13 +447,12 @@ public class MediaFileDao extends AbstractDao { if (musicFolders.isEmpty()) { return Collections.emptyList(); } - Map args = new HashMap() {{ - put("type", MediaFile.MediaType.DIRECTORY.name()); - put("folders", MusicFolder.toPathList(musicFolders)); - put("username", username); - put("count", count); - put("offset", offset); - }}; + Map args = new HashMap<>(); + args.put("type", MediaFile.MediaType.DIRECTORY.name()); + args.put("folders", MusicFolder.toPathList(musicFolders)); + args.put("username", username); + args.put("count", count); + args.put("offset", offset); return namedQuery("select " + prefix(QUERY_COLUMNS, "media_file") + " from starred_media_file, media_file " + "where media_file.id = starred_media_file.media_file_id and " + "media_file.present and media_file.type = :type and starred_media_file.username = :username and " + @@ -487,13 +475,12 @@ public class MediaFileDao extends AbstractDao { if (musicFolders.isEmpty()) { return Collections.emptyList(); } - Map args = new HashMap() {{ - put("types", Arrays.asList(MediaFile.MediaType.MUSIC.name(), MediaFile.MediaType.PODCAST.name(), MediaFile.MediaType.AUDIOBOOK.name(), MediaFile.MediaType.VIDEO.name())); - put("folders", MusicFolder.toPathList(musicFolders)); - put("username", username); - put("count", count); - put("offset", offset); - }}; + Map args = new HashMap<>(); + args.put("types", Arrays.asList(MediaFile.MediaType.MUSIC.name(), MediaFile.MediaType.PODCAST.name(), MediaFile.MediaType.AUDIOBOOK.name(), MediaFile.MediaType.VIDEO.name())); + args.put("folders", MusicFolder.toPathList(musicFolders)); + args.put("username", username); + args.put("count", count); + args.put("offset", offset); return namedQuery("select " + prefix(QUERY_COLUMNS, "media_file") + " from starred_media_file, media_file where media_file.id = starred_media_file.media_file_id and " + "media_file.present and media_file.type in (:types) and starred_media_file.username = :username and " + "media_file.folder in (:folders) " + @@ -506,22 +493,21 @@ public class MediaFileDao extends AbstractDao { return Collections.emptyList(); } - Map args = new HashMap() {{ - put("folders", MusicFolder.toPathList(criteria.getMusicFolders())); - put("username", username); - put("fromYear", criteria.getFromYear()); - put("toYear", criteria.getToYear()); - put("genre", criteria.getGenre()); - put("minLastPlayed", criteria.getMinLastPlayedDate()); - put("maxLastPlayed", criteria.getMaxLastPlayedDate()); - put("minAlbumRating", criteria.getMinAlbumRating()); - put("maxAlbumRating", criteria.getMaxAlbumRating()); - put("minPlayCount", criteria.getMinPlayCount()); - put("maxPlayCount", criteria.getMaxPlayCount()); - put("starred", criteria.isShowStarredSongs()); - put("unstarred", criteria.isShowUnstarredSongs()); - put("format", criteria.getFormat()); - }}; + Map args = new HashMap<>(); + args.put("folders", MusicFolder.toPathList(criteria.getMusicFolders())); + args.put("username", username); + args.put("fromYear", criteria.getFromYear()); + args.put("toYear", criteria.getToYear()); + args.put("genre", criteria.getGenre()); + args.put("minLastPlayed", criteria.getMinLastPlayedDate()); + args.put("maxLastPlayed", criteria.getMaxLastPlayedDate()); + args.put("minAlbumRating", criteria.getMinAlbumRating()); + args.put("maxAlbumRating", criteria.getMaxAlbumRating()); + args.put("minPlayCount", criteria.getMinPlayCount()); + args.put("maxPlayCount", criteria.getMaxPlayCount()); + args.put("starred", criteria.isShowStarredSongs()); + args.put("unstarred", criteria.isShowUnstarredSongs()); + args.put("format", criteria.getFormat()); boolean joinAlbumRating = (criteria.getMinAlbumRating() != null || criteria.getMaxAlbumRating() != null); boolean joinStarred = (criteria.isShowStarredSongs() ^ criteria.isShowUnstarredSongs()); @@ -612,10 +598,9 @@ public class MediaFileDao extends AbstractDao { if (musicFolders.isEmpty()) { return 0; } - Map args = new HashMap() {{ - put("type", MediaFile.MediaType.ALBUM.name()); - put("folders", MusicFolder.toPathList(musicFolders)); - }}; + Map args = new HashMap<>(); + args.put("type", MediaFile.MediaType.ALBUM.name()); + args.put("folders", MusicFolder.toPathList(musicFolders)); return namedQueryForInt("select count(*) from media_file where type = :type and folder in (:folders) and present", 0, args); } @@ -623,10 +608,9 @@ public class MediaFileDao extends AbstractDao { if (musicFolders.isEmpty()) { return 0; } - Map args = new HashMap() {{ - put("type", MediaFile.MediaType.ALBUM.name()); - put("folders", MusicFolder.toPathList(musicFolders)); - }}; + Map args = new HashMap<>(); + args.put("type", MediaFile.MediaType.ALBUM.name()); + args.put("folders", MusicFolder.toPathList(musicFolders)); return namedQueryForInt("select count(*) from media_file where type = :type " + "and play_count > 0 and present and folder in (:folders)", 0, args); } @@ -635,11 +619,10 @@ public class MediaFileDao extends AbstractDao { if (musicFolders.isEmpty()) { return 0; } - Map args = new HashMap() {{ - put("type", MediaFile.MediaType.ALBUM.name()); - put("folders", MusicFolder.toPathList(musicFolders)); - put("username", username); - }}; + Map args = new HashMap<>(); + args.put("type", MediaFile.MediaType.ALBUM.name()); + args.put("folders", MusicFolder.toPathList(musicFolders)); + args.put("username", uername); return namedQueryForInt("select count(*) from starred_media_file, media_file " + "where media_file.id = starred_media_file.media_file_id " + "and media_file.type = :type " + diff --git a/airsonic-main/src/main/java/org/airsonic/player/dao/RatingDao.java b/airsonic-main/src/main/java/org/airsonic/player/dao/RatingDao.java index e3a2d98a..44b1bf28 100644 --- a/airsonic-main/src/main/java/org/airsonic/player/dao/RatingDao.java +++ b/airsonic-main/src/main/java/org/airsonic/player/dao/RatingDao.java @@ -50,12 +50,11 @@ public class RatingDao extends AbstractDao { return Collections.emptyList(); } - Map args = new HashMap() {{ - put("type", MediaFile.MediaType.ALBUM.name()); - put("folders", MusicFolder.toPathList(musicFolders)); - put("count", count); - put("offset", offset); - }}; + Map args = new HashMap<>(); + args.put("type", MediaFile.MediaType.ALBUM.name()); + args.put("folders", MusicFolder.toPathList(musicFolders)); + args.put("count", count); + args.put("offset", offset); String sql = "select user_rating.path from user_rating, media_file " + "where user_rating.path=media_file.path and media_file.present and media_file.type = :type and media_file.folder in (:folders) " + @@ -115,11 +114,10 @@ public class RatingDao extends AbstractDao { if (musicFolders.isEmpty()) { return 0; } - Map args = new HashMap() {{ - put("type", MediaFile.MediaType.ALBUM.name()); - put("folders", MusicFolder.toPathList(musicFolders)); - put("username", username); - }}; + Map args = new HashMap<>(); + args.put("type", MediaFile.MediaType.ALBUM.name()); + args.put("folders", MusicFolder.toPathList(musicFolders)); + args.put("username", username); return namedQueryForInt("select count(*) from user_rating, media_file " + "where media_file.path = user_rating.path " + diff --git a/airsonic-main/src/main/java/org/airsonic/player/dao/ShareDao.java b/airsonic-main/src/main/java/org/airsonic/player/dao/ShareDao.java index 253b293f..d266d76e 100644 --- a/airsonic-main/src/main/java/org/airsonic/player/dao/ShareDao.java +++ b/airsonic-main/src/main/java/org/airsonic/player/dao/ShareDao.java @@ -115,10 +115,9 @@ public class ShareDao extends AbstractDao { if (musicFolders.isEmpty()) { return Collections.emptyList(); } - Map args = new HashMap() {{ - put("shareId", shareId); - put("folders", MusicFolder.toPathList(musicFolders)); - }}; + Map args = new HashMap<>(); + args.put("shareId", shareId); + args.put("folders", MusicFolder.toPathList(musicFolders)); return namedQuery("select share_file.path from share_file, media_file where share_id = :shareId and " + "share_file.path = media_file.path and media_file.present and media_file.folder in (:folders)", shareFileRowMapper, args);