package org.binwang.bard.util.user;

public interface UserDao<UserType> {
    public UserDao getInstance();

    public UserType getUser(long userId) throws UserNotFoundException;

    public long getUserIdFromName(String username, String password) throws UserNotFoundException;

    public void saveToken(String token, long userId, long expire);

    public Long getUserIdFromToken(String token) throws TokenNotFoundException;

    public void saveSalt(long userId, String salt);

    public String getSalt(String username) throws SaltNotFoundException;

    public static class UserNotFoundException extends Exception {
        public UserNotFoundException(Long userId) {
            super("User not found for id: " + userId.toString());
        }
    }


    public static class TokenNotFoundException extends Exception {
        public TokenNotFoundException(String token) {
            super("Token not found: " + token);
        }
    }


    public static class SaltNotFoundException extends Exception {
        public SaltNotFoundException(String username) {
            super("Salt not found for user: " + username);
        }
    }
}

@@ -75,485 +75,1683 @@
     
-public UserDao getInstance();%0A%0A    public UserType getUser(long userId) throws UserNotFoundException;%0A%0A    public long getUserIdFromName(String username, String password) throws UserNotFoundException;%0A%0A    public void saveToken(String token, long userId, long expire);%0A%0A    public Long getUserIdFromToken(String token) throws TokenNotFoundException;%0A%0A    public void saveSalt(long userId, String salt);%0A%0A    public String getSalt(String username) throws SaltNotFoundException;%0A
+/**%0A     * Get static UserDao. Used to get UserDao from class type.%0A     *%0A     * @return A global static UserDao.%0A     */%0A    public UserDao getInstance();%0A%0A    /**%0A     * Get user from userId.%0A     *%0A     * @param userId The id of user.%0A     * @return A user.%0A     * @throws UserNotFoundException%0A     */%0A    public UserType getUser(long userId) throws UserNotFoundException;%0A%0A    /**%0A     * Get user from username and password.%0A     *%0A     * @param username The username.%0A     * @param password The encrypted password.%0A     * @return A user.%0A     * @throws UserNotFoundException%0A     */%0A    public long getUserIdFromName(String username, String password) throws UserNotFoundException;%0A%0A    /**%0A     * Save a user's token, with an expire time.%0A     *%0A     * @param token  The token.%0A     * @param userId The id of user.%0A     * @param expire Expire time, in millisecond.%0A     */%0A    public void saveToken(String token, long userId, long expire);%0A%0A    /**%0A     * Get user's id from token.%0A     *%0A     * @param token The token.%0A     * @return The found user's id.%0A     * @throws TokenNotFoundException%0A     */%0A    public Long getUserIdFromToken(String token) throws TokenNotFoundException;%0A%0A    /**%0A     * Save a user's password salt.%0A     *%0A     * @param userId The id of user.%0A     * @param salt   The salt.%0A     */%0A    public void saveSalt(long userId, String salt);%0A%0A    /**%0A     * Get the salt from username.%0A     *%0A     * @param username The username.%0A     * @return The salt.%0A     * @throws SaltNotFoundException%0A     */%0A    public String getSalt(String username) throws SaltNotFoundException;%0A%0A    /**%0A     * If a user not found, this exception will be thrown.%0A     */
 %0A   
@@ -1941,32 +1941,116 @@
       %7D%0A    %7D%0A%0A%0A
+    /**%0A     * If token not found by userId, this exception will be thrown.%0A     */%0A
     public stati
@@ -2216,24 +2216,109 @@
   %7D%0A    %7D%0A%0A%0A
+    /**%0A     * If salt not found by username, this exception will be thrown.%0A     */%0A
     public s

add comments for UserDao