?? queryorder.java
字號:
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();
}
// 設定或取得REQUEST網頁傳過來的資料
public void setUser_id(String user_id){
this.user_id=user_id;
}
public String getUser_id(){
return this.user_id;
}
//設定產品id與產品項目物件(ProductItem類別)對應的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);
}
}
//取得產品名稱
public String getProductName(String product_id){
return ((ProductItem)pHashMap.get(product_id)).getName();
}
//取得產品價格
public int getProductPrice(String product_id){
return ((ProductItem)pHashMap.get(product_id)).getPrice();
}
//取得所有訂單的訂購項目
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("沒有訂購單記錄!");
}
catch(Exception ex){
throw new Exception("查詢訂單發生錯誤!");
}
while(i.hasNext()){
Order order=(Order)i.next();
ArrayList al=order.getOrderItems();
orderHt.put(order.getOrder_id(),al);
}
return orderHt;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -