⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 accountmanage.ejb

📁 J2EE的一个开发实例
💻 EJB
字号:
package music.ejb;import java.security.Principal;import java.util.*;import javax.ejb.*;import weblogic.ejb.*;import music.ejb.db.*;import music.shared.*;/** * @ejbgen:session type="Stateless" default-transaction="Required" *   ejb-name = "AccountManage" * * @ejbgen:jndi-name *   remote="ejb/AccountManage" * * @ejbgen:file-generation remote-class = "true" remote-class-name = "AccountManageRemote" remote-home = "true" remote-home-name="AccountManageRemoteHome" local-class="true" local-class-name = "AccountManageLocal" local-home="true" local-home-name = "AccountManageLocalHome" */public class AccountManage  extends GenericSessionBean  implements SessionBean{  public void ejbCreate() {    // Your code here  }    /**     * @ejbgen:remote-method     */    public void register(AccountVO accountVO)        throws UserExistException, FormatException, ApplicationException    {        // check format:        AccountUtil.checkAccountFormat(accountVO);        AccountLocalHome home = JndiHelper.getAccountLocalHome();        AccountLocal account = null;        try {            account = home.create(                accountVO.getUsername(),                accountVO.getPassword(),                accountVO.getEmail()            );        }        catch(DuplicateKeyException de) {            throw new UserExistException("User " + accountVO.getUsername() + " already exists.");        }        catch(CreateException ce) {            throw new ApplicationException("System internal error: " + ce.getMessage());        }    }    /**     * @ejbgen:remote-method     */    public AccountVO login(String username, String password)        throws UnauthorizedException    {        if(username==null || password==null)            throw new UnauthorizedException("Authorization failed.");        username = username.toLowerCase();        AccountLocal account = null;        try {            account = JndiHelper.getAccountLocalHome().findByPrimaryKey(username);        }        catch(FinderException fe) {            throw new UnauthorizedException("User not found: " + username);        }        if(!account.getPassword().equals(password))            throw new UnauthorizedException("Password not match.");        // passed, return the account value object(ignore password)        return new AccountVO(username, null, account.getEmail(), account.getRole());    }    /**     * @ejbgen:remote-method     */    public void  changePassword(String username, String oldPassword, String newPassword)        throws UnauthorizedException, FormatException    {        // check the new password:        AccountUtil.checkPasswordFormat(newPassword);        AccountLocal account = null;        try {            account = JndiHelper.getAccountLocalHome().findByPrimaryKey(username);        }        catch(FinderException fe) {            throw new UnauthorizedException("User not found: " + username);        }        if(!account.getPassword().equals(oldPassword)) {            throw new UnauthorizedException("Invalid old password.");        }        account.setPassword(newPassword);    }    /**     * @ejbgen:remote-method     */    public void  update(AccountVO accountVO)        throws UnauthorizedException    {        AccountLocal account = null;        try {            account = JndiHelper.getAccountLocalHome().findByPrimaryKey(accountVO.getUsername());        }        catch(FinderException fe) {            throw new UnauthorizedException("User not found: " + accountVO.getUsername());        }        account.setEmail(accountVO.getEmail());    }}

⌨️ 快捷键说明

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