1 4 package org.objectweb.jonas.stests.appli; 5 6 import java.rmi.RemoteException ; 7 import java.util.Enumeration ; 8 import java.util.Vector ; 9 10 import javax.ejb.CreateException ; 11 import javax.ejb.SessionBean ; 12 import javax.ejb.SessionContext ; 13 import javax.naming.InitialContext ; 14 import javax.rmi.PortableRemoteObject ; 15 16 import org.objectweb.jonas.common.Log; 17 import org.objectweb.util.monolog.api.BasicLevel; 18 import org.objectweb.util.monolog.api.Logger; 19 20 21 24 public class OrderPlacementSLR implements SessionBean { 25 26 static private Logger logger = null; 27 private transient SessionContext ctx; 28 29 33 34 public void setSessionContext(SessionContext ctxt) { 35 if (logger == null) { 36 logger = Log.getLogger("org.objectweb.jonas_tests"); 37 } 38 logger.log(BasicLevel.DEBUG, ""); 39 ctx = ctxt; 40 } 41 42 43 public void ejbRemove() { 44 logger.log(BasicLevel.DEBUG, ""); 45 } 46 47 48 public void ejbCreate() throws CreateException { 49 logger.log(BasicLevel.DEBUG, ""); 50 } 51 52 public void ejbPassivate() { 53 logger.log(BasicLevel.DEBUG, ""); 54 } 55 56 public void ejbActivate() { 57 logger.log(BasicLevel.DEBUG, ""); 58 } 59 60 64 75 public float placeOrder(String wID, String dID, Integer cID, Vector orderLines) 76 throws RemoteException { 77 78 try { 79 int districtInt = Integer.parseInt(dID); 80 return placeOrder(wID, districtInt, cID, orderLines); 81 } catch (NumberFormatException nfe) { 82 throw new RemoteException ("Unable to covert district id (" + cID + ") to an int."); 83 } 84 85 } 86 87 88 98 public float placeOrder(String wID, int dID, Integer cID, Vector orderLines) 99 throws RemoteException { 100 float oID = 0; 101 logger.log(BasicLevel.DEBUG, ""); 102 try { 103 InitialContext initCtx = new InitialContext (); 105 106 DistrictHome dHome = (DistrictHome) PortableRemoteObject.narrow(initCtx.lookup("DistrictHome"), DistrictHome.class); 108 DistrictID districtID = new DistrictID(dID, wID); 109 District district = (District)dHome.findByPrimaryKey(districtID); 110 oID = district.getNextOrderId(true); 112 logger.log(BasicLevel.DEBUG,"(District)dHome.findByPrimaryKey("+districtID+"); OK"); 113 114 StockHome sHome = (StockHome) PortableRemoteObject.narrow(initCtx.lookup("StockHome"), StockHome.class); 116 Enumeration lines = orderLines.elements(); 117 float orderTotal = 0; 118 while(lines.hasMoreElements()){ 119 OrderDetail od = (OrderDetail)lines.nextElement(); 120 Integer itemID = od.getItemID(); 121 int itemQty = od.getItemQty(); 122 orderTotal += od.getItemAmount(); 124 StockID stockID = new StockID(wID, itemID); 125 Stock stock = (Stock)sHome.findByPrimaryKey(stockID); 126 logger.log(BasicLevel.DEBUG,"(Stock)sHome.findByPrimaryKey("+stockID+");OK "); 127 stock.decreaseStockQuantity(itemQty); 128 logger.log(BasicLevel.DEBUG,"stock.decreaseStockQuantity("+itemQty+")"); 129 } 130 131 OrderHome oHome = (OrderHome) PortableRemoteObject.narrow(initCtx.lookup("OrderHome"), OrderHome.class); 133 Order o = oHome.create(wID, dID, cID, oID, orderLines); 134 System.out.println(">>>>>>>> CID= "+o.getCustomerID()+ " LC= "+o.getOrderLineCount()); 135 logger.log(BasicLevel.DEBUG,"OrderHome.create("+wID+","+ dID+","+ cID+","+ oID+","+ orderLines+"); OK"); 136 CustomerHome cHome = (CustomerHome) PortableRemoteObject.narrow(initCtx.lookup("CustomerHome"), CustomerHome.class); 138 139 Customer customer = (Customer)cHome.findByPrimaryKey(cID); 140 customer.updateBalance(orderTotal); 141 logger.log(BasicLevel.DEBUG,"(Customer)cHome.findByPrimaryKey("+cID+"); OK"); 142 try{ 144 writeDataQueue(wID, dID, cID, oID); 145 } catch(Exception e){ 146 System.out.println("WriteDataQueue error: " + e.getMessage()); 147 throw new RemoteException (e.getMessage()); 148 } 149 150 } catch (Exception e) { 151 throw new RemoteException (e.getMessage()); 152 } 153 logger.log(BasicLevel.DEBUG,"OrderPacementBean: placeOrder return "+oID); 154 return oID; 155 } 156 157 private void writeDataQueue(String wID, int dID, Integer cID, float oID) throws Exception {} 158 } 159 160 | Popular Tags |