Source Code Cross Referenced for OrderEntryClerkSFR.java in  » J2EE » JOnAS-4.8.6 » org » objectweb » jonas » stests » appli » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » JOnAS 4.8.6 » org.objectweb.jonas.stests.appli 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // OrderEntryClerkSFR.java
002:        // Stateful Session Bean
003:
004:        package org.objectweb.jonas.stests.appli;
005:
006:        import java.rmi.RemoteException;
007:        import java.sql.Connection;
008:        import java.sql.ResultSet;
009:        import java.sql.SQLException;
010:        import java.sql.Statement;
011:        import java.util.Vector;
012:
013:        import javax.ejb.CreateException;
014:        import javax.ejb.EJBException;
015:        import javax.ejb.SessionBean;
016:        import javax.ejb.SessionContext;
017:        import javax.naming.Context;
018:        import javax.naming.InitialContext;
019:        import javax.rmi.PortableRemoteObject;
020:        import javax.sql.DataSource;
021:
022:        import org.objectweb.jonas.common.Log;
023:        import org.objectweb.util.monolog.api.BasicLevel;
024:        import org.objectweb.util.monolog.api.Logger;
025:
026:        /**
027:         *
028:         */
029:        public class OrderEntryClerkSFR implements  SessionBean {
030:
031:            static private Logger logger = null;
032:            SessionContext ejbContext;
033:            private transient Connection dbConn = null;
034:            private static String whid = "0001";
035:            private static String did = "1";
036:
037:            // table names
038:            private static String customersTable = null;
039:            private static String stocksTable = null;
040:            private static String itemsTable = null;
041:            private static String ordersTable = null;
042:            private static String orderlinesTable = null;
043:
044:            // Following is the state in this stateful session bean
045:            public Integer custID;
046:            public Vector items;
047:
048:            // (The DataSource can be shared among all instances)
049:            protected static DataSource dataSource = null;
050:
051:            // ------------------------------------------------------------------
052:            // SessionBean implementation
053:            // ------------------------------------------------------------------
054:
055:            public void setSessionContext(SessionContext ctx) {
056:                if (logger == null) {
057:                    logger = Log.getLogger("org.objectweb.jonas_tests");
058:                }
059:                logger.log(BasicLevel.DEBUG, "");
060:                ejbContext = ctx;
061:                if (customersTable == null) {
062:                    try {
063:                        InitialContext initialContext = new InitialContext();
064:                        customersTable = (String) initialContext
065:                                .lookup("java:comp/env/CustomerTableName");
066:                        stocksTable = (String) initialContext
067:                                .lookup("java:comp/env/StockTableName");
068:                        itemsTable = (String) initialContext
069:                                .lookup("java:comp/env/ItemTableName");
070:                        ordersTable = (String) initialContext
071:                                .lookup("java:comp/env/OrderTableName");
072:                        orderlinesTable = (String) initialContext
073:                                .lookup("java:comp/env/OrderlineTableName");
074:                    } catch (Exception e) {
075:                        logger.log(BasicLevel.ERROR, "cannot lookup env-entry "
076:                                + e);
077:                        System.exit(2); // stop all
078:                    }
079:                }
080:            }
081:
082:            public void ejbRemove() {
083:                logger.log(BasicLevel.DEBUG, "");
084:            }
085:
086:            public void ejbCreate() throws CreateException {
087:                logger.log(BasicLevel.DEBUG, "");
088:                items = new Vector();
089:                custID = null;
090:            }
091:
092:            public void ejbPassivate() {
093:                logger.log(BasicLevel.DEBUG, "");
094:            }
095:
096:            public void ejbActivate() {
097:                logger.log(BasicLevel.DEBUG, "");
098:            }
099:
100:            // ------------------------------------------------------------------
101:            // OrderEntryClerk implementation
102:            // ------------------------------------------------------------------
103:
104:            // Set the current customer
105:            public void setCustomer(Integer cid) throws RemoteException {
106:                logger.log(BasicLevel.DEBUG, "customer = " + cid);
107:                if (verifyCustomer(cid)) {
108:                    custID = cid;
109:                } else {
110:                    throw new CpwejbException("Customer id " + cid
111:                            + " not valid");
112:                }
113:            }
114:
115:            // Find all available customers
116:            public Vector findAllCustomers() throws RemoteException {
117:                logger.log(BasicLevel.DEBUG, "");
118:                Vector customerVector = new Vector();
119:
120:                Customer customer = null;
121:                try {
122:                    Connection con = getConnection();
123:                    Statement stmt = con.createStatement();
124:                    ResultSet rs = stmt
125:                            .executeQuery("select cid, cfirst, clast, cinit, caddr1, caddr2, ccity, cstate, czip from "
126:                                    + customersTable);
127:                    while (rs != null && rs.next()) {
128:                        String customerString[] = new String[9];
129:                        customerString[0] = new Integer(rs.getInt("cid"))
130:                                .toString();
131:                        customerString[1] = rs.getString("clast");
132:                        customerString[2] = rs.getString("cfirst");
133:                        customerString[3] = rs.getString("cinit");
134:                        customerString[4] = rs.getString("caddr1");
135:                        customerString[5] = rs.getString("caddr2");
136:                        customerString[6] = rs.getString("ccity");
137:                        customerString[7] = rs.getString("cstate");
138:                        customerString[8] = rs.getString("czip");
139:                        customerVector.addElement(customerString);
140:                    }
141:                    stmt.close();
142:                    releaseConnection(con);
143:                } catch (Exception e) {
144:                    throw new RemoteException(e.getMessage());
145:                }
146:                return customerVector;
147:
148:            }
149:
150:            // Add an item and quantity to the order
151:            public void addOrderLine(Integer iid, int quantity)
152:                    throws RemoteException {
153:                logger.log(BasicLevel.DEBUG, "item = " + iid + " qty = "
154:                        + quantity);
155:                if (custID == null) {
156:                    throw new CpwejbException(
157:                            "OrderEntryClerkBean:  Customer ID must be set first");
158:                }
159:
160:                if (items.size() == 25) {
161:                    throw new CpwejbException(
162:                            "OrderEntryClerkBean:  Maximum of 25 lines per order reached");
163:                }
164:                Item item = null;
165:                try {
166:                    InitialContext initCtx = new InitialContext();
167:                    ItemHome home = (ItemHome) PortableRemoteObject.narrow(
168:                            initCtx.lookup("ItemHome"), ItemHome.class);
169:                    item = home.findByPrimaryKey(iid);
170:                } catch (Exception e) {
171:                    throw new RemoteException(e.getMessage());
172:                }
173:                OrderDetail ol = new OrderDetail(iid, item.getItemPrice()
174:                        * quantity, quantity);
175:                items.addElement(ol);
176:            }
177:
178:            // Reset the bean state ie the current customer and the current order
179:            public void undoAll() throws RemoteException {
180:                logger.log(BasicLevel.DEBUG, "");
181:                // Clear out the state of the session bean at this point
182:                items = new Vector();
183:                custID = null;
184:            }
185:
186:            // Verify an existing customer
187:            public boolean verifyCustomer(Integer cid) throws RemoteException {
188:                logger.log(BasicLevel.DEBUG, "cid = " + cid);
189:                Customer customer = null;
190:                boolean retval = false;
191:                try {
192:                    Connection con = getConnection();
193:                    Statement stmt = con.createStatement();
194:                    ResultSet rs = stmt.executeQuery("select cid from "
195:                            + customersTable + " where cid = '" + cid + "'");
196:                    if (rs != null && rs.next())
197:                        retval = true;
198:                    stmt.close();
199:                    releaseConnection(con);
200:                } catch (Exception e) {
201:                    throw new RemoteException(e.getMessage());
202:                }
203:                return retval;
204:            }
205:
206:            // Place an order
207:            public String placeOrder() throws RemoteException {
208:                logger.log(BasicLevel.DEBUG, "");
209:                String orderNumber = null;
210:                if (custID == null) {
211:                    throw new CpwejbException(
212:                            "OrderEntryClerkBean:  Customer ID must be set before placing an order");
213:                }
214:                if (items.size() == 0) {
215:                    throw new CpwejbException(
216:                            "OrderEntryClerkBean:  No order lines.  Cannot place order.");
217:                }
218:
219:                try {
220:                    InitialContext initCtx = new InitialContext();
221:                    OrderPlacementHome home = (OrderPlacementHome) PortableRemoteObject
222:                            .narrow(initCtx.lookup("OrderPlacementHome"),
223:                                    OrderPlacementHome.class);
224:                    OrderPlacement placement = home.create();
225:                    float number = placement.placeOrder(whid, did, custID,
226:                            items);
227:                    orderNumber = Float.toString(number);
228:                    orderNumber = orderNumber.substring(0,
229:                            orderNumber.length() - 2);
230:                    // Clear out the state of the session bean at this point
231:                    items = new Vector();
232:                    custID = null;
233:                } catch (Exception e) {
234:                    throw new RemoteException(e.getMessage());
235:                }
236:                return orderNumber;
237:            }
238:
239:            // Find a range of items
240:            public Vector findRangeOfItems(Integer lowID, Integer highID)
241:                    throws RemoteException {
242:                logger.log(BasicLevel.DEBUG, "low = " + lowID + " high = "
243:                        + highID);
244:                Vector itemVector = new Vector();
245:
246:                Item item = null;
247:                try {
248:                    Connection con = getConnection();
249:                    Statement stmt = con.createStatement();
250:                    ResultSet rs = stmt
251:                            .executeQuery("select iid, iname, iprice, idata, stqty from "
252:                                    + itemsTable
253:                                    + " , "
254:                                    + stocksTable
255:                                    + " where iid = stiid and iid >= '"
256:                                    + lowID
257:                                    + "' and iid <= '" + highID + "'");
258:                    while (rs != null && rs.next()) {
259:                        String itemString[] = new String[5];
260:                        itemString[0] = rs.getString("iid");
261:                        itemString[1] = rs.getString("iname");
262:                        itemString[2] = "$"
263:                                + Float.toString(rs.getFloat("iprice"));
264:                        itemString[3] = Integer.toString(rs.getInt("stqty"));
265:                        itemString[4] = rs.getString("idata");
266:                        itemVector.addElement(itemString);
267:                    }
268:                    stmt.close();
269:                    releaseConnection(con);
270:                } catch (Exception e) {
271:                    throw new RemoteException(e.getMessage());
272:                }
273:                return itemVector;
274:            }
275:
276:            public Vector findAllItems() throws RemoteException {
277:                logger.log(BasicLevel.DEBUG, "");
278:                Vector itemVector = new Vector();
279:                Item item = null;
280:                try {
281:                    Connection con = getConnection();
282:                    Statement stmt = con.createStatement();
283:
284:                    ResultSet rs = stmt
285:                            .executeQuery("select ProdId, Name, Price, Descrip, stqty from "
286:                                    + customersTable
287:                                    + " , "
288:                                    + stocksTable
289:                                    + " where ProdId = stiid");
290:
291:                    logger
292:                            .log(
293:                                    BasicLevel.DEBUG,
294:                                    "select ProdId, Name, Price, Descrip, stqty from itemtable,stocktable where ProdId = stiid");
295:                    while (rs != null && rs.next()) {
296:                        String itemString[] = new String[5];
297:                        itemString[0] = rs.getString("ProdId");
298:                        itemString[1] = rs.getString("Name");
299:                        String price = "$"
300:                                + Float.toString(rs.getFloat("Price"));
301:                        // make sure the price ends with .00 for even dollar amounts
302:                        if (price.endsWith(".0")) {
303:                            price += "0";
304:                        }
305:                        itemString[2] = price;
306:                        itemString[3] = Integer.toString(rs.getInt("stqty"));
307:                        itemString[4] = rs.getString("Descrip");
308:                        itemVector.addElement(itemString);
309:                    }
310:                    stmt.close();
311:                    releaseConnection(con);
312:                } catch (Exception e) {
313:                    throw new RemoteException(e.getMessage());
314:                }
315:                return itemVector;
316:            }
317:
318:            public String[] getCustomerForOrder(String wid, int did, int oid)
319:                    throws RemoteException, CpwejbException {
320:                logger.log(BasicLevel.DEBUG, "oid = " + oid);
321:                Integer customerID = null;
322:                String custInfo[] = new String[4];
323:                try {
324:                    Connection con = getConnection();
325:                    Statement stmt = con.createStatement();
326:                    String stmtString = "select ocid from " + ordersTable
327:                            + " where owid = '" + wid + "' and odid = " + did
328:                            + " and oid = " + oid;
329:                    ResultSet rs = stmt.executeQuery(stmtString);
330:                    if (rs != null && rs.next()) {
331:                        customerID = new Integer(rs.getInt("ocid"));
332:                        custInfo[0] = custID.toString();
333:                        if (rs.next()) {
334:                            // There were multiple orders with the same key -- severe error
335:                            throw new RemoteException("Duplicate Key Error: "
336:                                    + wid + "/" + did + "/" + oid);
337:                        }
338:                        InitialContext initCtx = new InitialContext();
339:                        CustomerHome cHome = (CustomerHome) PortableRemoteObject
340:                                .narrow(initCtx.lookup("CustomerHome"),
341:                                        CustomerHome.class);
342:                        Customer customer = (Customer) cHome
343:                                .findByPrimaryKey(customerID);
344:                        custInfo[1] = customer.getFirstName();
345:                        custInfo[2] = customer.getMiddleInitials();
346:                        custInfo[3] = customer.getLastName();
347:                    } else {
348:                        // order does not exist
349:                        throw new CpwejbException(
350:                                "Order does not exists for warehouse " + wid
351:                                        + " district " + did + " order " + oid);
352:                    }
353:                    stmt.close();
354:                    releaseConnection(con);
355:                } catch (Exception e) {
356:                    throw new RemoteException(e.getMessage());
357:                }
358:                return custInfo;
359:            }
360:
361:            public Vector getItemsForOrder(String wid, int did, int oid)
362:                    throws RemoteException, CpwejbException {
363:                logger.log(BasicLevel.DEBUG, "oid = " + oid);
364:                Vector itemVector = new Vector();
365:                try {
366:                    Connection con = getConnection();
367:                    Statement stmt = con.createStatement();
368:                    String stmtString = "select oliid, olqty, olamnt from "
369:                            + orderlinesTable + " where olwid = '" + wid
370:                            + "' and oldid = " + did + " and oloid = " + oid;
371:                    ResultSet rs = stmt.executeQuery(stmtString);
372:                    InitialContext initCtx = new InitialContext();
373:                    ItemHome iHome = (ItemHome) PortableRemoteObject.narrow(
374:                            initCtx.lookup("ItemHome"), ItemHome.class);
375:                    while (rs != null && rs.next()) {
376:                        String itemInfo[] = new String[4];
377:                        Integer ItemID = new Integer(rs.getInt("oliid"));
378:                        itemInfo[0] = ItemID.toString();
379:                        itemInfo[2] = Integer.toString(rs.getInt("olqty"));
380:                        itemInfo[3] = Float.toString(rs.getFloat("olamnt"));
381:                        Item item = (Item) iHome.findByPrimaryKey(ItemID);
382:                        itemInfo[1] = item.getItemName();
383:                        itemVector.addElement(itemInfo);
384:                    }
385:                    stmt.close();
386:                    releaseConnection(con);
387:                } catch (Exception e) {
388:                    throw new RemoteException(e.getMessage());
389:                }
390:                return itemVector;
391:            }
392:
393:            public void createAllTables() {
394:                logger.log(BasicLevel.DEBUG, "");
395:                createCustomersTable();
396:                createItemsTable();
397:                createStocksTable();
398:                createDistrictsTable();
399:                createOtherTables();
400:
401:            }
402:
403:            public void createOtherTables() {
404:                createOrdersTable();
405:                createOrderlinesTable();
406:            }
407:
408:            public void createOrdersTable() {
409:                logger.log(BasicLevel.DEBUG, "");
410:                // Drop table
411:                Connection conn = null;
412:                Statement stmt = null;
413:                try {
414:                    conn = getConnection();
415:                    stmt = conn.createStatement();
416:                    stmt.execute("drop table jt2_appli_order");
417:                } catch (Exception e) {
418:                    // The first time, table will not exist.
419:                    logger
420:                            .log(BasicLevel.INFO, "Exception in dropTable : "
421:                                    + e);
422:                }
423:
424:                // Create table.
425:                try {
426:                    stmt
427:                            .execute("create table jt2_appli_order(owid varchar(4),odid integer,ocid integer,ooid float,olines integer,primary key (owid,odid,ooid))");
428:                    stmt.close();
429:                    conn.close();
430:                    logger.log(BasicLevel.DEBUG, "jt2_appli_order created");
431:                } catch (SQLException e) {
432:                    logger.log(BasicLevel.ERROR,
433:                            "Exception in createOrderTable : " + e);
434:                    throw new EJBException("Exception in createOrderTable");
435:                }
436:            }
437:
438:            public void createOrderlinesTable() {
439:                logger.log(BasicLevel.DEBUG, "");
440:                // Drop table
441:                Connection conn = null;
442:                Statement stmt = null;
443:                try {
444:                    conn = getConnection();
445:                    stmt = conn.createStatement();
446:                    stmt.execute("drop table jt2_appli_orderline");
447:                } catch (Exception e) {
448:                    // The first time, table will not exist.
449:                    logger
450:                            .log(BasicLevel.INFO, "Exception in dropTable : "
451:                                    + e);
452:                }
453:
454:                // Create table.
455:                try {
456:                    stmt
457:                            .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))");
458:                    stmt.close();
459:                    conn.close();
460:                    logger.log(BasicLevel.DEBUG, "jt2_appli_orderline created");
461:                } catch (SQLException e) {
462:                    logger.log(BasicLevel.ERROR,
463:                            "Exception in createOrderlinesTable : " + e);
464:                    throw new EJBException("Exception in createOrderlinesTable");
465:                }
466:            }
467:
468:            private void createDistrictsTable() {
469:                logger.log(BasicLevel.DEBUG, "");
470:
471:                try {
472:                    InitialContext initCtx = new InitialContext();
473:                    DistrictHome home = (DistrictHome) PortableRemoteObject
474:                            .narrow(initCtx.lookup("DistrictHome"),
475:                                    DistrictHome.class);
476:                    home.create(1, "0001", "Belgique", 0);
477:                    home.create(2, "0001", "Espagne", 0);
478:                    home.create(3, "0001", "Finlande", 0);
479:                    home.create(4, "0001", "Irlande", 0);
480:                    logger.log(BasicLevel.DEBUG, "jt2_appli_district created");
481:                } catch (Exception e) {
482:                    logger.log(BasicLevel.ERROR, "Exception in createTable : "
483:                            + e);
484:                    throw new EJBException("Exception in createTable");
485:                }
486:            }
487:
488:            private void createCustomersTable() {
489:                logger.log(BasicLevel.DEBUG, "");
490:
491:                try {
492:                    InitialContext initCtx = new InitialContext();
493:                    CustomerHome home = (CustomerHome) PortableRemoteObject
494:                            .narrow(initCtx.lookup("CustomerHome"),
495:                                    CustomerHome.class);
496:                    home.create(new Integer(1), "Paul", "Desgranges", "PD",
497:                            "1 rue du bourg", "", "Nice", "06", "", "04050607",
498:                            1000);
499:                    home.create(new Integer(2), "François", "Exertier", "FE",
500:                            "16 avenue J. jaures", "", "Grenoble", "38", "",
501:                            "0476276115", 1000);
502:                    home.create(new Integer(3), "Florent", "Benoit", "FB",
503:                            "20 place de la gare", "", "Lyon", "69", "",
504:                            "04286745", 1000);
505:                    home.create(new Integer(4), "Gérard", "Vandome", "GV",
506:                            "13 rue A. Einstein", "", "Marseille", "13", "",
507:                            "04122436", 1000);
508:                    home.create(new Integer(5), "Philippe", "Coq", "PC",
509:                            "3 rue du Village", "", "Nice", "06", "",
510:                            "0405060713", 1000);
511:                    home.create(new Integer(6), "Philippe", "Durieux", "PD",
512:                            "6 avenue J. Valles", "", "Grenoble", "38", "",
513:                            "0476276115", 1000);
514:                    home.create(new Integer(7), "Hélène", "Joanin", "HJ",
515:                            "30 place du Tramway", "", "Lyon", "69", "",
516:                            "0428674513", 1000);
517:                    home.create(new Integer(8), "Adriana", "Danes", "AD",
518:                            "23 rue Galilé", "", "Marseille", "13", "",
519:                            "0412243613", 1000);
520:                    home.create(new Integer(9), "Jacques", "Cayuela", "JC",
521:                            "29 rue de la Clef", "", "Nice", "06", "",
522:                            "0405060717", 1000);
523:
524:                    home.create(new Integer(10), "Eric", "Hardesty", "EC",
525:                            "41 rue de la gare", "", "Nancy", "54", "",
526:                            "0302060627", 1000);
527:                    home.create(new Integer(11), "Goulven", "Lejeune", "GL",
528:                            "37 rue du Hameau", "", "Nice", "06", "",
529:                            "0405060717", 1000);
530:                    home.create(new Integer(12), "Christophe", "Loridan", "CL",
531:                            "26 avenue Gambetta", "", "Grenoble", "38", "",
532:                            "0476276117", 1000);
533:                    home.create(new Integer(13), "Jerome", "Camilleri", "JC",
534:                            "30 place des VFD", "", "Lyon", "69", "",
535:                            "0428674519", 1000);
536:                    home.create(new Integer(14), "Guillaume", "Sauthier", "GS",
537:                            "37 rue B.Giordano", "", "Marseille", "13", "",
538:                            "0412243196", 1000);
539:                    logger.log(BasicLevel.DEBUG, "jt2_appli_customer created");
540:                } catch (Exception e) {
541:                    logger.log(BasicLevel.ERROR, "Exception in createTable : "
542:                            + e);
543:                    throw new EJBException("Exception in createTable");
544:                }
545:            }
546:
547:            private void createItemsTable() {
548:                logger.log(BasicLevel.DEBUG, "");
549:
550:                try {
551:                    InitialContext initCtx = new InitialContext();
552:                    ItemHome home = (ItemHome) PortableRemoteObject.narrow(
553:                            initCtx.lookup("ItemHome"), ItemHome.class);
554:                    home.create(new Integer(1), "Beaujolais 95", 19,
555:                            "Grumage - Domaine des Averlys");
556:                    home.create(new Integer(2), "Beaujolais 95", 20,
557:                            "Domaine des Averlys");
558:                    home.create(new Integer(3), "Beaujolais 96", 18,
559:                            "Cuvée Antique - Domaine de Rochecorbière");
560:                    home.create(new Integer(4), "Beaujolais 96", 19,
561:                            "Vin de garde - Domaine des Averlys");
562:                    home.create(new Integer(5), "Beaujolais 96", 22,
563:                            "Domaine des Fortières");
564:                    home.create(new Integer(6), "Beaujolais 97", 28,
565:                            "Médaille Or - Paul Champier Producteur");
566:                    home.create(new Integer(7), "Beaujolais 97", 21,
567:                            "Domaine du Berret");
568:                    home.create(new Integer(8), "Beaujolais 98", 21,
569:                            "Domaine des Fortières");
570:                    home.create(new Integer(9), "Beauj Rosé 96", 19,
571:                            "Domaine de Rochecorbière");
572:                    home.create(new Integer(10), "Beauj Rosé 96", 19,
573:                            "Domaine de la Croix Ange");
574:                    home.create(new Integer(11), "Beauj Rosé 97", 21,
575:                            "Domaine de la Chambarde");
576:                    home.create(new Integer(12), "Beauj Rosé 97", 18,
577:                            "Domaine des Averlys");
578:                    home.create(new Integer(13), "Beauj Blanc 96", 24,
579:                            "Domaine de Rochcorbière");
580:                    home.create(new Integer(14), "Beauj Blanc 96", 21,
581:                            "Domaine du Berret");
582:                    home.create(new Integer(15), "Beauj Nouveau", 20,
583:                            "Domaine du Berret");
584:                    home.create(new Integer(16), "Beauj Nouveau", 21,
585:                            "Domaine des Fortières");
586:                    home.create(new Integer(17), "Beauj Nouveau", 19,
587:                            "Domaine de la Chambarde");
588:                    home.create(new Integer(18), "Beauj Nouveau", 18,
589:                            "Domaine de la Croix Ange");
590:                    home.create(new Integer(19), "Beauj Villages", 25,
591:                            "Agrément Terra Vitis");
592:                    home.create(new Integer(20), "Brouilly", 22,
593:                            "Paul Champier Producteur");
594:                    home.create(new Integer(21), "Brouilly 1994", 35,
595:                            "Domaine dit Barron");
596:                    home.create(new Integer(22), "Brouilly 1996", 28,
597:                            "Médaille de Bronze - Paul Champier Producteur");
598:                    home.create(new Integer(23), "Brouilly 1997", 71,
599:                            "Médaille Or - Paul Champier Producteur");
600:                    home.create(new Integer(24), "Côte de Br 94", 30,
601:                            "Paul Champier Producteur");
602:                    home.create(new Integer(25), "Côte de Br 97", 32,
603:                            "Les Muses - Château de Briante");
604:                    home.create(new Integer(26), "Morgon 1997", 29,
605:                            "Domaine dit Barron");
606:                    home.create(new Integer(27), "Régnié", 26,
607:                            "Cercle des Bulliats");
608:                    home.create(new Integer(28), "Régnié 1998", 26,
609:                            "Cercle des Bulliats");
610:                    logger.log(BasicLevel.DEBUG, "jt2_appli_item created");
611:                } catch (Exception e) {
612:                    logger.log(BasicLevel.ERROR, "Exception in createTable : "
613:                            + e);
614:                    throw new EJBException("Exception in createTable");
615:                }
616:            }
617:
618:            private void createStocksTable() {
619:                logger.log(BasicLevel.DEBUG, "");
620:
621:                try {
622:                    InitialContext initCtx = new InitialContext();
623:                    StockHome home = (StockHome) PortableRemoteObject.narrow(
624:                            initCtx.lookup("StockHome"), StockHome.class);
625:                    home.create("0001", new Integer(1), 1000);
626:                    home.create("0001", new Integer(2), 1000);
627:                    home.create("0001", new Integer(3), 1000);
628:                    home.create("0001", new Integer(4), 1000);
629:                    home.create("0001", new Integer(5), 1000);
630:                    home.create("0001", new Integer(6), 1000);
631:                    home.create("0001", new Integer(7), 1000);
632:                    home.create("0001", new Integer(8), 1000);
633:                    home.create("0001", new Integer(9), 1000);
634:                    home.create("0001", new Integer(10), 1000);
635:                    home.create("0001", new Integer(11), 1000);
636:                    home.create("0001", new Integer(12), 1000);
637:                    home.create("0001", new Integer(13), 1000);
638:                    home.create("0001", new Integer(14), 1000);
639:                    home.create("0001", new Integer(15), 1000);
640:                    home.create("0001", new Integer(16), 1000);
641:                    home.create("0001", new Integer(17), 1000);
642:                    home.create("0001", new Integer(18), 1000);
643:                    home.create("0001", new Integer(19), 1000);
644:                    home.create("0001", new Integer(20), 1000);
645:                    home.create("0001", new Integer(21), 1000);
646:                    home.create("0001", new Integer(22), 1000);
647:                    home.create("0001", new Integer(23), 1000);
648:                    home.create("0001", new Integer(24), 1000);
649:                    home.create("0001", new Integer(25), 1000);
650:                    home.create("0001", new Integer(26), 1000);
651:                    home.create("0001", new Integer(27), 1000);
652:                    home.create("0001", new Integer(28), 1000);
653:                    logger.log(BasicLevel.DEBUG, "jt2_appli_stock created");
654:                } catch (Exception e) {
655:                    logger.log(BasicLevel.ERROR, "Exception in createTable : "
656:                            + e);
657:                    throw new EJBException("Exception in createTable");
658:                }
659:            }
660:
661:            // ------------------------------------------------------------------
662:            // Internal methods
663:            // ------------------------------------------------------------------
664:
665:            private Connection getConnection() throws SQLException,
666:                    RemoteException {
667:                if (dataSource == null) {
668:
669:                    Context initialContext = null;
670:                    try {
671:                        initialContext = new InitialContext();
672:                    } catch (Exception e) {
673:                        throw new RemoteException("Cannot get InitialContext ",
674:                                e);
675:                    }
676:                    String dataSourceName = "java:comp/env/jdbc/OrderEntryClerk";
677:
678:                    try {
679:                        dataSource = (DataSource) initialContext
680:                                .lookup(dataSourceName);
681:                    } catch (Exception e) {
682:                        throw new RemoteException("cannot lookup "
683:                                + dataSourceName, e);
684:                    }
685:                }
686:                return dataSource.getConnection();
687:            }
688:
689:            // Return a JDBC connection to the pool
690:            private void releaseConnection(Connection con) {
691:                try {
692:                    con.close();
693:                } catch (Exception ignore) {
694:                }
695:            }
696:
697:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.