Source Code Cross Referenced for BankSessionSLR.java in  » J2EE » JOnAS-4.8.6 » org » objectweb » clusterDemo » 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.clusterDemo 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // BankSessionSLR.java
002:        // Stateless Session bean
003:
004:        package org.objectweb.clusterDemo;
005:
006:        import java.rmi.RemoteException;
007:        import java.sql.Connection;
008:        import java.sql.SQLException;
009:        import java.sql.Statement;
010:        import javax.ejb.CreateException;
011:        import javax.ejb.EJBException;
012:        import javax.ejb.RemoveException;
013:        import javax.ejb.EJBObject;
014:        import javax.ejb.SessionBean;
015:        import javax.ejb.SessionContext;
016:        import javax.naming.Context;
017:        import javax.naming.InitialContext;
018:        import javax.naming.NamingException;
019:        import javax.sql.DataSource;
020:
021:        import java.util.Vector;
022:        import java.util.Calendar;
023:        import java.util.GregorianCalendar;
024:        import java.util.Iterator;
025:
026:        import org.objectweb.jonas.common.Log;
027:        import org.objectweb.util.monolog.api.Logger;
028:        import org.objectweb.util.monolog.api.BasicLevel;
029:
030:        /**
031:         *
032:         */
033:        public class BankSessionSLR implements  SessionBean {
034:
035:            static private Logger logger = null;
036:            SessionContext ejbContext;
037:
038:            InitialContext ic = null;
039:            private DataSource dataSource = null;
040:            Connection conn = null;
041:            Statement stmt;
042:
043:            // ------------------------------------------------------------------
044:            // SessionBean implementation
045:            // ------------------------------------------------------------------
046:
047:            /** 
048:             * Set the associated session context. The container calls this method
049:             * after the instance creation. 
050:             * The enterprise Bean instance should store the reference to the context
051:             * object in an instance variable. 
052:             * This method is called with no transaction context.
053:             *
054:             * @param sessionContext A SessionContext interface for the instance.
055:             * @throws EJBException Thrown by the method to indicate a failure caused by
056:             * a system-level error.
057:             */
058:            public void setSessionContext(SessionContext ctx) {
059:                if (logger == null) {
060:                    logger = Log.getLogger("org.objectweb.jonas_tests");
061:                }
062:                logger.log(BasicLevel.DEBUG, "");
063:                ejbContext = ctx;
064:            }
065:
066:            /**
067:             * A container invokes this method before it ends the life of the session object. 
068:             * This happens as a result of a client's invoking a remove operation, or when a 
069:             *  container decides to terminate the session object after a timeout. 
070:             * This method is called with no transaction context. 
071:             *
072:             * @throws EJBException Thrown by the method to indicate a failure caused by
073:             * a system-level error.
074:             */
075:            public void ejbRemove() {
076:                logger.log(BasicLevel.DEBUG, "");
077:            }
078:
079:            /**
080:             * The Session bean must define 1 or more ejbCreate methods.
081:             *
082:             * @throws CreateException Failure to create a session EJB object.
083:             */
084:            public void ejbCreate() throws CreateException {
085:                logger.log(BasicLevel.DEBUG, "");
086:                try {
087:                    ic = new InitialContext();
088:                } catch (Exception e) {
089:                    e.printStackTrace();
090:                }
091:            }
092:
093:            /**
094:             * A container invokes this method on an instance before the instance
095:             * becomes disassociated with a specific EJB object.
096:             */
097:            public void ejbPassivate() {
098:                logger.log(BasicLevel.DEBUG, "");
099:            }
100:
101:            /**
102:             * A container invokes this method when the instance is taken out of 
103:             * the pool of available instances to become associated with a specific 
104:             * EJB object.
105:             */
106:            public void ejbActivate() {
107:                logger.log(BasicLevel.DEBUG, "");
108:            }
109:
110:            // ------------------------------------------------------------------
111:            // BankSession implementation
112:            // ------------------------------------------------------------------
113:
114:            /**
115:             * credit method
116:             */
117:            public void credit(Integer accountId, String clientName, int value,
118:                    String reason) {
119:                try {
120:                    logger.log(BasicLevel.DEBUG, "");
121:                    BankAccountLocalHome accountHome = (BankAccountLocalHome) ic
122:                            .lookup("java:comp/env/ejb/account");
123:                    BankAccountLocal account = (BankAccountLocal) accountHome
124:                            .findByPrimaryKey(accountId);
125:                    account.putMoney(value);
126:                    BankOperationLocalHome operationHome = (BankOperationLocalHome) ic
127:                            .lookup("java:comp/env/ejb/operation");
128:                    operationHome.create(value, reason + " in bank "
129:                            + getBank(), getDate());
130:                    System.out.println(">>>>>> account " + clientName
131:                            + " credited");
132:                } catch (Exception e) {
133:                    e.printStackTrace();
134:                }
135:
136:            }
137:
138:            /**
139:             * debit method
140:             */
141:            public void debit(Integer accountId, String clientName, int value,
142:                    String reason) {
143:                try {
144:                    logger.log(BasicLevel.DEBUG, "");
145:                    BankAccountLocalHome accountHome = (BankAccountLocalHome) ic
146:                            .lookup("java:comp/env/ejb/account");
147:                    BankAccountLocal account = (BankAccountLocal) accountHome
148:                            .findByPrimaryKey(accountId);
149:                    account.getMoney(value);
150:                    BankOperationLocalHome operationHome = (BankOperationLocalHome) ic
151:                            .lookup("java:comp/env/ejb/operation");
152:                    operationHome.create(value, reason + " in bank "
153:                            + getBank(), getDate());
154:                    System.out.println(">>>>>> account " + clientName
155:                            + " debited");
156:                } catch (Exception e) {
157:                    e.printStackTrace();
158:                }
159:            }
160:
161:            /**
162:             * create new account 
163:             */
164:            public Integer createAccount(String clientName, int value) {
165:                Integer accountId = null;
166:                try {
167:                    logger.log(BasicLevel.DEBUG, "");
168:                    BankAccountLocalHome accountHome = (BankAccountLocalHome) ic
169:                            .lookup("java:comp/env/ejb/account");
170:                    BankAccountLocal account = accountHome.create(value,
171:                            clientName);
172:                    System.out.println(">>>>>> account " + clientName
173:                            + " created");
174:                } catch (Exception e) {
175:                    e.printStackTrace();
176:                }
177:                return accountId;
178:            }
179:
180:            /**
181:             * get Date method for primary key generation
182:             */
183:            public String getDate() {
184:                Calendar c = new GregorianCalendar();
185:                String result = c.get(Calendar.YEAR) + "/"
186:                        + c.get(Calendar.MONTH) + "/"
187:                        + c.get(Calendar.DAY_OF_MONTH) + " ";
188:                int hour = c.get(Calendar.HOUR_OF_DAY);
189:                if (hour < 10) {
190:                    result += "0" + hour + "h";
191:                } else {
192:                    result += "" + hour + "h";
193:                }
194:                int minute = c.get(Calendar.MINUTE);
195:                if (minute < 10) {
196:
197:                    result += "0" + minute + "m";
198:                } else {
199:                    result += "" + minute + "m";
200:                }
201:
202:                int second = c.get(Calendar.SECOND);
203:                if (second < 10) {
204:                    result += "0" + second + "s";
205:                } else {
206:                    result += "" + second + "s";
207:                }
208:                return result + " " + getBank();
209:            }
210:
211:            /**
212:             * get Bank value from env value
213:             */
214:            public String getBank() {
215:                try {
216:                    return (String) ic.lookup("java:comp/env/bankname");
217:                } catch (Exception e) {
218:                    e.printStackTrace();
219:                    return null;
220:                }
221:            }
222:
223:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.