?? queryorder.java
字號(hào):
package order.javabean;
import order.ejb.*;
import order.common.*;
import java.util.*;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
import javax.ejb.*;
public class QueryOrder{
String user_id;
HashMap pHashMap=new HashMap();
ProductHome producthome=null;
OrderHome orderhome=null;
// 取得ProductHome和OrderHome
public QueryOrder() throws Exception{
Context initial=new InitialContext();
Object objref=initial.lookup("ejb/ProductEntityBean");
producthome=(ProductHome)
PortableRemoteObject.narrow(objref, ProductHome.class);
objref=initial.lookup("ejb/OrderEntityBean");
orderhome=(OrderHome)
PortableRemoteObject.narrow(objref, OrderHome.class);
setProductHashMap();
}
// 設(shè)定或取得REQUEST網(wǎng)頁(yè)傳過(guò)來(lái)的資料
public void setUser_id(String user_id){
this.user_id=user_id;
}
public String getUser_id(){
return this.user_id;
}
//設(shè)定產(chǎn)品id與產(chǎn)品項(xiàng)目物件(ProductItem類別)對(duì)應(yīng)的HashMap
private void setProductHashMap() throws Exception{
Collection c=producthome.findAll();
Iterator i=c.iterator();
while (i.hasNext()) {
ProductItem pItem=
((Product)i.next()).getProductData();
pHashMap.put(pItem.getProduct_id(),pItem);
}
}
//取得產(chǎn)品名稱
public String getProductName(String product_id){
return ((ProductItem)pHashMap.get(product_id)).getName();
}
//取得產(chǎn)品價(jià)格
public int getProductPrice(String product_id){
return ((ProductItem)pHashMap.get(product_id)).getPrice();
}
//取得所有訂單的訂購(gòu)項(xiàng)目
public Hashtable getOrders() throws Exception{
Hashtable orderHt=new Hashtable();
Iterator i=null;
try{
i=orderhome.findByUserId(user_id).iterator();
}
catch(ObjectNotFoundException oex){
throw new Exception("沒(méi)有訂購(gòu)單記錄!");
}
catch(Exception ex){
throw new Exception("查詢訂單發(fā)生錯(cuò)誤!");
}
while(i.hasNext()){
Order order=(Order)i.next();
ArrayList al=order.getOrderItems();
orderHt.put(order.getOrder_id(),al);
}
return orderHt;
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -