Source Code Cross Referenced for ContainerTxStatelessBean.java in  » J2EE » openejb3 » org » apache » openejb » test » stateless » 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 » openejb3 » org.apache.openejb.test.stateless 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */package org.apache.openejb.test.stateless;
017:
018:        import java.rmi.RemoteException;
019:        import java.sql.Connection;
020:        import java.sql.PreparedStatement;
021:        import java.sql.ResultSet;
022:
023:        import javax.ejb.CreateException;
024:        import javax.ejb.EJBException;
025:        import javax.ejb.SessionContext;
026:        import javax.naming.InitialContext;
027:        import javax.sql.DataSource;
028:        import javax.transaction.RollbackException;
029:
030:        import org.apache.openejb.test.object.Account;
031:
032:        /**
033:         * 
034:         * @author <a href="mailto:david.blevins@visi.com">David Blevins</a>
035:         */
036:        public class ContainerTxStatelessBean implements  javax.ejb.SessionBean {
037:
038:            private String name;
039:            private SessionContext ejbContext;
040:            private InitialContext jndiContext;
041:            public final String jndiDatabaseEntry = "jdbc/stateless/containerManagedTransaction/database";
042:
043:            //=============================
044:            // Home interface methods
045:            //    
046:
047:            //    
048:            // Home interface methods
049:            //=============================
050:
051:            //=============================
052:            // Remote interface methods
053:            //    
054:
055:            public String txMandatoryMethod(String message) {
056:                return message;
057:            }
058:
059:            public String txNeverMethod(String message) {
060:                return message;
061:            }
062:
063:            public String txNotSupportedMethod(String message) {
064:                return message;
065:            }
066:
067:            public String txRequiredMethod(String message) {
068:                return message;
069:            }
070:
071:            public String txRequiresNewMethod(String message) {
072:                return message;
073:            }
074:
075:            public String txSupportsMethod(String message) {
076:                return message;
077:            }
078:
079:            public void openAccount(Account acct, Boolean rollback)
080:                    throws RollbackException {
081:
082:                try {
083:                    DataSource ds = (DataSource) jndiContext
084:                            .lookup("java:comp/env/database");
085:                    Connection con = ds.getConnection();
086:
087:                    try {
088:                        /*[2] Update the table */
089:                        PreparedStatement stmt = con
090:                                .prepareStatement("insert into Account (SSN, First_name, Last_name, Balance) values (?,?,?,?)");
091:                        try {
092:                            stmt.setString(1, acct.getSsn());
093:                            stmt.setString(2, acct.getFirstName());
094:                            stmt.setString(3, acct.getLastName());
095:                            stmt.setInt(4, acct.getBalance());
096:                            stmt.executeUpdate();
097:                        } finally {
098:                            stmt.close();
099:                        }
100:                    } finally {
101:                        con.close();
102:                    }
103:                } catch (Exception e) {
104:                    //throw new RemoteException("[Bean] "+e.getClass().getName()+" : "+e.getMessage());
105:                }
106:            }
107:
108:            public Account retreiveAccount(String ssn) {
109:                Account acct = new Account();
110:                try {
111:                    DataSource ds = (DataSource) jndiContext
112:                            .lookup("java:comp/env/database");
113:                    Connection con = ds.getConnection();
114:
115:                    try {
116:                        PreparedStatement stmt = con
117:                                .prepareStatement("select * from Account where SSN = ?");
118:                        try {
119:                            stmt.setString(1, ssn);
120:                            ResultSet rs = stmt.executeQuery();
121:                            if (!rs.next())
122:                                return null;
123:
124:                            acct.setSsn(rs.getString(1));
125:                            acct.setFirstName(rs.getString(2));
126:                            acct.setLastName(rs.getString(3));
127:                            acct.setBalance(rs.getInt(4));
128:                        } finally {
129:                            stmt.close();
130:                        }
131:                    } finally {
132:                        con.close();
133:                    }
134:                } catch (Exception e) {
135:                    //throw new RemoteException("[Bean] "+e.getClass().getName()+" : "+e.getMessage());
136:                }
137:                return acct;
138:            }
139:
140:            //    
141:            // Remote interface methods
142:            //=============================
143:
144:            //=================================
145:            // SessionBean interface methods
146:            //    
147:            /**
148:             * 
149:             * @exception javax.ejb.CreateException
150:             */
151:            public void ejbCreate() throws javax.ejb.CreateException {
152:                try {
153:                    jndiContext = new InitialContext();
154:                } catch (Exception e) {
155:                    throw new CreateException(
156:                            "Can not get the initial context: "
157:                                    + e.getMessage());
158:                }
159:            }
160:
161:            /**
162:             * Set the associated session context. The container calls this method
163:             * after the instance creation.
164:             */
165:            public void setSessionContext(SessionContext ctx)
166:                    throws EJBException, RemoteException {
167:                ejbContext = ctx;
168:            }
169:
170:            /**
171:             * A container invokes this method before it ends the life of the session
172:             * object. This happens as a result of a client's invoking a remove
173:             * operation, or when a container decides to terminate the session object
174:             * after a timeout.
175:             */
176:            public void ejbRemove() throws EJBException, RemoteException {
177:            }
178:
179:            /**
180:             * The activate method is called when the instance is activated
181:             * from its "passive" state. The instance should acquire any resource
182:             * that it has released earlier in the ejbPassivate() method.
183:             */
184:            public void ejbActivate() throws EJBException, RemoteException {
185:            }
186:
187:            /**
188:             * The passivate method is called before the instance enters
189:             * the "passive" state. The instance should release any resources that
190:             * it can re-acquire later in the ejbActivate() method.
191:             */
192:            public void ejbPassivate() throws EJBException, RemoteException {
193:            }
194:
195:            //    
196:            // SessionBean interface methods
197:            //==================================
198:            public String remove(String arg) {
199:                return arg;
200:            }
201:
202:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.