Remove use useless arrays creation

master
jvoisin 5 years ago committed by GitHub
parent 4679bac08d
commit e085d77635
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 35
      airsonic-main/src/main/java/org/airsonic/player/dao/UserDao.java

@ -164,9 +164,9 @@ public class UserDao extends AbstractDao {
public void updateUser(User user) { public void updateUser(User user) {
String sql = "update " + getUserTable() + " set password=?, email=?, ldap_authenticated=?, bytes_streamed=?, bytes_downloaded=?, bytes_uploaded=? " + String sql = "update " + getUserTable() + " set password=?, email=?, ldap_authenticated=?, bytes_streamed=?, bytes_downloaded=?, bytes_uploaded=? " +
"where username=?"; "where username=?";
getJdbcTemplate().update(sql, new Object[]{encrypt(user.getPassword()), user.getEmail(), user.isLdapAuthenticated(), getJdbcTemplate().update(sql, encrypt(user.getPassword()), user.getEmail(), user.isLdapAuthenticated(),
user.getBytesStreamed(), user.getBytesDownloaded(), user.getBytesUploaded(), user.getBytesStreamed(), user.getBytesDownloaded(), user.getBytesUploaded(),
user.getUsername()}); user.getUsername());
writeRoles(user); writeRoles(user);
} }
@ -204,13 +204,13 @@ public class UserDao extends AbstractDao {
* @param settings The user-specific settings. * @param settings The user-specific settings.
*/ */
public void updateUserSettings(UserSettings settings) { public void updateUserSettings(UserSettings settings) {
getJdbcTemplate().update("delete from user_settings where username=?", new Object[]{settings.getUsername()}); getJdbcTemplate().update("delete from user_settings where username=?", settings.getUsername());
String sql = "insert into user_settings (" + USER_SETTINGS_COLUMNS + ") values (" + questionMarks(USER_SETTINGS_COLUMNS) + ')'; String sql = "insert into user_settings (" + USER_SETTINGS_COLUMNS + ") values (" + questionMarks(USER_SETTINGS_COLUMNS) + ')';
String locale = settings.getLocale() == null ? null : settings.getLocale().toString(); String locale = settings.getLocale() == null ? null : settings.getLocale().toString();
UserSettings.Visibility main = settings.getMainVisibility(); UserSettings.Visibility main = settings.getMainVisibility();
UserSettings.Visibility playlist = settings.getPlaylistVisibility(); UserSettings.Visibility playlist = settings.getPlaylistVisibility();
getJdbcTemplate().update(sql, new Object[]{settings.getUsername(), locale, settings.getThemeId(), getJdbcTemplate().update(sql, settings.getUsername(), locale, settings.getThemeId(),
settings.isFinalVersionNotificationEnabled(), settings.isBetaVersionNotificationEnabled(), settings.isFinalVersionNotificationEnabled(), settings.isBetaVersionNotificationEnabled(),
settings.isSongNotificationEnabled(), main.isTrackNumberVisible(), settings.isSongNotificationEnabled(), main.isTrackNumberVisible(),
main.isArtistVisible(), main.isAlbumVisible(), main.isGenreVisible(), main.isYearVisible(), main.isArtistVisible(), main.isAlbumVisible(), main.isGenreVisible(), main.isYearVisible(),
@ -225,8 +225,7 @@ public class UserDao extends AbstractDao {
settings.isShowArtistInfoEnabled(), settings.isAutoHidePlayQueue(), settings.isShowArtistInfoEnabled(), settings.isAutoHidePlayQueue(),
settings.isViewAsList(), settings.getDefaultAlbumList().getId(), settings.isQueueFollowingSongs(), settings.isViewAsList(), settings.getDefaultAlbumList().getId(), settings.isQueueFollowingSongs(),
settings.isShowSideBar(), settings.getListReloadDelay(), settings.isKeyboardShortcutsEnabled(), settings.isShowSideBar(), settings.getListReloadDelay(), settings.isKeyboardShortcutsEnabled(),
settings.getPaginationSize() settings.getPaginationSize());
});
} }
private static String encrypt(String s) { private static String encrypt(String s) {
@ -288,40 +287,40 @@ public class UserDao extends AbstractDao {
private void writeRoles(User user) { private void writeRoles(User user) {
String sql = "delete from user_role where username=?"; String sql = "delete from user_role where username=?";
getJdbcTemplate().update(sql, new Object[]{user.getUsername()}); getJdbcTemplate().update(sql, user.getUsername());
sql = "insert into user_role (username, role_id) values(?, ?)"; sql = "insert into user_role (username, role_id) values(?, ?)";
if (user.isAdminRole()) { if (user.isAdminRole()) {
getJdbcTemplate().update(sql, new Object[]{user.getUsername(), ROLE_ID_ADMIN}); getJdbcTemplate().update(sql, user.getUsername(), ROLE_ID_ADMIN);
} }
if (user.isDownloadRole()) { if (user.isDownloadRole()) {
getJdbcTemplate().update(sql, new Object[]{user.getUsername(), ROLE_ID_DOWNLOAD}); getJdbcTemplate().update(sql, user.getUsername(), ROLE_ID_DOWNLOAD);
} }
if (user.isUploadRole()) { if (user.isUploadRole()) {
getJdbcTemplate().update(sql, new Object[]{user.getUsername(), ROLE_ID_UPLOAD}); getJdbcTemplate().update(sql, user.getUsername(), ROLE_ID_UPLOAD);
} }
if (user.isPlaylistRole()) { if (user.isPlaylistRole()) {
getJdbcTemplate().update(sql, new Object[]{user.getUsername(), ROLE_ID_PLAYLIST}); getJdbcTemplate().update(sql, user.getUsername(), ROLE_ID_PLAYLIST);
} }
if (user.isCoverArtRole()) { if (user.isCoverArtRole()) {
getJdbcTemplate().update(sql, new Object[]{user.getUsername(), ROLE_ID_COVER_ART}); getJdbcTemplate().update(sql, user.getUsername(), ROLE_ID_COVER_ART);
} }
if (user.isCommentRole()) { if (user.isCommentRole()) {
getJdbcTemplate().update(sql, new Object[]{user.getUsername(), ROLE_ID_COMMENT}); getJdbcTemplate().update(sql, user.getUsername(), ROLE_ID_COMMENT);
} }
if (user.isPodcastRole()) { if (user.isPodcastRole()) {
getJdbcTemplate().update(sql, new Object[]{user.getUsername(), ROLE_ID_PODCAST}); getJdbcTemplate().update(sql, user.getUsername(), ROLE_ID_PODCAST);
} }
if (user.isStreamRole()) { if (user.isStreamRole()) {
getJdbcTemplate().update(sql, new Object[]{user.getUsername(), ROLE_ID_STREAM}); getJdbcTemplate().update(sql, user.getUsername(), ROLE_ID_STREAM);
} }
if (user.isJukeboxRole()) { if (user.isJukeboxRole()) {
getJdbcTemplate().update(sql, new Object[]{user.getUsername(), ROLE_ID_JUKEBOX}); getJdbcTemplate().update(sql, user.getUsername(), ROLE_ID_JUKEBOX);
} }
if (user.isSettingsRole()) { if (user.isSettingsRole()) {
getJdbcTemplate().update(sql, new Object[]{user.getUsername(), ROLE_ID_SETTINGS}); getJdbcTemplate().update(sql, user.getUsername(), ROLE_ID_SETTINGS);
} }
if (user.isShareRole()) { if (user.isShareRole()) {
getJdbcTemplate().update(sql, new Object[]{user.getUsername(), ROLE_ID_SHARE}); getJdbcTemplate().update(sql, user.getUsername(), ROLE_ID_SHARE);
} }
} }

Loading…
Cancel
Save