📄 day11.txt
字号:
建表:
create table shipmentstatus(
statusid integer primary key,
name varchar2(32) not null
);
insert into shipmentstatus values(1, 'preparing');
insert into shipmentstatus values(2, 'prepared');
insert into shipmentstatus values(3, 'shipped');
insert into shipmentstatus values(4, 'received');
create table shipment(
shipmentid integer primary key,
orderid integer references order(orderid),
statusid integer references shipmentstatus(statusid)
);
==========================================================
1,创建ShipmentEJB
右键点击数据源重的shipment表 --->
create entity 2.0 cmp bean
bean name : ShipmentEJB
abastract schame name : Shipment
interface : local
----> class package
bean name : ShipmentEJB
bean class : ShipmentBean
local home : ShipmentLocalHome
Local interface: ShipmentLcoal
修改属性:
shipmentid :
is primary key : true
type : Integer
in ejbcreate : true
删除属性: ordeid , statusId
==========================================================
2, 创建 1,创建ShipmentstatucsEJB
右键点击数据源重的shipmentstatus表 --->
create entity 2.0 cmp bean
bean name : ShipmentstatucsEJB
abastract schame name : Shipmentstatucs
interface : local
----> class package
bean name : ShipmentstatucsEJB
bean class : ShipmentstatucsBean
local home : ShipmentstatucsLocalHome
Local interface: ShipmentstatucsLcoal
修改属性:
statusid :
is primary key : true
type : Integer
in ejbcreate : true
name :
is primary key : false
type : Integer
in ejbcreate : true
==========================================================
3, 从shipmentstatusEJB 发起,创建ShipmentstatusEJB 到ShipmentEJB 的 one - many relationship
右键点击 ShipmentstatusEJB ---> add ---> relationship
指向 ShipmentEJB
编辑ShipmentstatusEJB中的联系域
motiplicity : one to many
navigability : biredirection
field name : shipments
return type : java.util.Collection
编辑ShipmentstatusEJB中的关系域
navigability : biredirection
field name : status
return type : bean instance
---> edit rdbms relationship
==========================================================
4,从OrderEJB发起,创建从OrderEJB 到 ShipmentEJB 的 one-one relationship
右键点击 OrderEJB ---> add ---> relationship
指向 ShipmentEJB
编辑OrderEJB中的联系域
motiplicity : one to one
navigability : biredirection
field name : shipment
return type : bean instance
编辑ShipmentEJB中的关系域
navigability : biredirection
field name : order
return type : bean instance
---> edit rdbms relationship
==========================================================
5,为ShipmentEJB 添加商业方法
右键点击 OrderEJB ---> add ---> finder
finder name : findAll
return type : java.util.Collection
input parameter :
home interface : Local home
query : select object( s ) from Shipment s
==========================================================
7, 在dto 中创建 ShipmentStatusDTO
package dto;
import java.io.Serializable;
public class ShipmentStatusDTO implements Serializable{
private String statusID;
private String name;
public ShipmentStatusDTO(String id , String name ) {
this.statusID = id;
this.name = name;
}
public void setStatusID( String id ){
this.statusID = id;
}
public String getStatusID(){
return this.statusID;
}
public void setName( String name ){
this.name = name;
}
public String getName(){
return this.name;
}
}
=========================================================
8, 在dto包中创建 ShipmentDTO
package dto;
import java.io.Serializable;
public class ShipmentDTO implements Serializable{
private String id ;
private String orderid;
private String userid;
private ShipmentStatusDTO status;
private double cost;
public ShipmentDTO() {
}
public ShipmentDTO( String id, String order ,
ShipmentStatusDTO status,String userid,double cost){
this.id = id;
this.orderid = order;
this.status = status;
this.userid = userid;
this.cost = cost;
}
public String getId(){
return this.id;
}
public void setId( String id ){
this.id = id;
}
public String getOrder(){
return this.orderid;
}
public void setOrder( String order ){
this.orderid = order;
}
public ShipmentStatusDTO getStatus(){
return this.status;
}
public void setStutas( ShipmentStatusDTO status ){
this.status = status;
}
public String getUserid(){
return this.userid;
}
public void setUserid( String userid ){
this.userid = userid;
}
public void setCost( double cost ){
this.cost = cost;
}
public double getCost( ){
return this.cost;
}
}
==========================================================
9, 在excepitons包中封装ManageException
==========================================================
10,为ShoppingSessionFacade添加商业方法
右键点击 ShoppingSessionFacade ---> add ---> method
1)
method name : getAllShipment
return type : java.util.Collection
input paramenter :
interface : local
2)
method name : getOrderLinesByOrderId
return type : java.util.Collection
input paramenter : java.lang.String id
interface : local
==========================================================
11,为getAllShipment和getOrderLinesByOrderId添加函数体:
右键点击 ShoppingSessionFacade --->view bean source
public java.util.Collection getAllShipment()
throws ManageException {
HashSet hs = new HashSet();
try{
Collection col = shipmentLocalHome.findAll();
Iterator i = col.iterator();
while( i.hasNext() ){
ShipmentLocal sLocal= (ShipmentLocal) i.next();
OrderLocal oLocal = sLocal.getOrder();
ShipmentstatusLocal statusLocal =
sLocal.getShipmentstatus();
ShipmentStatusDTO status =
new ShipmentStatusDTO(
statusLocal.getStatusid().intValue() + "",
statusLocal.getName());
ShipmentDTO shipment = new ShipmentDTO(
sLocal.getShipmentid().intValue() + "",
oLocal.getOrderid().intValue() + "",
status,oLocal.getUserid(),
oLocal.getCost() );
hs.add( shipment);
}
return hs;
}catch( FinderException fe ){
fe.printStackTrace();
throw new ManageException( fe.getMessage() );
}
public Collection getOrderLinesByOrderId(String id)
throws ManageException {
HashSet set = new HashSet();
try{
OrderLocal oLocal = orderLocalHome.
findByPrimaryKey( new Integer(id.trim()));
Collection lines = oLocal.getOrderlines();
Iterator i = lines.iterator();
ProductDTO product = null;
OrderLine orderLine = null;
CategoryDTO category = null;
while( i.hasNext() ){
OrderlineLocal line = (OrderlineLocal) i.next();
ProductLocal pLocal = line.getProduct();
CategoryLocal cLocal = pLocal.getCategory();
category = new CategoryDTO(
cLocal.getCategoryid(),
cLocal.getName(),
cLocal.getDescription());
product = new ProductDTO(pLocal.getProductid(),
pLocal.getName(),
pLocal.getBaseprice(),
pLocal.getDescription(),
category);
orderLine = new OrderLine(
product , line.getAmount() );
set.add( orderLine );
}
return set;
}catch( FinderException fe ){
fe.printStackTrace();
throw new ManageException( fe.getMessage() );
}
}
为ShoppingDelegate添加方法:
public Collection getAllShipment()
throws ManageException{
return sessionLocal.getAllShipment();
}
public Collectio getOrderlinesByOrderId(String orderId )
throws ManageException{
return sessionLocal.
getOrderLinesByOrderId( orderId );
}
==========================================================
12,修改ShoppingSessionFacadeLocal中的函数声明,使之与
bean class 中的一致
package ejbs;
import javax.ejb.*;
import java.util.*;
import exceptions.OrderException;
import exceptions.ManageException;
public interface ShoppingSessionFacadeLocal
extends javax.ejb.EJBLocalObject {
public void addOrder(double cost, String no, String uid, String payway, Collection lines) throws OrderException;
public Collection getAllPayway() throws OrderException;
public Collection getAllShipment()
throws ManageException;
public Collection getOrderlinesByOrderId(
String orderId ) throws ManageException;
}
==========================================================
13,修改ShoppingSessionFacade中的addOrder方法,增加创建Shipment的功能 (如下:)
public void addOrder(double cost, String no, String uid,
String payway, Collection lines) throws OrderException {
try{
SequenceLocal seqLocal = sequenceLocalHome.
findByPrimaryKey( new Integer(1));
OrderStatusLocal osLocal = orderStatusLocalHome.
findByPrimaryKey(new Integer(1));
PaywayLocal payLocal = paywayLocalHome.
findByPrimaryKey( new Integer(payway));
ShipmentstatusLocal ssLocal=shipmentStatusLocalHome.
findByPrimaryKey(new Integer(1));
OrderLocal orderLocal = orderLocalHome.create(
new Integer(seqLocal.getSequence()),
"dddd",0,cost,no,uid);
orderLocal.setFinished( 0 );
orderLocal.setOrderStatus(osLocal);
orderLocal.setPayway(payLocal);
Iterator i = lines.iterator();
while( i.hasNext() ){
OrderLine line = (OrderLine)i.next();
int amount = line.getAmount();
int seq = seqLocal.getSequence();
OrderlineLocal lineLocal =
orderlineLocalHome.create(
new Integer(seq),amount);
ProductLocal proLocal = productLocalHome
.findByPrimaryKey(
line.getProduct().getProductId());
lineLocal.setOrderid( orderLocal );
lineLocal.setProduct( proLocal );
}
ShipmentLocal sLocal = shipmentLocalHome.create(
new Integer( seqLocal.getSequence() )
);
sLocal.setOrder( orderLocal );
sLocal.setShipmentstatus( ssLocal );
}catch( CreateException ce ){
ce.printStackTrace();
throw new OrderException( ce.getMessage() );
}
catch( FinderException fe ){
fe.printStackTrace();
throw new OrderException ( fe.getMessage() );
}
}
==========================================================
14,修改advinceMgm.jsp,添加shipment manage连接:
<html:link href="shipmentMgm.do">
shipment management
</html:link>
==========================================================
15,为shipmentMgm.do 创建Action
file --> new --> web --> Aciton
package : ec_port_web
Aciton : ShipmentMgmAction
---> next
Action path : shipmentMgm.do
formbean name :
scope :
validate :
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -