Source Code Cross Referenced for TellerBean.java in  » EJB-Server-JBoss-4.2.1 » testsuite » org » jboss » test » jca » bank » ejb » 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 » EJB Server JBoss 4.2.1 » testsuite » org.jboss.test.jca.bank.ejb 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * JBoss, Home of Professional Open Source.
003:         * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004:         * as indicated by the @author tags. See the copyright.txt file in the
005:         * distribution for a full listing of individual contributors.
006:         *
007:         * This is free software; you can redistribute it and/or modify it
008:         * under the terms of the GNU Lesser General Public License as
009:         * published by the Free Software Foundation; either version 2.1 of
010:         * the License, or (at your option) any later version.
011:         *
012:         * This software is distributed in the hope that it will be useful,
013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015:         * Lesser General Public License for more details.
016:         *
017:         * You should have received a copy of the GNU Lesser General Public
018:         * License along with this software; if not, write to the Free
019:         * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020:         * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021:         */
022:        package org.jboss.test.jca.bank.ejb;
023:
024:        import java.sql.Connection;
025:        import java.sql.SQLException;
026:        import java.sql.Statement;
027:        import java.util.*;
028:        import javax.ejb.EJBException;
029:        import javax.ejb.SessionBean;
030:        import javax.ejb.SessionContext;
031:        import javax.naming.InitialContext;
032:        import javax.sql.DataSource;
033:        import org.apache.log4j.Category;
034:        import org.jboss.test.jca.bank.interfaces.Account;
035:        import org.jboss.test.jca.bank.interfaces.AccountHome;
036:        import org.jboss.test.jca.bank.interfaces.AccountLocal;
037:        import org.jboss.test.jca.bank.interfaces.AccountLocalHome;
038:
039:        /**
040:         * Describe class <code>TellerBean</code> here.
041:         * The equals and hashCode methods have been overridden to test bug 595738,
042:         * a problem  with CachedConnectionManager if it directly puts objects in a hashmap.
043:         *
044:         * @author <a href="mailto:d_jencks@users.sourceforge.net">David Jencks</a>
045:         * @version 1.0
046:         *
047:         * @ejb:bean   name="Teller"
048:         *             jndi-name="Teller"
049:         *             local-jndi-name="LocalTellerBean"
050:         *             view-type="both"
051:         *             type="Stateless"
052:         */
053:        public class TellerBean implements  SessionBean {
054:            static int invocations;
055:
056:            private Connection c;
057:
058:            /**
059:             * Describe <code>setUp</code> method here.
060:             *
061:             * @exception EJBException if an error occurs
062:             * @ejb:interface-method
063:             */
064:            public void setUp() {
065:                try {
066:                    tearDown();
067:                } catch (Exception e) {
068:                    //ignore
069:                } // end of try-catch
070:
071:                try {
072:                    Statement s = getConnection().createStatement();
073:                    s
074:                            .execute("CREATE TABLE CCBMPCUSTOMER (ID INTEGER NOT NULL PRIMARY KEY, NAME VARCHAR(64))");
075:                    s
076:                            .execute("CREATE TABLE CCBMPACCOUNT (ID INTEGER NOT NULL PRIMARY KEY, BALANCE INTEGER NOT NULL, CUSTOMERID INTEGER)");
077:                    s.close();
078:
079:                } catch (Exception e) {
080:                    throw new EJBException(e);
081:                } // end of try-catch
082:
083:            }
084:
085:            /**
086:             * Describe <code>tearDown</code> method here.
087:             *
088:             * @exception EJBException if an error occurs
089:             * @ejb:interface-method
090:             */
091:            public void tearDown() {
092:                try {
093:                    Statement s = getConnection().createStatement();
094:                    s.execute("DROP TABLE CCBMPCUSTOMER");
095:                    s.execute("DROP TABLE CCBMPACCOUNT");
096:                    s.close();
097:
098:                } catch (Exception e) {
099:                    throw new EJBException(e);
100:                } // end of try-catch
101:
102:            }
103:
104:            /**
105:             * This <code>equals</code> method tests whether the CachedConnectionManager deals
106:             * properly with ejbs that override equals and hashCode.  See bug 595738
107:             *
108:             * @param other an <code>Object</code> value
109:             * @return a <code>boolean</code> value
110:             */
111:            public boolean equals(Object other) {
112:                return other.getClass() == this .getClass();
113:            }
114:
115:            public int hashCode() {
116:                return 1;
117:            }
118:
119:            /**
120:             * Describe <code>transfer</code> method here.
121:             *
122:             * @param from an <code>Account</code> value
123:             * @param to an <code>Account</code> value
124:             * @param amount a <code>float</code> value
125:             * @exception EJBException if an error occurs
126:             * @ejb:interface-method
127:             */
128:            public void transfer(Account from, Account to, int amount) {
129:                try {
130:                    Category.getInstance(TellerBean.class.getName()).info(
131:                            "Invocation #" + invocations++);
132:                    from.withdraw(amount);
133:                    to.deposit(amount);
134:                } catch (Exception e) {
135:                    throw new EJBException("Could not transfer " + amount
136:                            + " from " + from + " to " + to, e);
137:                }
138:            }
139:
140:            /**
141:             * Describe <code>createAccount</code> method here.
142:             *
143:             * @param id a <code>Integer</code> value, id of account
144:             * @return an <code>Account</code> value
145:             * @exception EJBException if an error occurs
146:             * @ejb:interface-method
147:             */
148:            public Account createAccount(Integer id) {
149:                try {
150:                    AccountHome home = (AccountHome) new InitialContext()
151:                            .lookup("Account");
152:                    Account acct = home.create(id, 0, null);
153:
154:                    return acct;
155:                } catch (Exception e) {
156:                    throw new EJBException("Could not create account", e);
157:                }
158:            }
159:
160:            /**
161:             * Describe <code>getAccountBalance</code> method here.
162:             *
163:             * @param id a <code>integer</code> value, id of account
164:             * @return an <code>int</code> value, balbance of account
165:             * @exception EJBException if an error occurs
166:             * @ejb:interface-method
167:             */
168:            public int getAccountBalance(Integer id) {
169:                try {
170:                    AccountLocalHome home = (AccountLocalHome) new InitialContext()
171:                            .lookup("AccountLocal");
172:                    AccountLocal a = home.findByPrimaryKey(id);
173:                    return a.getBalance();
174:                } catch (Exception e) {
175:                    Category.getInstance(getClass().getName()).info(
176:                            "getAccountBalance failed", e);
177:                    throw new EJBException(
178:                            "Could not get account for id " + id, e);
179:                }
180:            }
181:
182:            /**
183:             * Describe <code>transferTest</code> method here.
184:             *
185:             * @param from an <code>AccountLocal</code> value
186:             * @param to an <code>AccountLocal</code> value
187:             * @param amount a <code>float</code> value
188:             * @param iter an <code>int</code> value
189:             * @exception java.rmi.RemoteException if an error occurs
190:             * @exception EJBException if an error occurs
191:             * @ejb:interface-method
192:             */
193:            public void transferTest(AccountLocal from, AccountLocal to,
194:                    int amount, int iter) {
195:                for (int i = 0; i < iter; i++) {
196:                    from.withdraw(amount);
197:                    to.deposit(amount);
198:                }
199:            }
200:
201:            public void ejbCreate() {
202:            }
203:
204:            public void ejbActivate() {
205:            }
206:
207:            public void ejbPassivate() {
208:                if (c != null) {
209:                    try {
210:                        c.close();
211:                    } catch (SQLException e) {
212:                        Category.getInstance(getClass().getName()).info(
213:                                "SQLException closing c: " + e);
214:                    } // end of try-catch
215:                    c = null;
216:                } // end of if ()
217:            }
218:
219:            public void ejbRemove() {
220:            }
221:
222:            public void setSessionContext(SessionContext ctx) {
223:            }
224:
225:            public void unsetSessionContext() {
226:            }
227:
228:            private Connection getConnection() throws Exception {
229:                if (c == null) {
230:                    DataSource ds = (DataSource) new InitialContext()
231:                            .lookup("java:/DefaultDS");
232:                    c = ds.getConnection();
233:
234:                } // end of if ()
235:
236:                return c;
237:            }
238:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.