KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > stests > appli > OrderEntryClerkSFR


1 // OrderEntryClerkSFR.java
2
// Stateful Session Bean
3

4 package org.objectweb.jonas.stests.appli;
5
6 import java.rmi.RemoteException JavaDoc;
7 import java.sql.Connection JavaDoc;
8 import java.sql.ResultSet JavaDoc;
9 import java.sql.SQLException JavaDoc;
10 import java.sql.Statement JavaDoc;
11 import java.util.Vector JavaDoc;
12
13 import javax.ejb.CreateException JavaDoc;
14 import javax.ejb.EJBException JavaDoc;
15 import javax.ejb.SessionBean JavaDoc;
16 import javax.ejb.SessionContext JavaDoc;
17 import javax.naming.Context JavaDoc;
18 import javax.naming.InitialContext JavaDoc;
19 import javax.rmi.PortableRemoteObject JavaDoc;
20 import javax.sql.DataSource JavaDoc;
21
22 import org.objectweb.jonas.common.Log;
23 import org.objectweb.util.monolog.api.BasicLevel;
24 import org.objectweb.util.monolog.api.Logger;
25
26
27 /**
28  *
29  */

30 public class OrderEntryClerkSFR implements SessionBean JavaDoc {
31
32     static private Logger logger = null;
33     SessionContext JavaDoc ejbContext;
34     private transient Connection JavaDoc dbConn = null;
35     private static String JavaDoc whid = "0001";
36     private static String JavaDoc did = "1";
37
38     // table names
39
private static String JavaDoc customersTable = null;
40     private static String JavaDoc stocksTable = null;
41     private static String JavaDoc itemsTable = null;
42     private static String JavaDoc ordersTable = null;
43     private static String JavaDoc orderlinesTable = null;
44
45     // Following is the state in this stateful session bean
46
public Integer JavaDoc custID;
47     public Vector JavaDoc items;
48
49     // (The DataSource can be shared among all instances)
50
protected static DataSource JavaDoc dataSource = null;
51
52     // ------------------------------------------------------------------
53
// SessionBean implementation
54
// ------------------------------------------------------------------
55

56
57     public void setSessionContext(SessionContext JavaDoc ctx) {
58         if (logger == null) {
59             logger = Log.getLogger("org.objectweb.jonas_tests");
60         }
61         logger.log(BasicLevel.DEBUG, "");
62         ejbContext = ctx;
63         if ( customersTable == null) {
64             try {
65                 InitialContext JavaDoc initialContext = new InitialContext JavaDoc();
66                 customersTable = (String JavaDoc) initialContext.lookup("java:comp/env/CustomerTableName");
67                 stocksTable = (String JavaDoc) initialContext.lookup("java:comp/env/StockTableName");
68                 itemsTable = (String JavaDoc) initialContext.lookup("java:comp/env/ItemTableName");
69                 ordersTable = (String JavaDoc) initialContext.lookup("java:comp/env/OrderTableName");
70                 orderlinesTable = (String JavaDoc) initialContext.lookup("java:comp/env/OrderlineTableName");
71             } catch (Exception JavaDoc e) {
72                 logger.log(BasicLevel.ERROR, "cannot lookup env-entry "+e);
73                 System.exit(2); // stop all
74
}
75         }
76     }
77         
78
79     public void ejbRemove() {
80         logger.log(BasicLevel.DEBUG, "");
81     }
82         
83
84     public void ejbCreate() throws CreateException JavaDoc {
85         logger.log(BasicLevel.DEBUG, "");
86         items = new Vector JavaDoc();
87         custID = null;
88     }
89
90     public void ejbPassivate() {
91         logger.log(BasicLevel.DEBUG, "");
92     }
93
94     public void ejbActivate() {
95         logger.log(BasicLevel.DEBUG, "");
96     }
97     
98     // ------------------------------------------------------------------
99
// OrderEntryClerk implementation
100
// ------------------------------------------------------------------
101

102     // Set the current customer
103
public void setCustomer(Integer JavaDoc cid) throws RemoteException JavaDoc {
104         logger.log(BasicLevel.DEBUG, "customer = "+cid);
105         if ( verifyCustomer(cid) ) {
106             custID = cid;
107         } else {
108             throw new CpwejbException("Customer id " + cid + " not valid");
109         }
110     }
111
112     // Find all available customers
113
public Vector JavaDoc findAllCustomers() throws RemoteException JavaDoc{
114         logger.log(BasicLevel.DEBUG, "");
115         Vector JavaDoc customerVector = new Vector JavaDoc();
116
117         Customer customer = null;
118         try {
119             Connection JavaDoc con = getConnection();
120             Statement JavaDoc stmt = con.createStatement();
121             ResultSet JavaDoc rs = stmt.executeQuery("select cid, cfirst, clast, cinit, caddr1, caddr2, ccity, cstate, czip from "+ customersTable);
122             while ( rs != null && rs.next() ) {
123                 String JavaDoc customerString[] = new String JavaDoc[9];
124                 customerString[0] = new Integer JavaDoc(rs.getInt("cid")).toString();
125                 customerString[1] = rs.getString("clast");
126                 customerString[2] = rs.getString("cfirst");
127                 customerString[3] = rs.getString("cinit");
128                 customerString[4] = rs.getString("caddr1");
129                 customerString[5] = rs.getString("caddr2");
130                 customerString[6] = rs.getString("ccity");
131                 customerString[7] = rs.getString("cstate");
132                 customerString[8] = rs.getString("czip");
133                 customerVector.addElement(customerString);
134             }
135             stmt.close();
136             releaseConnection(con);
137         } catch (Exception JavaDoc e) {
138             throw new RemoteException JavaDoc(e.getMessage());
139         }
140         return customerVector;
141
142     }
143
144     // Add an item and quantity to the order
145
public void addOrderLine(Integer JavaDoc iid, int quantity) throws RemoteException JavaDoc {
146         logger.log(BasicLevel.DEBUG, "item = "+iid+" qty = "+quantity);
147         if ( custID == null ) {
148             throw new CpwejbException("OrderEntryClerkBean: Customer ID must be set first");
149         }
150         
151         if ( items.size() == 25 ) {
152             throw new CpwejbException("OrderEntryClerkBean: Maximum of 25 lines per order reached");
153         }
154         Item item = null;
155         try {
156             InitialContext JavaDoc initCtx = new InitialContext JavaDoc();
157             ItemHome home =
158                 (ItemHome) PortableRemoteObject.narrow(initCtx.lookup("ItemHome"), ItemHome.class);
159             item = home.findByPrimaryKey(iid);
160         } catch (Exception JavaDoc e) {
161             throw new RemoteException JavaDoc(e.getMessage());
162         }
163         OrderDetail ol = new OrderDetail(iid, item.getItemPrice()*quantity, quantity);
164         items.addElement(ol);
165     }
166
167
168     // Reset the bean state ie the current customer and the current order
169
public void undoAll() throws RemoteException JavaDoc {
170         logger.log(BasicLevel.DEBUG, "");
171         // Clear out the state of the session bean at this point
172
items = new Vector JavaDoc();
173         custID = null;
174     }
175    // Verify an existing customer
176
public boolean verifyCustomer(Integer JavaDoc cid) throws RemoteException JavaDoc {
177         logger.log(BasicLevel.DEBUG, "cid = "+cid);
178         Customer customer = null;
179         boolean retval = false;
180         try {
181             Connection JavaDoc con = getConnection();
182             Statement JavaDoc stmt = con.createStatement();
183             ResultSet JavaDoc rs = stmt.executeQuery("select cid from "+ customersTable +" where cid = '" + cid + "'");
184             if ( rs != null && rs.next())
185                 retval = true;
186             stmt.close();
187             releaseConnection(con);
188         } catch (Exception JavaDoc e) {
189             throw new RemoteException JavaDoc(e.getMessage());
190         }
191         return retval;
192     }
193
194     // Place an order
195
public String JavaDoc placeOrder() throws RemoteException JavaDoc {
196         logger.log(BasicLevel.DEBUG, "");
197         String JavaDoc orderNumber = null;
198         if ( custID == null ) {
199         throw new CpwejbException("OrderEntryClerkBean: Customer ID must be set before placing an order");
200         }
201         if ( items.size() == 0 ) {
202             throw new CpwejbException("OrderEntryClerkBean: No order lines. Cannot place order.");
203     }
204
205         try {
206             InitialContext JavaDoc initCtx = new InitialContext JavaDoc();
207             OrderPlacementHome home = (OrderPlacementHome) PortableRemoteObject.narrow(initCtx.lookup("OrderPlacementHome"), OrderPlacementHome.class);
208             OrderPlacement placement = home.create();
209             float number = placement.placeOrder(whid, did, custID, items);
210             orderNumber = Float.toString(number);
211             orderNumber = orderNumber.substring(0,orderNumber.length()-2);
212             // Clear out the state of the session bean at this point
213
items = new Vector JavaDoc();
214             custID = null;
215         } catch (Exception JavaDoc e) {
216             throw new RemoteException JavaDoc(e.getMessage());
217         }
218         return orderNumber;
219     }
220    
221    // Find a range of items
222
public Vector JavaDoc findRangeOfItems(Integer JavaDoc lowID, Integer JavaDoc highID) throws RemoteException JavaDoc {
223         logger.log(BasicLevel.DEBUG, "low = "+lowID+" high = "+highID);
224         Vector JavaDoc itemVector = new Vector JavaDoc();
225
226         Item item = null;
227         try {
228             Connection JavaDoc con = getConnection();
229             Statement JavaDoc stmt = con.createStatement();
230             ResultSet JavaDoc rs = stmt.executeQuery("select iid, iname, iprice, idata, stqty from "+itemsTable+" , " + stocksTable +" where iid = stiid and iid >= '" + lowID +
231                          "' and iid <= '" + highID + "'");
232             while ( rs != null && rs.next() ) {
233                 String JavaDoc itemString[] = new String JavaDoc[5];
234                 itemString[0] = rs.getString("iid");
235                 itemString[1] = rs.getString("iname");
236                 itemString[2] = "$" + Float.toString(rs.getFloat("iprice"));
237                 itemString[3] = Integer.toString(rs.getInt("stqty"));
238                 itemString[4] = rs.getString("idata");
239                 itemVector.addElement(itemString);
240             }
241             stmt.close();
242             releaseConnection(con);
243         } catch (Exception JavaDoc e) {
244             throw new RemoteException JavaDoc(e.getMessage());
245         }
246         return itemVector;
247     }
248
249     public Vector JavaDoc findAllItems() throws RemoteException JavaDoc{
250         logger.log(BasicLevel.DEBUG, "");
251         Vector JavaDoc itemVector = new Vector JavaDoc();
252         Item item = null;
253         try {
254             Connection JavaDoc con = getConnection();
255             Statement JavaDoc stmt = con.createStatement();
256
257             ResultSet JavaDoc rs = stmt.executeQuery("select ProdId, Name, Price, Descrip, stqty from "+ customersTable + " , " + stocksTable + " where ProdId = stiid");
258
259             logger.log(BasicLevel.DEBUG,"select ProdId, Name, Price, Descrip, stqty from itemtable,stocktable where ProdId = stiid");
260             while ( rs != null && rs.next() ) {
261                 String JavaDoc itemString[] = new String JavaDoc[5];
262                 itemString[0] = rs.getString("ProdId");
263                 itemString[1] = rs.getString("Name");
264                 String JavaDoc price = "$" + Float.toString(rs.getFloat("Price"));
265                 // make sure the price ends with .00 for even dollar amounts
266
if ( price.endsWith(".0") ) {
267                     price += "0";
268                 }
269                 itemString[2] = price;
270                 itemString[3] = Integer.toString(rs.getInt("stqty"));
271                 itemString[4] = rs.getString("Descrip");
272                 itemVector.addElement(itemString);
273             }
274             stmt.close();
275             releaseConnection(con);
276         } catch (Exception JavaDoc e) {
277             throw new RemoteException JavaDoc(e.getMessage());
278         }
279         return itemVector;
280     }
281     public String JavaDoc[] getCustomerForOrder(String JavaDoc wid, int did, int oid)
282         throws RemoteException JavaDoc, CpwejbException {
283         logger.log(BasicLevel.DEBUG, "oid = "+oid);
284         Integer JavaDoc customerID = null;
285         String JavaDoc custInfo[] = new String JavaDoc[4];
286         try {
287             Connection JavaDoc con = getConnection();
288             Statement JavaDoc stmt = con.createStatement();
289             String JavaDoc stmtString = "select ocid from " + ordersTable + " where owid = '" + wid + "' and odid = " + did +
290                 " and oid = " + oid;
291             ResultSet JavaDoc rs = stmt.executeQuery(stmtString);
292             if ( rs != null && rs.next() ) {
293                 customerID = new Integer JavaDoc(rs.getInt("ocid"));
294                 custInfo[0] = custID.toString();
295                 if ( rs.next() ) {
296                     // There were multiple orders with the same key -- severe error
297
throw new RemoteException JavaDoc("Duplicate Key Error: " + wid + "/" + did + "/" + oid);
298                 }
299                 InitialContext JavaDoc initCtx = new InitialContext JavaDoc();
300                 CustomerHome cHome = (CustomerHome) PortableRemoteObject.narrow(initCtx.lookup("CustomerHome"), CustomerHome.class);
301                 Customer customer = (Customer)cHome.findByPrimaryKey(customerID);
302                 custInfo[1] = customer.getFirstName();
303                 custInfo[2] = customer.getMiddleInitials();
304                 custInfo[3] = customer.getLastName();
305             } else {
306                 // order does not exist
307
throw new CpwejbException("Order does not exists for warehouse " + wid +
308                       " district " + did + " order " + oid);
309             }
310             stmt.close();
311             releaseConnection(con);
312         } catch (Exception JavaDoc e) {
313             throw new RemoteException JavaDoc(e.getMessage());
314         }
315         return custInfo;
316     }
317
318
319     public Vector JavaDoc getItemsForOrder(String JavaDoc wid, int did, int oid)
320         throws RemoteException JavaDoc, CpwejbException {
321         logger.log(BasicLevel.DEBUG, "oid = "+oid);
322         Vector JavaDoc itemVector = new Vector JavaDoc();
323         try {
324             Connection JavaDoc con = getConnection();
325             Statement JavaDoc stmt = con.createStatement();
326             String JavaDoc stmtString = "select oliid, olqty, olamnt from " + orderlinesTable + " where olwid = '" + wid + "' and oldid = " + did +
327                 " and oloid = " + oid;
328             ResultSet JavaDoc rs = stmt.executeQuery(stmtString);
329             InitialContext JavaDoc initCtx = new InitialContext JavaDoc();
330             ItemHome iHome = (ItemHome) PortableRemoteObject.narrow(initCtx.lookup("ItemHome"), ItemHome.class);
331             while ( rs != null && rs.next() ) {
332                 String JavaDoc itemInfo[] = new String JavaDoc[4];
333                 Integer JavaDoc ItemID = new Integer JavaDoc(rs.getInt("oliid"));
334                 itemInfo[0] = ItemID.toString();
335                 itemInfo[2] = Integer.toString(rs.getInt("olqty"));
336                 itemInfo[3] = Float.toString(rs.getFloat("olamnt"));
337                 Item item = (Item)iHome.findByPrimaryKey(ItemID);
338                 itemInfo[1] = item.getItemName();
339                 itemVector.addElement(itemInfo);
340             }
341             stmt.close();
342             releaseConnection(con);
343         } catch (Exception JavaDoc e) {
344             throw new RemoteException JavaDoc(e.getMessage());
345         }
346         return itemVector;
347     }
348
349     public void createAllTables() {
350         logger.log(BasicLevel.DEBUG, "");
351         createCustomersTable();
352         createItemsTable();
353         createStocksTable();
354         createDistrictsTable();
355         createOtherTables();
356  
357     }
358
359     public void createOtherTables() {
360         createOrdersTable();
361         createOrderlinesTable();
362     }
363
364     public void createOrdersTable() {
365             logger.log(BasicLevel.DEBUG, "");
366         // Drop table
367
Connection JavaDoc conn = null;
368         Statement JavaDoc stmt = null;
369         try {
370             conn = getConnection();
371             stmt = conn.createStatement();
372             stmt.execute("drop table jt2_appli_order");
373         } catch (Exception JavaDoc e) {
374             // The first time, table will not exist.
375
logger.log(BasicLevel.INFO, "Exception in dropTable : " + e);
376         }
377
378         // Create table.
379
try {
380             stmt.execute("create table jt2_appli_order(owid varchar(4),odid integer,ocid integer,ooid float,olines integer,primary key (owid,odid,ooid))");
381             stmt.close();
382             conn.close();
383             logger.log(BasicLevel.DEBUG, "jt2_appli_order created");
384         } catch (SQLException JavaDoc e) {
385             logger.log(BasicLevel.ERROR, "Exception in createOrderTable : " + e);
386             throw new EJBException JavaDoc("Exception in createOrderTable");
387         }
388     }
389
390
391     public void createOrderlinesTable() {
392         logger.log(BasicLevel.DEBUG, "");
393         // Drop table
394
Connection JavaDoc conn = null;
395         Statement JavaDoc stmt = null;
396         try {
397             conn = getConnection();
398             stmt = conn.createStatement();
399             stmt.execute("drop table jt2_appli_orderline");
400         } catch (Exception JavaDoc e) {
401             // The first time, table will not exist.
402
logger.log(BasicLevel.INFO, "Exception in dropTable : " + e);
403         }
404
405         // Create table.
406
try {
407             stmt.execute("create table jt2_appli_orderline (OLOID float not null, OLDID integer not null, OLWID varchar(4) not null, OLNBR integer not null,OLIID integer, OLQTY integer, OLAMNT float,primary key (OLWID,OLDID,OLOID,OLNBR))");
408             stmt.close();
409             conn.close();
410             logger.log(BasicLevel.DEBUG, "jt2_appli_orderline created");
411         } catch (SQLException JavaDoc e) {
412             logger.log(BasicLevel.ERROR, "Exception in createOrderlinesTable : " + e);
413             throw new EJBException JavaDoc("Exception in createOrderlinesTable");
414         }
415   }
416  
417   private void createDistrictsTable() {
418         logger.log(BasicLevel.DEBUG, "");
419  
420         try {
421             InitialContext JavaDoc initCtx = new InitialContext JavaDoc();
422             DistrictHome home =
423                 (DistrictHome) PortableRemoteObject.narrow(initCtx.lookup("DistrictHome"),
424                                                            DistrictHome.class);
425             home.create(1,"0001","Belgique",0);
426             home.create(2,"0001","Espagne",0);
427             home.create(3,"0001","Finlande",0);
428             home.create(4,"0001","Irlande",0);
429             logger.log(BasicLevel.DEBUG, "jt2_appli_district created");
430         } catch (Exception JavaDoc e) {
431             logger.log(BasicLevel.ERROR, "Exception in createTable : " + e);
432             throw new EJBException JavaDoc("Exception in createTable");
433         }
434   }
435
436   private void createCustomersTable() {
437         logger.log(BasicLevel.DEBUG, "");
438  
439         try {
440             InitialContext JavaDoc initCtx = new InitialContext JavaDoc();
441             CustomerHome home =
442                 (CustomerHome) PortableRemoteObject.narrow(initCtx.lookup("CustomerHome"), CustomerHome.class);
443             home.create( new Integer JavaDoc(1),"Paul","Desgranges","PD","1 rue du bourg","",
444                    "Nice","06","","04050607",1000);
445             home.create( new Integer JavaDoc(2),"François","Exertier","FE","16 avenue J. jaures","",
446                    "Grenoble","38","","0476276115",1000);
447             home.create( new Integer JavaDoc(3),"Florent","Benoit","FB","20 place de la gare","",
448                    "Lyon","69","","04286745",1000);
449             home.create( new Integer JavaDoc(4),"Gérard","Vandome","GV","13 rue A. Einstein","",
450                    "Marseille","13","","04122436",1000);
451             home.create( new Integer JavaDoc(5),"Philippe","Coq","PC","3 rue du Village","",
452                    "Nice","06","","0405060713",1000);
453             home.create( new Integer JavaDoc(6),"Philippe","Durieux","PD","6 avenue J. Valles","",
454                    "Grenoble","38","","0476276115",1000);
455             home.create( new Integer JavaDoc(7),"Hélène","Joanin","HJ","30 place du Tramway","",
456                    "Lyon","69","","0428674513",1000);
457             home.create( new Integer JavaDoc(8),"Adriana","Danes","AD","23 rue Galilé","",
458                    "Marseille","13","","0412243613",1000);
459             home.create( new Integer JavaDoc(9),"Jacques","Cayuela","JC","29 rue de la Clef","",
460                    "Nice","06","","0405060717",1000);
461
462             home.create( new Integer JavaDoc(10),"Eric","Hardesty","EC","41 rue de la gare","",
463                    "Nancy","54","","0302060627",1000);
464             home.create( new Integer JavaDoc(11),"Goulven","Lejeune","GL","37 rue du Hameau","",
465                    "Nice","06","","0405060717",1000);
466             home.create( new Integer JavaDoc(12),"Christophe","Loridan","CL","26 avenue Gambetta","",
467                    "Grenoble","38","","0476276117",1000);
468             home.create( new Integer JavaDoc(13),"Jerome","Camilleri","JC","30 place des VFD","",
469                    "Lyon","69","","0428674519",1000);
470             home.create( new Integer JavaDoc(14),"Guillaume","Sauthier","GS","37 rue B.Giordano","",
471                    "Marseille","13","","0412243196",1000);
472            logger.log(BasicLevel.DEBUG, "jt2_appli_customer created");
473         } catch (Exception JavaDoc e) {
474             logger.log(BasicLevel.ERROR, "Exception in createTable : " + e);
475             throw new EJBException JavaDoc("Exception in createTable");
476         }
477   }
478     private void createItemsTable() {
479         logger.log(BasicLevel.DEBUG, "");
480  
481         try {
482             InitialContext JavaDoc initCtx = new InitialContext JavaDoc();
483             ItemHome home =
484                 (ItemHome) PortableRemoteObject.narrow(initCtx.lookup("ItemHome"), ItemHome.class);
485             home.create(new Integer JavaDoc(1),"Beaujolais 95",19,"Grumage - Domaine des Averlys");
486             home.create(new Integer JavaDoc(2),"Beaujolais 95",20,"Domaine des Averlys");
487             home.create(new Integer JavaDoc(3),"Beaujolais 96",18,"Cuvée Antique - Domaine de Rochecorbière");
488             home.create(new Integer JavaDoc(4),"Beaujolais 96",19,"Vin de garde - Domaine des Averlys");
489             home.create(new Integer JavaDoc(5),"Beaujolais 96",22,"Domaine des Fortières");
490             home.create(new Integer JavaDoc(6),"Beaujolais 97",28,"Médaille Or - Paul Champier Producteur");
491             home.create(new Integer JavaDoc(7),"Beaujolais 97",21,"Domaine du Berret");
492             home.create(new Integer JavaDoc(8),"Beaujolais 98",21,"Domaine des Fortières");
493             home.create(new Integer JavaDoc(9),"Beauj Rosé 96",19,"Domaine de Rochecorbière");
494             home.create(new Integer JavaDoc(10),"Beauj Rosé 96",19,"Domaine de la Croix Ange");
495             home.create(new Integer JavaDoc(11),"Beauj Rosé 97",21,"Domaine de la Chambarde");
496             home.create(new Integer JavaDoc(12),"Beauj Rosé 97",18,"Domaine des Averlys");
497             home.create(new Integer JavaDoc(13),"Beauj Blanc 96",24,"Domaine de Rochcorbière");
498             home.create(new Integer JavaDoc(14),"Beauj Blanc 96",21,"Domaine du Berret");
499             home.create(new Integer JavaDoc(15),"Beauj Nouveau",20,"Domaine du Berret");
500             home.create(new Integer JavaDoc(16),"Beauj Nouveau",21,"Domaine des Fortières");
501             home.create(new Integer JavaDoc(17),"Beauj Nouveau",19,"Domaine de la Chambarde");
502             home.create(new Integer JavaDoc(18),"Beauj Nouveau",18,"Domaine de la Croix Ange");
503             home.create(new Integer JavaDoc(19),"Beauj Villages",25,"Agrément Terra Vitis");
504             home.create(new Integer JavaDoc(20),"Brouilly",22,"Paul Champier Producteur");
505             home.create(new Integer JavaDoc(21),"Brouilly 1994",35,"Domaine dit Barron");
506             home.create(new Integer JavaDoc(22),"Brouilly 1996",28,"Médaille de Bronze - Paul Champier Producteur");
507             home.create(new Integer JavaDoc(23),"Brouilly 1997",71,"Médaille Or - Paul Champier Producteur");
508             home.create(new Integer JavaDoc(24),"Côte de Br 94",30,"Paul Champier Producteur");
509             home.create(new Integer JavaDoc(25),"Côte de Br 97",32,"Les Muses - Château de Briante");
510             home.create(new Integer JavaDoc(26),"Morgon 1997",29,"Domaine dit Barron");
511             home.create(new Integer JavaDoc(27),"Régnié",26,"Cercle des Bulliats");
512             home.create(new Integer JavaDoc(28),"Régnié 1998",26,"Cercle des Bulliats");
513             logger.log(BasicLevel.DEBUG, "jt2_appli_item created");
514         } catch (Exception JavaDoc e) {
515             logger.log(BasicLevel.ERROR, "Exception in createTable : " + e);
516             throw new EJBException JavaDoc("Exception in createTable");
517         }
518     }
519
520    private void createStocksTable() {
521         logger.log(BasicLevel.DEBUG, "");
522  
523         try {
524             InitialContext JavaDoc initCtx = new InitialContext JavaDoc();
525             StockHome home =
526                 (StockHome) PortableRemoteObject.narrow(initCtx.lookup("StockHome"), StockHome.class);
527             home.create("0001", new Integer JavaDoc(1),1000);
528             home.create("0001", new Integer JavaDoc(2),1000);
529             home.create("0001", new Integer JavaDoc(3),1000);
530             home.create("0001", new Integer JavaDoc(4),1000);
531             home.create("0001", new Integer JavaDoc(5),1000);
532             home.create("0001", new Integer JavaDoc(6),1000);
533             home.create("0001", new Integer JavaDoc(7),1000);
534             home.create("0001", new Integer JavaDoc(8),1000);
535             home.create("0001", new Integer JavaDoc(9),1000);
536             home.create("0001", new Integer JavaDoc(10),1000);
537             home.create("0001", new Integer JavaDoc(11),1000);
538             home.create("0001", new Integer JavaDoc(12),1000);
539             home.create("0001", new Integer JavaDoc(13),1000);
540             home.create("0001", new Integer JavaDoc(14),1000);
541             home.create("0001", new Integer JavaDoc(15),1000);
542             home.create("0001", new Integer JavaDoc(16),1000);
543             home.create("0001", new Integer JavaDoc(17),1000);
544             home.create("0001", new Integer JavaDoc(18),1000);
545             home.create("0001", new Integer JavaDoc(19),1000);
546             home.create("0001", new Integer JavaDoc(20),1000);
547             home.create("0001", new Integer JavaDoc(21),1000);
548             home.create("0001", new Integer JavaDoc(22),1000);
549             home.create("0001", new Integer JavaDoc(23),1000);
550             home.create("0001", new Integer JavaDoc(24),1000);
551             home.create("0001", new Integer JavaDoc(25),1000);
552             home.create("0001", new Integer JavaDoc(26),1000);
553             home.create("0001", new Integer JavaDoc(27),1000);
554             home.create("0001", new Integer JavaDoc(28),1000);
555             logger.log(BasicLevel.DEBUG, "jt2_appli_stock created");
556         } catch (Exception JavaDoc e) {
557             logger.log(BasicLevel.ERROR, "Exception in createTable : " + e);
558             throw new EJBException JavaDoc("Exception in createTable");
559         }
560     }
561     // ------------------------------------------------------------------
562
// Internal methods
563
// ------------------------------------------------------------------
564

565     private Connection JavaDoc getConnection() throws SQLException JavaDoc,RemoteException JavaDoc{
566         if (dataSource == null) {
567
568             Context JavaDoc initialContext = null;
569             try {
570                 initialContext = new InitialContext JavaDoc();
571             } catch (Exception JavaDoc e) {
572                 throw new RemoteException JavaDoc("Cannot get InitialContext ", e);
573             }
574             String JavaDoc dataSourceName = "java:comp/env/jdbc/OrderEntryClerk";
575             
576             try {
577                 dataSource = (DataSource JavaDoc)initialContext.lookup(dataSourceName);
578             } catch (Exception JavaDoc e) {
579                 throw new RemoteException JavaDoc("cannot lookup " + dataSourceName, e);
580             }
581         }
582         return dataSource.getConnection();
583     }
584
585     // Return a JDBC connection to the pool
586
private void releaseConnection(Connection JavaDoc con) {
587         try{
588             con.close();
589         } catch (Exception JavaDoc ignore) {}
590     }
591
592
593
594
595
596 }
597
598
Popular Tags