userloader.java

来自「我在加拿大学习的一个比较复杂的在线银行程序.」· Java 代码 · 共 88 行

JAVA
88 行
字号
package com.ebusiness.ebank.security;/** * <p>Title: </p> * <p>Description: This class is to load a new user through ...</p> * <p>Copyright: Copyright (c) 2005</p> * <p>Company: eBusiness Inc., All right reserved</p> * @author unascribed * @version 1.0 */import java.sql.Connection;import java.sql.PreparedStatement;import java.sql.ResultSet;import javax.sql.DataSource;import com.ebusiness.ebank.servicedelegate.ServiceLocator;import com.ebusiness.ebank.exception.SystemException;import com.ebusiness.ebank.util.Constants;public class UserLoader{    private DataSource ds;    private static UserLoader loader = new UserLoader();    private UserLoader(){}    public static UserLoader getInstance() {return loader;}    //Load UserProfile through data store. It may be a LDAP server    public UserProfile load(String userID, String[] roles) throws SystemException    {        try        {            UserPreference pref = getUserPreference(userID);            return new UserProfile(userID, pref.getLanguage(), roles);        }        catch (Exception e)        {            throw new SystemException(e);        }    }    private UserPreference getUserPreference(String userID) throws SystemException    {        UserPreference pref = null;        PreparedStatement ps = null;        Connection con = null;        try        {            if (ds == null )                ds = ServiceLocator.getInstance().getDataSource(Constants.DATASOURCE_EBANK);            con = ds.getConnection();            ps = con.prepareStatement("Select * from Preference where User_ID = ?");            ps.setString(1, userID);            ResultSet rs = ps.executeQuery();            pref = new UserPreference();            pref.setUserID(userID);            if (rs.next())                pref.setLanguage(rs.getString("language"));            else                pref.setLanguage("en"); //default to English        }        catch (Exception e)        {            throw new SystemException(e);        }        finally        {            try            {                if (ps != null)                   ps.close();                if (con != null)                   con.close();            }            catch (Exception e)            {                throw new SystemException(e);            }        }        return pref;    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?