WCS学习笔记(第八天) - 创建entity bean实现
来源:互联网 发布:php动态网页设计 编辑:程序博客网 时间:2024/06/08 16:07
1. 创建数据库表XBONUS:
a. 启动wcs服务器;
b. IE打开:URL: http://localhost/webapp/wcs/admin/servlet/db.jsp;
c. 插入sql:
Derby/DB2: create table XBONUS (MEMBERID BIGINT NOT NULL, BONUSPOINT INTEGER NOT NULL, OPTCOUNTER SMALLINT NOT NULL,constraint p_xbonus primary key (MEMBERID), constraint f_xbonus foreign key (MEMBERID) references users (users_id) on delete cascade); Oracle: create table XBONUS (MEMBERID NUMBER NOT NULL,BONUSPOINT INTEGER NOT NULL, OPTCOUNTER SMALLINT NOT NULL,constraint p_xbonus primary key (MEMBERID), constraint f_xbonus foreign key (MEMBERID references users (users_id) on delete cascade);
2. 创建BonusBean实体Bean:
a. 右键 Deployment Descriptor: WebSphereCommerceServerExtensionsData; 选择
- 选择 Entity bean with container-managed persistence (CMP) fields
- 在 Bean name 项, 输入Bonus
- Source folder 项保持默认ejbModule
- 在Default package项, 输入com.ibm.commerce.extension.objects
- CMP Version选项选择1.x
- 点击 Next
b. 在Enterprise Bean Details窗口,为BONUS的MEMBERID and BONUSPOINT等列增加CMP属性
- 选择 default CMP attribute id:java.lang.Integer 并 点击Remove
- 点击 Add
- 在 Name 项, 输入memberId
- 在Type项, 输入 java.lang.Long
- 勾选Key Field , 表示为Bean和数据表主键标识
- 点击 Apply
- 在Name 项, 输入bonusPoint
- 在Type 项, 输入java.lang.Integer
- 确保 Access with getter and setter methods 勾选,用于自动生成get、set方法
- 点击 Apply
- 在 Name 项, 输入 optCounter
- 在 Type 项, 输入 short
- 取消 Access with getter and setter metheos 选项
- 点击 Apply并关闭CMP窗口
- 确保 Use the single key attribute type for the key class 选项不被选择(取消选中), 然后点击Next
b. 在EJB Java Class Details窗口,增加Bonus实体Bean调用
- 选择bean superclass, 点击Browse.
- 在 Type Selection 窗口,Select a class using: (any)项, 输入 ECEntityBean 并点击OK.
- 点击 Add 指定远程接口.
- 在 Type Selection 窗口,Select an interface using: (any) 项, 输入Protectable 并点击OK 选择com.ibm.commerce.security.Protectable.
- 点击 Next.
- 取消选中 Add bean to Class Diagram.
- 点击 Finish.
3. 为新建Bean设置隔离等级(isolation level):
4. 为Bean设置安全标识(security identity):
b. 在Security Identity (Method Level)栏目中点击Add
5. 为Bean方法设置安全作用(security role):
b. 在 Method Permissions 栏目中点击Add
6. 增删BonusBean参数和方法:
a. 打开 .java
b. 删除下面声明和方法(可在Outline view窗口操作)
删除参数:myEntityCtx
删除方法:getEntityContext()、setEntityContext(EntityContext)、unsetEntityContext()
c. 增加getMemberId方法
public java.lang.Long getMemberId() { return memberId;}
d. Outline view 窗口中右键 getMemberId 方法,选择
7. 为BonusHome接口增加FinderHelper方法:
a. 打开
8. 增加ejbCreate and ejbPostCreate方法,使用ejbCreate进行数据库插入操作:
a. 打开
方法,选择 ,添加到home interface
c. 增加ejbPostCreate(Long, Integer)方法
9. 增加getOwner and fulfills方法:
a. 打开
public java.lang.Long getOwner() throws java.lang.Exception { return getMemberId(); }
public boolean fulfills(Long member, String relationship) throws java.lang.Exception { if ("creator".equalsIgnoreCase(relationship)) { return member.equals(getMemberId()); } return false; }
10. 创建数据库和表定义:
a. 右键WebSphereCommerceServerExtensionsData 选择
d. 在
右键Columns 选项卡新建对应列,如下:
,输入XBONUS, 在
f. 点击Finish
11. 关联XBONUS表和entity bean:
a. 右键 WebSphereCommerceServerExtensionsData EJB project 选择
12. 使用乐观锁:
a. Bean tab > Bonus bean
>b. 在 Concurrency Control 栏目中勾选Enable optimistic locking
13. 在optcounter设置相关属性:
a. 在
窗口Enterprise Beans 选项卡中选择optcounter : short
c. 在 Properties 视图中,为 OptimisticPredicate 选择 true
14. 编辑BonusBean.java的方法调用乐观锁类:
a. 在 ejbLoad()方法第一行加上 super.ejbLoad();
b. 在 ejbStore()方法第一行加上 super.ejbStore();
c. ejbCreate(Long, Integer)方法修改为:
public com.ibm.commerce.extension.objects.BonusKey ejbCreate( java.lang.Long memberId,java.lang.Integer bonusPoint) throws javax.ejb.CreateException { this.initializeFields(); _initLinks(); this.memberId=memberId; this.bonusPoint=bonusPoint; BonusKey myNewKey = new BonusKey(memberId); this.initializeOptCounter(myNewKey); return null; }
15. 创建access bean:
a. 右键 WebSphereCommerceServerExtensionsData project 选择 点击Next
b. 选择 Copy helper 点击Next
c. 选择 Bonus bean 点击Next
d. 在 Constructor Method 选项, 选择findByPrimaryKey(com.ibm.commerce.extension.objects.BonusKey) 点击Finish.
e. 在 Overview 选项卡中下拉找到JNDI - CMP Connection Factory Binding 栏目,JNDI name 输入下面名称
17. 更新BonusAccessBean:
a. 右键 WebSphereCommerceServerExtensionsData 选择
b. 在 Select access beans to regenerate 窗口,点击Deselect All
c. 只选择 BonusAccessBean
d. 点击 Finish
参考: http://pic.dhe.ibm.com/infocenter/wchelp/v7r0m0/topic/com.ibm.commerce.developer.tutorial.doc/tutorial/ttd18.htm
- WCS学习笔记(第八天) - 创建entity bean实现
- WCS学习笔记(第九天) - MyNewControllerCmd整合Bonus entity bean
- 第八天学习笔记
- WCS学习笔记(第五天) - Controller实现参数分析与验证validateParameters()
- WCS学习笔记(第十一天) - 创建MyOrderItemAddCmdImpl实现重写加入购物车逻辑
- java学习笔记--第八天
- WCS学习笔记(第一天) - 增加一个JSP页面访问
- WCS学习笔记(第三天) - JSP提取Controller信息
- WCS学习笔记(第七天) - 修改MyNewTaskCmd任务命令
- WCS学习笔记(第六天) - 创建新的任务命令
- WCS学习笔记(第十天) - 创建消息信息
- J2EE学习笔记五:entity bean概念
- Entity Bean(经典学习笔记之一)
- 黑马程序员--- 学习笔记(第八天)
- iOS-学习笔记-UI-第八天
- 黑马程序员--java学习笔记第八天
- WCS学习笔记(第四天) - 使用data bean从MyNewControllerCmd 向 MyNewView传递信息
- 第八天:听课笔记
- android编译模块
- 让工作更轻松——EA类图与代码同步
- 机制与策略
- java 实现图片的任意拖动
- 30天自制OS笔记(一)前10天内容中遇到的问题
- WCS学习笔记(第八天) - 创建entity bean实现
- F28335_DMA使用
- cocos2d-x 使用 CCScale9Sprite 实现微信对话框
- Ubuntu 12.04 快速安装 ADB, fastboot
- java基础语法
- 非常实用的15款开源PHP类库
- ArrayList<String> 转化为String数组问题
- Android中Bitmap和Drawable转换(zz)
- IOS APP的图标尺寸、启动画面尺寸、宣传画面尺寸