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.
master
jvoisin 6 years ago
parent 1463f75b06
commit 41408bc2c3
  1. 78
      airsonic-main/src/main/java/org/airsonic/player/dao/AlbumDao.java
  2. 27
      airsonic-main/src/main/java/org/airsonic/player/dao/ArtistDao.java
  3. 209
      airsonic-main/src/main/java/org/airsonic/player/dao/MediaFileDao.java
  4. 20
      airsonic-main/src/main/java/org/airsonic/player/dao/RatingDao.java
  5. 7
      airsonic-main/src/main/java/org/airsonic/player/dao/ShareDao.java

@ -98,10 +98,9 @@ public class AlbumDao extends AbstractDao {
if (musicFolders.isEmpty()) { if (musicFolders.isEmpty()) {
return Collections.emptyList(); return Collections.emptyList();
} }
Map<String, Object> args = new HashMap<String, Object>() {{ Map<String, Object> args = new HashMap<>();
put("artist", artist); args.put("artist", artist);
put("folders", MusicFolder.toIdList(musicFolders)); args.put("folders", MusicFolder.toIdList(musicFolders));
}};
return namedQuery("select " + QUERY_COLUMNS return namedQuery("select " + QUERY_COLUMNS
+ " from album where artist = :artist and present and folder_id in (:folders) " + + " from album where artist = :artist and present and folder_id in (:folders) " +
"order by name", "order by name",
@ -176,11 +175,10 @@ public class AlbumDao extends AbstractDao {
if (musicFolders.isEmpty()) { if (musicFolders.isEmpty()) {
return Collections.emptyList(); return Collections.emptyList();
} }
Map<String, Object> args = new HashMap<String, Object>() {{ Map<String, Object> args = new HashMap<>();
put("folders", MusicFolder.toIdList(musicFolders)); args.put("folders", MusicFolder.toIdList(musicFolders));
put("count", count); args.put("count", count);
put("offset", offset); args.put("offset", offset);
}};
String orderBy; String orderBy;
if (ignoreCase) { if (ignoreCase) {
orderBy = byArtist ? "LOWER(artist), LOWER(name)" : "LOWER(name)"; orderBy = byArtist ? "LOWER(artist), LOWER(name)" : "LOWER(name)";
@ -221,11 +219,10 @@ public class AlbumDao extends AbstractDao {
if (musicFolders.isEmpty()) { if (musicFolders.isEmpty()) {
return Collections.emptyList(); return Collections.emptyList();
} }
Map<String, Object> args = new HashMap<String, Object>() {{ Map<String, Object> args = new HashMap<>();
put("folders", MusicFolder.toIdList(musicFolders)); args.put("folders", MusicFolder.toIdList(musicFolders));
put("count", count); args.put("count", count);
put("offset", offset); args.put("offset", offset);
}};
return namedQuery("select " + QUERY_COLUMNS return namedQuery("select " + QUERY_COLUMNS
+ " from album where play_count > 0 and present and folder_id in (:folders) " + + " from album where play_count > 0 and present and folder_id in (:folders) " +
"order by play_count desc limit :count offset :offset", rowMapper, args); "order by play_count desc limit :count offset :offset", rowMapper, args);
@ -243,11 +240,10 @@ public class AlbumDao extends AbstractDao {
if (musicFolders.isEmpty()) { if (musicFolders.isEmpty()) {
return Collections.emptyList(); return Collections.emptyList();
} }
Map<String, Object> args = new HashMap<String, Object>() {{ Map<String, Object> args = new HashMap<>();
put("folders", MusicFolder.toIdList(musicFolders)); args.put("folders", MusicFolder.toIdList(musicFolders));
put("count", count); args.put("count", count);
put("offset", offset); args.put("offset", offset);
}};
return namedQuery("select " + QUERY_COLUMNS return namedQuery("select " + QUERY_COLUMNS
+ " from album where last_played is not null and present and folder_id in (:folders) " + + " 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); "order by last_played desc limit :count offset :offset", rowMapper, args);
@ -265,11 +261,10 @@ public class AlbumDao extends AbstractDao {
if (musicFolders.isEmpty()) { if (musicFolders.isEmpty()) {
return Collections.emptyList(); return Collections.emptyList();
} }
Map<String, Object> args = new HashMap<String, Object>() {{ Map<String, Object> args = new HashMap<>();
put("folders", MusicFolder.toIdList(musicFolders)); args.put("folders", MusicFolder.toIdList(musicFolders));
put("count", count); args.put("count", count);
put("offset", offset); args.put("offset", offset);
}};
return namedQuery("select " + QUERY_COLUMNS + " from album where present and folder_id in (:folders) " + return namedQuery("select " + QUERY_COLUMNS + " from album where present and folder_id in (:folders) " +
"order by created desc limit :count offset :offset", rowMapper, args); "order by created desc limit :count offset :offset", rowMapper, args);
} }
@ -287,12 +282,11 @@ public class AlbumDao extends AbstractDao {
if (musicFolders.isEmpty()) { if (musicFolders.isEmpty()) {
return Collections.emptyList(); return Collections.emptyList();
} }
Map<String, Object> args = new HashMap<String, Object>() {{ Map<String, Object> args = new HashMap<>();
put("folders", MusicFolder.toIdList(musicFolders)); args.put("folders", MusicFolder.toIdList(musicFolders));
put("count", count); args.put("count", count);
put("offset", offset); args.put("offset", offset);
put("username", username); args.put("username", username);
}};
return namedQuery("select " + prefix(QUERY_COLUMNS, "album") + " from starred_album, album where album.id = starred_album.album_id and " + 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 " + "album.present and album.folder_id in (:folders) and starred_album.username = :username " +
"order by starred_album.created desc limit :count offset :offset", "order by starred_album.created desc limit :count offset :offset",
@ -312,12 +306,11 @@ public class AlbumDao extends AbstractDao {
if (musicFolders.isEmpty()) { if (musicFolders.isEmpty()) {
return Collections.emptyList(); return Collections.emptyList();
} }
Map<String, Object> args = new HashMap<String, Object>() {{ Map<String, Object> args = new HashMap<>();
put("folders", MusicFolder.toIdList(musicFolders)); args.put("folders", MusicFolder.toIdList(musicFolders));
put("count", count); args.put("count", count);
put("offset", offset); args.put("offset", offset);
put("genre", genre); args.put("genre", genre);
}};
return namedQuery("select " + QUERY_COLUMNS + " from album where present and folder_id in (:folders) " + return namedQuery("select " + QUERY_COLUMNS + " from album where present and folder_id in (:folders) " +
"and genre = :genre limit :count offset :offset", rowMapper, args); "and genre = :genre limit :count offset :offset", rowMapper, args);
} }
@ -337,13 +330,12 @@ public class AlbumDao extends AbstractDao {
if (musicFolders.isEmpty()) { if (musicFolders.isEmpty()) {
return Collections.emptyList(); return Collections.emptyList();
} }
Map<String, Object> args = new HashMap<String, Object>() {{ Map<String, Object> args = new HashMap<>();
put("folders", MusicFolder.toIdList(musicFolders)); args.put("folders", MusicFolder.toIdList(musicFolders));
put("count", count); args.put("count", count);
put("offset", offset); args.put("offset", offset);
put("fromYear", fromYear); args.put("fromYear", fromYear);
put("toYear", toYear); args.put("toYear", toYear);
}};
if (fromYear <= toYear) { if (fromYear <= toYear) {
return namedQuery("select " + QUERY_COLUMNS + " from album where present and folder_id in (:folders) " + 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", "and year between :fromYear and :toYear order by year limit :count offset :offset",

@ -66,10 +66,9 @@ public class ArtistDao extends AbstractDao {
if (musicFolders.isEmpty()) { if (musicFolders.isEmpty()) {
return null; return null;
} }
Map<String, Object> args = new HashMap<String, Object>() {{ Map<String, Object> args = new HashMap<>();
put("name", artistName); args.put("name", artistName);
put("folders", MusicFolder.toIdList(musicFolders)); args.put("folders", MusicFolder.toIdList(musicFolders));
}};
return namedQueryOne("select " + QUERY_COLUMNS + " from artist where name = :name and folder_id in (:folders)", return namedQueryOne("select " + QUERY_COLUMNS + " from artist where name = :name and folder_id in (:folders)",
rowMapper, args); rowMapper, args);
@ -123,11 +122,10 @@ public class ArtistDao extends AbstractDao {
if (musicFolders.isEmpty()) { if (musicFolders.isEmpty()) {
return Collections.emptyList(); return Collections.emptyList();
} }
Map<String, Object> args = new HashMap<String, Object>() {{ Map<String, Object> args = new HashMap<>();
put("folders", MusicFolder.toIdList(musicFolders)); args.put("folders", MusicFolder.toIdList(musicFolders));
put("count", count); args.put("count", count);
put("offset", offset); args.put("offset", offset);
}};
return namedQuery("select " + QUERY_COLUMNS + " from artist where present and folder_id in (:folders) " + return namedQuery("select " + QUERY_COLUMNS + " from artist where present and folder_id in (:folders) " +
"order by name limit :count offset :offset", rowMapper, args); "order by name limit :count offset :offset", rowMapper, args);
@ -147,12 +145,11 @@ public class ArtistDao extends AbstractDao {
if (musicFolders.isEmpty()) { if (musicFolders.isEmpty()) {
return Collections.emptyList(); return Collections.emptyList();
} }
Map<String, Object> args = new HashMap<String, Object>() {{ Map<String, Object> args = new HashMap<>();
put("folders", MusicFolder.toIdList(musicFolders)); args.put("folders", MusicFolder.toIdList(musicFolders));
put("username", username); args.put("username", username);
put("count", count); args.put("count", count);
put("offset", offset); args.put("offset", offset);
}};
return namedQuery("select " + prefix(QUERY_COLUMNS, "artist") + " from starred_artist, artist " + return namedQuery("select " + prefix(QUERY_COLUMNS, "artist") + " from starred_artist, artist " +
"where artist.id = starred_artist.artist_id and " + "where artist.id = starred_artist.artist_id and " +

@ -104,12 +104,11 @@ public class MediaFileDao extends AbstractDao {
if (musicFolders.isEmpty()) { if (musicFolders.isEmpty()) {
return Collections.emptyList(); return Collections.emptyList();
} }
Map<String, Object> args = new HashMap<String, Object>() {{ Map<String, Object> args = new HashMap<>();
put("type", MediaFile.MediaType.VIDEO.name()); args.put("type", MediaFile.MediaType.VIDEO.name());
put("folders", MusicFolder.toPathList(musicFolders)); args.put("folders", MusicFolder.toPathList(musicFolders));
put("count", count); args.put("count", count);
put("offset", offset); args.put("offset", offset);
}};
return namedQuery("select " + QUERY_COLUMNS return namedQuery("select " + QUERY_COLUMNS
+ " from media_file where type = :type and present and folder in (:folders) " + + " from media_file where type = :type and present and folder in (:folders) " +
"order by title limit :count offset :offset", rowMapper, args); "order by title limit :count offset :offset", rowMapper, args);
@ -119,11 +118,10 @@ public class MediaFileDao extends AbstractDao {
if (musicFolders.isEmpty()) { if (musicFolders.isEmpty()) {
return null; return null;
} }
Map<String, Object> args = new HashMap<String, Object>() {{ Map<String, Object> args = new HashMap<>();
put("type", MediaFile.MediaType.DIRECTORY.name()); args.put("type", MediaFile.MediaType.DIRECTORY.name());
put("name", name); args.put("name", name);
put("folders", MusicFolder.toPathList(musicFolders)); args.put("folders", MusicFolder.toPathList(musicFolders));
}};
return namedQueryOne("select " + QUERY_COLUMNS + " from media_file where type = :type and artist = :name " + return namedQueryOne("select " + QUERY_COLUMNS + " from media_file where type = :type and artist = :name " +
"and present and folder in (:folders)", rowMapper, args); "and present and folder in (:folders)", rowMapper, args);
} }
@ -233,12 +231,11 @@ public class MediaFileDao extends AbstractDao {
if (musicFolders.isEmpty()) { if (musicFolders.isEmpty()) {
return Collections.emptyList(); return Collections.emptyList();
} }
Map<String, Object> args = new HashMap<String, Object>() {{ Map<String, Object> args = new HashMap<>();
put("type", MediaFile.MediaType.ALBUM.name()); args.put("type", MediaFile.MediaType.ALBUM.name());
put("folders", MusicFolder.toPathList(musicFolders)); args.put("folders", MusicFolder.toPathList(musicFolders));
put("count", count); args.put("count", count);
put("offset", offset); args.put("offset", offset);
}};
return namedQuery("select " + QUERY_COLUMNS return namedQuery("select " + QUERY_COLUMNS
+ " from media_file where type = :type and play_count > 0 and present and folder in (:folders) " + + " 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()) { if (musicFolders.isEmpty()) {
return Collections.emptyList(); return Collections.emptyList();
} }
Map<String, Object> args = new HashMap<String, Object>() {{ Map<String, Object> args = new HashMap<>();
put("type", MediaFile.MediaType.ALBUM.name()); args.put("type", MediaFile.MediaType.ALBUM.name());
put("folders", MusicFolder.toPathList(musicFolders)); args.put("folders", MusicFolder.toPathList(musicFolders));
put("count", count); args.put("count", count);
put("offset", offset); args.put("offset", offset);
}};
return namedQuery("select " + QUERY_COLUMNS return namedQuery("select " + QUERY_COLUMNS
+ " from media_file where type = :type and last_played is not null and present " + + " 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); "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()) { if (musicFolders.isEmpty()) {
return Collections.emptyList(); return Collections.emptyList();
} }
Map<String, Object> args = new HashMap<String, Object>() {{ Map<String, Object> args = new HashMap<>();
put("type", MediaFile.MediaType.ALBUM.name()); args.put("type", MediaFile.MediaType.ALBUM.name());
put("folders", MusicFolder.toPathList(musicFolders)); args.put("folders", MusicFolder.toPathList(musicFolders));
put("count", count); args.put("count", count);
put("offset", offset); args.put("offset", offset);
}};
return namedQuery("select " + QUERY_COLUMNS return namedQuery("select " + QUERY_COLUMNS
+ " from media_file where type = :type and folder in (:folders) and present " + + " from media_file where type = :type and folder in (:folders) and present " +
@ -305,12 +300,11 @@ public class MediaFileDao extends AbstractDao {
if (musicFolders.isEmpty()) { if (musicFolders.isEmpty()) {
return Collections.emptyList(); return Collections.emptyList();
} }
Map<String, Object> args = new HashMap<String, Object>() {{ Map<String, Object> args = new HashMap<>();
put("type", MediaFile.MediaType.ALBUM.name()); args.put("type", MediaFile.MediaType.ALBUM.name());
put("folders", MusicFolder.toPathList(musicFolders)); args.put("folders", MusicFolder.toPathList(musicFolders));
put("count", count); args.put("count", count);
put("offset", offset); args.put("offset", offset);
}};
String orderBy = byArtist ? "artist, album" : "album"; String orderBy = byArtist ? "artist, album" : "album";
return namedQuery("select " + QUERY_COLUMNS return namedQuery("select " + QUERY_COLUMNS
@ -333,14 +327,13 @@ public class MediaFileDao extends AbstractDao {
if (musicFolders.isEmpty()) { if (musicFolders.isEmpty()) {
return Collections.emptyList(); return Collections.emptyList();
} }
Map<String, Object> args = new HashMap<String, Object>() {{ Map<String, Object> args = new HashMap<>();
put("type", MediaFile.MediaType.ALBUM.name()); args.put("type", MediaFile.MediaType.ALBUM.name());
put("folders", MusicFolder.toPathList(musicFolders)); args.put("folders", MusicFolder.toPathList(musicFolders));
put("fromYear", fromYear); args.put("fromYear", fromYear);
put("toYear", toYear); args.put("toYear", toYear);
put("count", count); args.put("count", count);
put("offset", offset); args.put("offset", offset);
}};
if (fromYear <= toYear) { if (fromYear <= toYear) {
return namedQuery("select " + QUERY_COLUMNS return namedQuery("select " + QUERY_COLUMNS
@ -369,13 +362,12 @@ public class MediaFileDao extends AbstractDao {
if (musicFolders.isEmpty()) { if (musicFolders.isEmpty()) {
return Collections.emptyList(); return Collections.emptyList();
} }
Map<String, Object> args = new HashMap<String, Object>() {{ Map<String, Object> args = new HashMap<>();
put("type", MediaFile.MediaType.ALBUM.name()); args.put("type", MediaFile.MediaType.ALBUM.name());
put("genre", genre); args.put("genre", genre);
put("folders", MusicFolder.toPathList(musicFolders)); args.put("folders", MusicFolder.toPathList(musicFolders));
put("count", count); args.put("count", count);
put("offset", offset); args.put("offset", offset);
}};
return namedQuery("select " + QUERY_COLUMNS + " from media_file where type = :type and folder in (:folders) " + 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); "and present and genre = :genre limit :count offset :offset", rowMapper, args);
} }
@ -384,13 +376,12 @@ public class MediaFileDao extends AbstractDao {
if (musicFolders.isEmpty()) { if (musicFolders.isEmpty()) {
return Collections.emptyList(); return Collections.emptyList();
} }
Map<String, Object> args = new HashMap<String, Object>() {{ Map<String, Object> args = new HashMap<>();
put("types", Arrays.asList(MediaFile.MediaType.MUSIC.name(), MediaFile.MediaType.PODCAST.name(), MediaFile.MediaType.AUDIOBOOK.name())); args.put("types", Arrays.asList(MediaFile.MediaType.MUSIC.name(), MediaFile.MediaType.PODCAST.name(), MediaFile.MediaType.AUDIOBOOK.name()));
put("genre", genre); args.put("genre", genre);
put("count", count); args.put("count", count);
put("offset", offset); args.put("offset", offset);
put("folders", MusicFolder.toPathList(musicFolders)); args.put("folders", MusicFolder.toPathList(musicFolders));
}};
return namedQuery("select " + QUERY_COLUMNS + " from media_file where type in (:types) and genre = :genre " + 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", "and present and folder in (:folders) limit :count offset :offset",
rowMapper, args); rowMapper, args);
@ -406,12 +397,11 @@ public class MediaFileDao extends AbstractDao {
if (musicFolders.isEmpty() || StringUtils.isBlank(title) || StringUtils.isBlank(artist)) { if (musicFolders.isEmpty() || StringUtils.isBlank(title) || StringUtils.isBlank(artist)) {
return null; return null;
} }
Map<String, Object> args = new HashMap<String, Object>() {{ Map<String, Object> args = new HashMap<>();
put("artist", artist); args.put("artist", artist);
put("title", title); args.put("title", title);
put("type", MediaFile.MediaType.MUSIC.name()); args.put("type", MediaFile.MediaType.MUSIC.name());
put("folders", MusicFolder.toPathList(musicFolders)); args.put("folders", MusicFolder.toPathList(musicFolders));
}};
return namedQueryOne("select " + QUERY_COLUMNS + " from media_file where artist = :artist " + return namedQueryOne("select " + QUERY_COLUMNS + " from media_file where artist = :artist " +
"and title = :title and type = :type and present and folder in (:folders)" , "and title = :title and type = :type and present and folder in (:folders)" ,
rowMapper, args); rowMapper, args);
@ -431,13 +421,12 @@ public class MediaFileDao extends AbstractDao {
if (musicFolders.isEmpty()) { if (musicFolders.isEmpty()) {
return Collections.emptyList(); return Collections.emptyList();
} }
Map<String, Object> args = new HashMap<String, Object>() {{ Map<String, Object> args = new HashMap<>();
put("type", MediaFile.MediaType.ALBUM.name()); args.put("type", MediaFile.MediaType.ALBUM.name());
put("folders", MusicFolder.toPathList(musicFolders)); args.put("folders", MusicFolder.toPathList(musicFolders));
put("username", username); args.put("username", username);
put("count", count); args.put("count", count);
put("offset", offset); 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 " + 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 " + "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", "order by starred_media_file.created desc limit :count offset :offset",
@ -458,13 +447,12 @@ public class MediaFileDao extends AbstractDao {
if (musicFolders.isEmpty()) { if (musicFolders.isEmpty()) {
return Collections.emptyList(); return Collections.emptyList();
} }
Map<String, Object> args = new HashMap<String, Object>() {{ Map<String, Object> args = new HashMap<>();
put("type", MediaFile.MediaType.DIRECTORY.name()); args.put("type", MediaFile.MediaType.DIRECTORY.name());
put("folders", MusicFolder.toPathList(musicFolders)); args.put("folders", MusicFolder.toPathList(musicFolders));
put("username", username); args.put("username", username);
put("count", count); args.put("count", count);
put("offset", offset); args.put("offset", offset);
}};
return namedQuery("select " + prefix(QUERY_COLUMNS, "media_file") + " from starred_media_file, media_file " + 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 " + "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 " + "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()) { if (musicFolders.isEmpty()) {
return Collections.emptyList(); return Collections.emptyList();
} }
Map<String, Object> args = new HashMap<String, Object>() {{ Map<String, Object> args = new HashMap<>();
put("types", Arrays.asList(MediaFile.MediaType.MUSIC.name(), MediaFile.MediaType.PODCAST.name(), MediaFile.MediaType.AUDIOBOOK.name(), MediaFile.MediaType.VIDEO.name())); args.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)); args.put("folders", MusicFolder.toPathList(musicFolders));
put("username", username); args.put("username", username);
put("count", count); args.put("count", count);
put("offset", offset); 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 " + 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.present and media_file.type in (:types) and starred_media_file.username = :username and " +
"media_file.folder in (:folders) " + "media_file.folder in (:folders) " +
@ -506,22 +493,21 @@ public class MediaFileDao extends AbstractDao {
return Collections.emptyList(); return Collections.emptyList();
} }
Map<String, Object> args = new HashMap<String, Object>() {{ Map<String, Object> args = new HashMap<>();
put("folders", MusicFolder.toPathList(criteria.getMusicFolders())); args.put("folders", MusicFolder.toPathList(criteria.getMusicFolders()));
put("username", username); args.put("username", username);
put("fromYear", criteria.getFromYear()); args.put("fromYear", criteria.getFromYear());
put("toYear", criteria.getToYear()); args.put("toYear", criteria.getToYear());
put("genre", criteria.getGenre()); args.put("genre", criteria.getGenre());
put("minLastPlayed", criteria.getMinLastPlayedDate()); args.put("minLastPlayed", criteria.getMinLastPlayedDate());
put("maxLastPlayed", criteria.getMaxLastPlayedDate()); args.put("maxLastPlayed", criteria.getMaxLastPlayedDate());
put("minAlbumRating", criteria.getMinAlbumRating()); args.put("minAlbumRating", criteria.getMinAlbumRating());
put("maxAlbumRating", criteria.getMaxAlbumRating()); args.put("maxAlbumRating", criteria.getMaxAlbumRating());
put("minPlayCount", criteria.getMinPlayCount()); args.put("minPlayCount", criteria.getMinPlayCount());
put("maxPlayCount", criteria.getMaxPlayCount()); args.put("maxPlayCount", criteria.getMaxPlayCount());
put("starred", criteria.isShowStarredSongs()); args.put("starred", criteria.isShowStarredSongs());
put("unstarred", criteria.isShowUnstarredSongs()); args.put("unstarred", criteria.isShowUnstarredSongs());
put("format", criteria.getFormat()); args.put("format", criteria.getFormat());
}};
boolean joinAlbumRating = (criteria.getMinAlbumRating() != null || criteria.getMaxAlbumRating() != null); boolean joinAlbumRating = (criteria.getMinAlbumRating() != null || criteria.getMaxAlbumRating() != null);
boolean joinStarred = (criteria.isShowStarredSongs() ^ criteria.isShowUnstarredSongs()); boolean joinStarred = (criteria.isShowStarredSongs() ^ criteria.isShowUnstarredSongs());
@ -612,10 +598,9 @@ public class MediaFileDao extends AbstractDao {
if (musicFolders.isEmpty()) { if (musicFolders.isEmpty()) {
return 0; return 0;
} }
Map<String, Object> args = new HashMap<String, Object>() {{ Map<String, Object> args = new HashMap<>();
put("type", MediaFile.MediaType.ALBUM.name()); args.put("type", MediaFile.MediaType.ALBUM.name());
put("folders", MusicFolder.toPathList(musicFolders)); args.put("folders", MusicFolder.toPathList(musicFolders));
}};
return namedQueryForInt("select count(*) from media_file where type = :type and folder in (:folders) and present", 0, args); 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()) { if (musicFolders.isEmpty()) {
return 0; return 0;
} }
Map<String, Object> args = new HashMap<String, Object>() {{ Map<String, Object> args = new HashMap<>();
put("type", MediaFile.MediaType.ALBUM.name()); args.put("type", MediaFile.MediaType.ALBUM.name());
put("folders", MusicFolder.toPathList(musicFolders)); args.put("folders", MusicFolder.toPathList(musicFolders));
}};
return namedQueryForInt("select count(*) from media_file where type = :type " + return namedQueryForInt("select count(*) from media_file where type = :type " +
"and play_count > 0 and present and folder in (:folders)", 0, args); "and play_count > 0 and present and folder in (:folders)", 0, args);
} }
@ -635,11 +619,10 @@ public class MediaFileDao extends AbstractDao {
if (musicFolders.isEmpty()) { if (musicFolders.isEmpty()) {
return 0; return 0;
} }
Map<String, Object> args = new HashMap<String, Object>() {{ Map<String, Object> args = new HashMap<>();
put("type", MediaFile.MediaType.ALBUM.name()); args.put("type", MediaFile.MediaType.ALBUM.name());
put("folders", MusicFolder.toPathList(musicFolders)); args.put("folders", MusicFolder.toPathList(musicFolders));
put("username", username); args.put("username", uername);
}};
return namedQueryForInt("select count(*) from starred_media_file, media_file " + return namedQueryForInt("select count(*) from starred_media_file, media_file " +
"where media_file.id = starred_media_file.media_file_id " + "where media_file.id = starred_media_file.media_file_id " +
"and media_file.type = :type " + "and media_file.type = :type " +

@ -50,12 +50,11 @@ public class RatingDao extends AbstractDao {
return Collections.emptyList(); return Collections.emptyList();
} }
Map<String, Object> args = new HashMap<String, Object>() {{ Map<String, Object> args = new HashMap<>();
put("type", MediaFile.MediaType.ALBUM.name()); args.put("type", MediaFile.MediaType.ALBUM.name());
put("folders", MusicFolder.toPathList(musicFolders)); args.put("folders", MusicFolder.toPathList(musicFolders));
put("count", count); args.put("count", count);
put("offset", offset); args.put("offset", offset);
}};
String sql = "select user_rating.path from user_rating, media_file " + 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) " + "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()) { if (musicFolders.isEmpty()) {
return 0; return 0;
} }
Map<String, Object> args = new HashMap<String, Object>() {{ Map<String, Object> args = new HashMap<>();
put("type", MediaFile.MediaType.ALBUM.name()); args.put("type", MediaFile.MediaType.ALBUM.name());
put("folders", MusicFolder.toPathList(musicFolders)); args.put("folders", MusicFolder.toPathList(musicFolders));
put("username", username); args.put("username", username);
}};
return namedQueryForInt("select count(*) from user_rating, media_file " + return namedQueryForInt("select count(*) from user_rating, media_file " +
"where media_file.path = user_rating.path " + "where media_file.path = user_rating.path " +

@ -115,10 +115,9 @@ public class ShareDao extends AbstractDao {
if (musicFolders.isEmpty()) { if (musicFolders.isEmpty()) {
return Collections.emptyList(); return Collections.emptyList();
} }
Map<String, Object> args = new HashMap<String, Object>() {{ Map<String, Object> args = new HashMap<>();
put("shareId", shareId); args.put("shareId", shareId);
put("folders", MusicFolder.toPathList(musicFolders)); args.put("folders", MusicFolder.toPathList(musicFolders));
}};
return namedQuery("select share_file.path from share_file, media_file where share_id = :shareId and " + 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)", "share_file.path = media_file.path and media_file.present and media_file.folder in (:folders)",
shareFileRowMapper, args); shareFileRowMapper, args);

Loading…
Cancel
Save