?? loginbean.java~62~
字號(hào):
package sqlaccounts;import javax.ejb.*;import javax.naming.*;import javax.rmi.PortableRemoteObject;import java.rmi.RemoteException;import java.util.Collection;import java.util.Hashtable;import java.util.Properties;import java.util.Vector;import java.util.Iterator;import javax.ejb.CreateException;import javax.ejb.DuplicateKeyException;import javax.ejb.FinderException;import javax.ejb.ObjectNotFoundException;import javax.ejb.RemoveException;import javax.naming.Context;import javax.naming.InitialContext;import javax.naming.NamingException;import javax.rmi.PortableRemoteObject;public class LoginBean implements SessionBean { SessionContext sessionContext; private EjbAccountsHome ejbAccountsHome = null; private EjbAccounts ejbAccounts=null; //管理日志變量 private AManagerLogHome aManagerLogHome = null; private AManagerLog aManagerLog=null; public Collection conType; java.lang.String type; //String Type; public LoginBean() { } public LoginBean(String Type) { this.type=Type; }public void ejbCreate() throws CreateException { /**@todo Complete this method*/ try { Context ctx = new InitialContext(); Object ref = ctx.lookup("EjbAccountsRemote"); //this.employeeHome = (EmployeeRemoteHome)PortableRemoteObject.narrow(ctx.lookup("EmployeeRemote"),EmployeeRemoteHome.class); this.ejbAccountsHome = (EjbAccountsHome)PortableRemoteObject.narrow(ref,EjbAccountsHome.class); // EjbAccounts ejbAccounts = ejbAccountsHome.findByPrimaryKey(Id); } catch(Exception e){ }} public void ejbRemove() { /**@todo Complete this method*/ } public void ejbActivate() { /**@todo Complete this method*/ } public void ejbPassivate() { /**@todo Complete this method*/ } public void setSessionContext(SessionContext sessionContext) { this.sessionContext = sessionContext; } public boolean login(String Id) { /**@todo Complete this method*/ try{ //Context ctx = new InitialContext(); //Object ref = ctx.lookup("EjbAccountsRemote"); //this.employeeHome = (EmployeeRemoteHome)PortableRemoteObject.narrow(ctx.lookup("EmployeeRemote"),EmployeeRemoteHome.class); //this.ejbAccountsHome = (EjbAccountsHome)PortableRemoteObject.narrow(ref,EjbAccountsHome.class); ejbAccounts = ejbAccountsHome.findByPrimaryKey(Id); }catch(Exception e){ log("不能找到用戶(hù)ID號(hào)碼!"); return false; } log("找到用戶(hù)ID號(hào)碼!"); return true; } private void log(String s) { System.out.println(s); } public boolean AddId(String id, String Type, double bal) { /**@todo Complete this method*/ long startTime = 0; try { ejbAccounts = ejbAccountsHome.create(id, Type, bal); } catch(Exception e) { log("Failed: create(" + id + ", " + Type + ", " + bal + ")"); return false; } log("成功創(chuàng)建賬號(hào):(" + id + ", " + Type + ", " + bal + ")"); return true; } //發(fā)現(xiàn)和創(chuàng)建賬號(hào) public boolean findOrCreateAccount(String id, String accountType, double balance) { try { ejbAccounts =ejbAccountsHome.findByPrimaryKey(id);//(EjbAccounts)PortableRemoteObject.narrow(ejbAccountsHome.findByPrimaryKey(id), EjbAccounts.class); log("發(fā)現(xiàn)新賬號(hào):(" + id + ", " + accountType + ", " + balance + ")"); ejbAccounts.remove(); log("刪除新賬號(hào):(" + id + ", " + accountType + ", " + balance + ")"); return true; } catch (Exception onfe) { // the account id does not yet exist so create it. if(AddId(id, accountType, balance)==true) //ejbAccounts = ejbAccountsHome.create(id, accountType, balance); { log("創(chuàng)建新賬號(hào):(" + id + ", " + accountType + ", " + balance + ")"); return false; } else return false; } } public Vector findByType(String Type) { try { Collection AllejbAccounts = ejbAccountsHome.findByType(Type); if (AllejbAccounts.isEmpty()) return null; Iterator it = AllejbAccounts.iterator(); Vector all=new Vector(); while (it.hasNext()){ /* EjbAccounts ejbAccounts = (EjbAccounts)(javax.rmi.PortableRemoteObject.narrow(it.next(),EjbAccounts.class)); Login x=GetLogintype(ejbAccounts.getType()); //all.add(new LoginBean(ejbAccounts.getType())); all.add(x); */ EjbAccounts ejbAccounts = (EjbAccounts)(javax.rmi.PortableRemoteObject.narrow(it.next(),EjbAccounts.class)); String[] info ={ejbAccounts.getType().toString(),""+ejbAccounts.getBal(),toString(),""+ejbAccounts.getId(),}; all.add(info); } return all; }catch(Exception e){ return null; } } public Login GetLogintype(String type) { /**@todo Complete this method*/ setType(type); // Login loginBean=new Login(); // loginBean.setType(type); //return loginBean; return null; } public void untitledMethod1() { /**@todo Complete this method*/ } //查出所有的認(rèn)證日志 public Vector findAllManagelog() { /**@todo Complete this method*/ try { Collection AllManagelog = aManagerLogHome.findAllManagelog(); if (AllManagelog.isEmpty()) return null; Iterator it = AllManagelog.iterator(); Vector all=new Vector(); while (it.hasNext()){ AManagerLog aManagerLog = (AManagerLog)(javax.rmi.PortableRemoteObject.narrow(it.next(),AManagerLog.class)); String[] info ={ejbAccounts.getType().toString(),""+ejbAccounts.getBal(),toString(),""+ejbAccounts.getId(),}; all.add(info); } return all; }catch(Exception e){ return null; } } public void setType(java.lang.String type) { this.type = type; } public java.lang.String getType() { return type; }}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -