📄 usersessionbeanbean.java
字号:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package BusinessSessionBeans;import Entities.UserEntityBean;import javax.ejb.Stateless;import java.util.List;import java.util.Iterator;import javax.persistence.EntityManager;import javax.persistence.PersistenceContext;/** * * @author kiriashoo */@Statelesspublic class UserSessionBeanBean implements BusinessSessionBeans.UserSessionBeanRemote { @PersistenceContext EntityManager em; // id; name; address; telephone; email; code; userType; public void create(String name, String address, int telephone, String email, String code, int userType ) { UserEntityBean userBean = new UserEntityBean(); userBean.setName(name); userBean.setAddress(address); userBean.setTelephone(code); userBean.setEmail(email); userBean.setCode(code); userBean.setUserType(userType); em.persist(userBean); } public void edit(UserEntityBean userBean){ em.merge(userBean); } public void destroy(Integer id){ UserEntityBean userBean = (UserEntityBean) em.find(UserEntityBean.class, id); em.remove(userBean); } public UserEntityBean find(Object pk){ return (UserEntityBean) em.find(UserEntityBean.class,pk); } public List findAll(){ return em.createQuery("select OBJECT(o) from UserEntityBean o").getResultList(); } public int userLogin(String name, String email, String code) { int ret=0, type=0; String uname, uemail, ucode; UserEntityBean uB; List userList = findAll(); Iterator it = userList.iterator(); while ( it.hasNext() ) { uB = (UserEntityBean) it.next(); uname = uB.getName(); uemail = uB.getEmail(); ucode = uB.getCode(); type = uB.getUserType(); if ( uname.equalsIgnoreCase(name) & uemail.equalsIgnoreCase(email) & ucode.equalsIgnoreCase(code) ) { ret = type; break; } } return ret; } public int getUserId(String name, String email, String code) { int ret=0, id=0; String uname, uemail, ucode; UserEntityBean uB; List userList = findAll(); Iterator it = userList.iterator(); while ( it.hasNext() ) { uB = (UserEntityBean) it.next(); uname = uB.getName(); uemail = uB.getEmail(); ucode = uB.getCode(); id = uB.getId(); if ( uname.equalsIgnoreCase(name) & uemail.equalsIgnoreCase(email) & ucode.equalsIgnoreCase(code) ) { ret = id; } } return ret; } // Add business logic below. (Right-click in editor and choose // "EJB Methods > Add Business Method" or "Web Service > Add Operation") }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -