您的位置:首页 >> 编程开发 >> Java >> Java基础 >> Eclipse >> 正文
Eclipse RSS
 

Eclipse快速上手EJB -- 5. 一对多的双向关系的CMR(2)

http://www.rdxx.com 05年01月28日 12:12 Blog 我要投稿

关键词: 关系 , EJB , Eclipse , IP , JB
二、在UserManagementBean中添加业务方法
 
1. 增加一个 GroupLocalHome 的变量 groupHome,并将它放入 ejbCreate 和 ejbPassivate 方法中。
 
2. 依次增加以下几个业务方法。

UserManagementBean中有关 GroupBean 的部分(很简单)

 //********************************************************************** //                    一对多的双向关系 //********************************************************************** /**  * 创建组别  * @throws CreateException  * @ejb.interface-method view-type="remote"  */ public void createGroup(String groupName, String description)  throws CreateException {  groupHome.create(groupName, description); } /**  * 删除组别  * @throws RemoveException  * @throws EJBException  * @ejb.interface-method view-type="remote"  */ public void removeGroup(String groupName)  throws EJBException,  RemoveException {  groupHome.remove(groupName); }   /**  * 显示所有组别  * @throws FinderException  * @ejb.interface-method view-type="remote"  */ public ArrayList getGroups() throws FinderException {  ArrayList groupList = new ArrayList(30);  Iterator iter = groupHome.findAll().iterator();  while (iter.hasNext()) {   GroupLocal group = (GroupLocal) iter.next();   groupList.add(group.getName());  }  return groupList; }  /**  * 将用户添加到组  * @throws FinderException  * @ejb.interface-method view-type="remote"  */ public void moveUserToGroup(String email, String groupName)  throws FinderException {  UserInfoLocal user = infoHome.findByPrimaryKey(email);  GroupLocal group = groupHome.findByPrimaryKey(groupName);  user.setGroup(group); } /**  * 验证用户所在组  * @throws FinderException  * @ejb.interface-method view-type="remote"  */ public boolean inGroup(String email, String groupName)  throws FinderException {  UserInfoLocal user = infoHome.findByPrimaryKey(email);  return user.getGroup().getName().equals(groupName); }  /**  * 给一组用户增加权限  * @throws FinderException  * @ejb.interface-method view-type="remote"  */ public void addRoleToUsers(String groupName, String roleName)  throws FinderException {  GroupLocal group = groupHome.findByPrimaryKey(groupName);  RoleLocal role = roleHome.findByPrimaryKey(roleName);  Iterator iter = group.getUsers().iterator();  while (iter.hasNext()) {   UserInfoLocal user = (UserInfoLocal) iter.next();   user.getUser().getRoles().add(role);  } } /**  * 通过 ejb.finder 输出某组别的用户  * @throws FinderException  * @ejb.interface-method view-type="remote"  */ public ArrayList getUserIDsInGroup1(String groupName)         throws FinderException {  ArrayList userList = new ArrayList(30);  GroupLocal group = groupHome.findByPrimaryKey(groupName);  Iterator iter = group.getUsers().iterator();  while (iter.hasNext()) {   UserInfoLocal element = (UserInfoLocal) iter.next();   userList.add(element.getEmail());  }  return userList; }  /**  * 通过 ejb.select 输出某组别的用户  * Business method  * @throws FinderException  * @ejb.interface-method  view-type = "remote"  */ public ArrayList getUserIDsInGroup2(String groupName)          throws FinderException {    return groupHome.getUserIDs(groupName); }    
 

共2页  1 2


 
 
标签: 关系 , EJB , Eclipse , IP , JB 打印本文
 
 
  热点搜索
 
 
 



Valid XHTML 1.0 Transitional
Copyright ©2005 - 2008 Rdxx.Com,All Rights Reserved
收藏本页
收藏本站