Source Code Cross Referenced for OrderPlacementSLR.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:        // OrderPlacementSLR.java
002:        // Stateless Session bean
003:
004:        package org.objectweb.jonas.stests.appli;
005:
006:        import java.rmi.RemoteException;
007:        import java.util.Enumeration;
008:        import java.util.Vector;
009:
010:        import javax.ejb.CreateException;
011:        import javax.ejb.SessionBean;
012:        import javax.ejb.SessionContext;
013:        import javax.naming.InitialContext;
014:        import javax.rmi.PortableRemoteObject;
015:
016:        import org.objectweb.jonas.common.Log;
017:        import org.objectweb.util.monolog.api.BasicLevel;
018:        import org.objectweb.util.monolog.api.Logger;
019:
020:        /**
021:         *
022:         */
023:        public class OrderPlacementSLR implements  SessionBean {
024:
025:            static private Logger logger = null;
026:            private transient SessionContext ctx;
027:
028:            // ------------------------------------------------------------------
029:            // SessionBean implementation
030:            // ------------------------------------------------------------------
031:
032:            public void setSessionContext(SessionContext ctxt) {
033:                if (logger == null) {
034:                    logger = Log.getLogger("org.objectweb.jonas_tests");
035:                }
036:                logger.log(BasicLevel.DEBUG, "");
037:                ctx = ctxt;
038:            }
039:
040:            public void ejbRemove() {
041:                logger.log(BasicLevel.DEBUG, "");
042:            }
043:
044:            public void ejbCreate() throws CreateException {
045:                logger.log(BasicLevel.DEBUG, "");
046:            }
047:
048:            public void ejbPassivate() {
049:                logger.log(BasicLevel.DEBUG, "");
050:            }
051:
052:            public void ejbActivate() {
053:                logger.log(BasicLevel.DEBUG, "");
054:            }
055:
056:            // ------------------------------------------------------------------
057:            // OrderPlacement implementation
058:            // ------------------------------------------------------------------
059:
060:            // Implementation of business methods defined in remote interface OrderPlacement
061:            /**
062:             * Convenience method to place an order using all Strings for the IDs.  
063:             * Converts district id String to an int and calls the appropriate placeOrder method.
064:             * @param wID			String Warehouse ID
065:             * @param dID			String District ID
066:             * @param cID			Integer Customer ID
067:             * @param orderLines	    Vector of OrderDetail objects.  
068:             * Each OrderDetail object represents one line item on the order.  
069:             * @exception             javax.ejb.RemoteException
070:             */
071:            public float placeOrder(String wID, String dID, Integer cID,
072:                    Vector orderLines) throws RemoteException {
073:
074:                try {
075:                    int districtInt = Integer.parseInt(dID);
076:                    return placeOrder(wID, districtInt, cID, orderLines);
077:                } catch (NumberFormatException nfe) {
078:                    throw new RemoteException("Unable to covert district id ("
079:                            + cID + ") to an int.");
080:                }
081:
082:            }
083:
084:            /**
085:             * Place an order.
086:             * @param wID	       String Warehouse ID
087:             * @param dID	       int District ID
088:             * @param cID	       Integer Customer ID
089:             * @param orderLines       Vector of OrderDetail objects.  
090:             *                         Each OrderDetail object represents one line item on the order. 
091:             * @return                 The order number assigned to this order.
092:             * @exception              javax.ejb.RemoteException
093:             */
094:            public float placeOrder(String wID, int dID, Integer cID,
095:                    Vector orderLines) throws RemoteException {
096:                float oID = 0;
097:                logger.log(BasicLevel.DEBUG, "");
098:                try {
099:                    // The InitialContext will let us retrieve references to the entity beans we need.
100:                    InitialContext initCtx = new InitialContext();
101:
102:                    //Get the Order Number from the District entity bean.
103:                    DistrictHome dHome = (DistrictHome) PortableRemoteObject
104:                            .narrow(initCtx.lookup("DistrictHome"),
105:                                    DistrictHome.class);
106:                    DistrictID districtID = new DistrictID(dID, wID);
107:                    District district = (District) dHome
108:                            .findByPrimaryKey(districtID);
109:                    //'true' tells the District to increment the order id.
110:                    oID = district.getNextOrderId(true);
111:                    logger.log(BasicLevel.DEBUG,
112:                            "(District)dHome.findByPrimaryKey(" + districtID
113:                                    + ");  OK");
114:
115:                    //Update the Stock level for each item in an order line using the Stock entity bean
116:                    StockHome sHome = (StockHome) PortableRemoteObject.narrow(
117:                            initCtx.lookup("StockHome"), StockHome.class);
118:                    Enumeration lines = orderLines.elements();
119:                    float orderTotal = 0;
120:                    while (lines.hasMoreElements()) {
121:                        OrderDetail od = (OrderDetail) lines.nextElement();
122:                        Integer itemID = od.getItemID();
123:                        int itemQty = od.getItemQty();
124:                        //Calculate the order total while we are going through the orders. 
125:                        orderTotal += od.getItemAmount();
126:                        StockID stockID = new StockID(wID, itemID);
127:                        Stock stock = (Stock) sHome.findByPrimaryKey(stockID);
128:                        logger.log(BasicLevel.DEBUG,
129:                                "(Stock)sHome.findByPrimaryKey(" + stockID
130:                                        + ");OK  ");
131:                        stock.decreaseStockQuantity(itemQty);
132:                        logger.log(BasicLevel.DEBUG,
133:                                "stock.decreaseStockQuantity(" + itemQty + ")");
134:                    }
135:
136:                    //Save the Order to the database by creating an Order entity bean
137:                    OrderHome oHome = (OrderHome) PortableRemoteObject.narrow(
138:                            initCtx.lookup("OrderHome"), OrderHome.class);
139:                    Order o = oHome.create(wID, dID, cID, oID, orderLines);
140:                    System.out.println(">>>>>>>> CID= " + o.getCustomerID()
141:                            + " LC= " + o.getOrderLineCount());
142:                    logger.log(BasicLevel.DEBUG, "OrderHome.create(" + wID
143:                            + "," + dID + "," + cID + "," + oID + ","
144:                            + orderLines + ");  OK");
145:                    //Update the Customer records using the Customer entity bean
146:                    CustomerHome cHome = (CustomerHome) PortableRemoteObject
147:                            .narrow(initCtx.lookup("CustomerHome"),
148:                                    CustomerHome.class);
149:
150:                    Customer customer = (Customer) cHome.findByPrimaryKey(cID);
151:                    customer.updateBalance(orderTotal);
152:                    logger.log(BasicLevel.DEBUG,
153:                            "(Customer)cHome.findByPrimaryKey(" + cID
154:                                    + ");  OK");
155:                    //Write the order to the data queue.
156:                    try {
157:                        writeDataQueue(wID, dID, cID, oID);
158:                    } catch (Exception e) {
159:                        System.out.println("WriteDataQueue error: "
160:                                + e.getMessage());
161:                        throw new RemoteException(e.getMessage());
162:                    }
163:
164:                } catch (Exception e) {
165:                    throw new RemoteException(e.getMessage());
166:                }
167:                logger.log(BasicLevel.DEBUG,
168:                        "OrderPacementBean: placeOrder return " + oID);
169:                return oID;
170:            }
171:
172:            private void writeDataQueue(String wID, int dID, Integer cID,
173:                    float oID) throws Exception {
174:            }
175:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.