中国IT动力,最新最全的IT技术教程
最新100篇 | 推荐100篇 | 专题100篇 | 排行榜 | 搜索 | 在线API文档 | 网通镜像
首 页 | 程序开发 | 操作系统 | 软件应用 | 图形图象 | 网络应用 | 精文荟萃 | 教育认证 | 硬件维护 | 未整理篇 | 站长教程
ASP JS PHP工程 ASP.NET 网站建设 UML J2EESUN .NET VC VB VFP 网络维护 数据库 DB2 SQL2000 Oracle Mysql
服务器 Win2000 Office C DreamWeaver FireWorks Flash PhotoShop 上网宝典 CorelDraw 协议大全 网络安全 微软认证
硬件维护  CPU  主板  硬盘  内存  显卡  显示器  键盘鼠标  声卡音箱  打印机  机箱电源  BIOS  网卡  C#  Java  Delphi  vs.net2005
  当前位置:> 程序开发 > Web开发 > JavaScripts > 综合文章
TutorialforbuildingJ2EEApplicationsusingJBOSSandECLIPSE-5
作者:佚名 时间:2005-03-11 11:03 出处:互连网 责编:chinaitpower
              摘要:TutorialforbuildingJ2EEApplicationsusingJBOSSandECLIPSE-5

Chapter 5.



Creating a BMP Entity Bean


This chapter describes how to create a Bean Managed Persistence (BMP) EJB component. We will create two BMP beans, Customer and Manager, as shown below. The Customer bean will be responsible for storing the details of customers of MyStore. The Manager bean stores details of the manager of MyStore. Both beans communicate with their respective tables in the database using Data Access Objects (DAOs) named CustomerDAO and ManagerDAO respectively.









All customers have been assigned a unique customerID for housekeeping purposes in MyStore in addition to their username for accessing the services of MyStore. Similarly the Manager of MyStore has been assigned a unique ManagerID.





Note : It is the usual practice to access business methods of BMP beans via a session bean, which encapsulates business logic and acts as an interface to further EJB components. In this case Customer and Manager are accessible via by StoreAccess.


This approach comes from a pattern called a Session Facade, whereby enterprise beans encapsulate business logic and business data and expose their interfaces. The session bean acts as a facade to encapsulate the complexity of interactions with the lower-level beans. The session facade is responsible for managing business objects and provides a uniform business service abstraction to presentation layer clients, thereby hiding the business object implementation in the lower-level beans.


This tutorial uses that pattern for business tier implementation.


Tasks :




  1. Create a BMP bean named Customer under package au.com.tusc.bmp.



  2. Create a DAO class named CustomerDAOImpl under package au.com.tusc.dao.



  3. Add all attributes/properties to the CustomerBean, with getter and setter methods for each of the attributes.



  4. Add a finder method named ejbFindByPrimaryKey with the signature


    public CustomerPK ejbFindByPrimaryKey (CustomerPK pk) throws FinderException



  5. Add a finder method named ejbFindByUserID with the signature


    public CustomerPK ejbFindByUserID (String userID) throws FinderException



  6. Add a business method named getCustomerData with the signature


    public CustomerData getCustomerData()



  7. Implement required methods in the CustomerDAOImpl class.



  8. Deploy the Customer Bean.



  9. Add a create method to the StoreAccess Bean.


    public void ejbCreate() throws javax.ejb.CreateException



  10. Add a business method to the StoreAccess Bean.


    public CustomerData getCustomerData(String userID)



  11. Create a test client named SessionBMPClient under package au.com.tusc.client.



  12. Run your client and test the bean.




Create the Customer BMP Entity Bean :




Go To Package Explorer > Expand Mystore (project) node > select src, right click and a menu will pop up.


On the pop up menu > New > Lomboz EJB Creation Wizard.


Enter package name au.com.tusc.bmp, bean name Customer and select bean type as Bean Manged Entity > Finish.


This will create a package named au.com.tusc.bmp under src and CustomerBean under that package as shown below.



Note: It will generate the bean name, jndi-name and type of bean in file. Also, the word 'Bean' is appended to the name of the file.


As we can see from the figure above it has created a class level tag @ejb.bean, which has assigned the bean type, its name and its JNDI name which will be generated in the Home interface. This tag will also generate deployment descriptors in ejb-jar.xml and jboss.xml file once you generate your EJB classes.


Now we are going to generate all the interfaces including Home, Remote, DAO and other helper classes. We don't need to specify any tags in ejbGenerate.xml as we have already set up that for the MyStoreMgr EJB module in chapter 3.


Go to node CustomerBean under au.com.tusc.bmp > LombozJ2EE > Add EJB to Module > Select MyStoreMgr > Ok.


Go to MyStoreMgr node > LombozJ2EE > Generate EJB classes.


Note: All these steps are covered in previous chapters (chapter 3 and 1) so please refer to those sections if you need further details.


Now let's see what files are generated by Xdoclet.


As shown below there are two new files named CustomerData and CustomerPK in addition to what we had for our session beans. We also have a CustomerBMP which extends our CustomerBean class. The remaining files should be familiar from our work with session beans.



As discussed in chapter 3 regading the various ejbDoclet tags used in ejbGenerate.xml, to generate these classes, CustomerData and CutomerPk are generated by following tags as shown below in this snippet from ejbGenerate.xml:


The relevant tags are <dataobject/> and <entitypk/>.



Note: There is no CustomerDAO class, as we haven't generated that file by specifying the dao tag in the CustomerBean class.


Create Customer's DAO Interface :




Since we are going to use a DAO to access database for this bean, we have to create a DAOImpl class to provide an implementation for the generated DAO interface.


Go to src > package au.com.tusc.dao > Add a class

关闭本页
 
首页 | 投资与合作 | 服务条款 | 隐私政策 | 收藏本站 | 设为首页 | 新用户注册 | 免责声明 | 使用帮助
Copyright ©2005-2008 chinaitpower.com All rights reserved. www.chinaitpower.com 版权所有