Source Code Cross Referenced for TxSessionBean.java in  » EJB-Server-JBoss-4.2.1 » testsuite » org » jboss » test » testbean » bean » 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.testbean.bean 
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.testbean.bean;
023:
024:        import java.rmi.*;
025:        import javax.ejb.*;
026:        import javax.naming.InitialContext;
027:        import javax.naming.Context;
028:        import org.jboss.test.testbean.interfaces.TxSession;
029:
030:        public class TxSessionBean implements  SessionBean {
031:            org.apache.log4j.Category log = org.apache.log4j.Category
032:                    .getInstance(getClass());
033:            private SessionContext sessionContext;
034:
035:            public void ejbCreate() throws RemoteException, CreateException {
036:                log.debug("TxSessionBean.ejbCreate() called");
037:            }
038:
039:            public void ejbActivate() throws RemoteException {
040:                log.debug("TxSessionBean.ejbActivate() called");
041:            }
042:
043:            public void ejbPassivate() throws RemoteException {
044:                log.debug("TxSessionBean.ejbPassivate() called");
045:            }
046:
047:            public void ejbRemove() throws RemoteException {
048:                log.debug("TxSessionBean.ejbRemove() called");
049:            }
050:
051:            public void setSessionContext(SessionContext context)
052:                    throws RemoteException {
053:                sessionContext = context;
054:                //Exception e = new Exception("in set Session context");
055:                //log.debug("failed", e);
056:            }
057:
058:            /*
059:             * This method is defined with "Required"
060:             */
061:            public String txRequired() {
062:
063:                log.debug("TxSessionBean.txRequired() called");
064:
065:                try {
066:                    Object tx = getDaTransaction();
067:                    if (tx == null)
068:                        throw new Error("Required sees no transaction");
069:                    else
070:                        return ("required sees a transaction " + tx.hashCode());
071:                } catch (Exception e) {
072:                    log.debug("failed", e);
073:                    return e.getMessage();
074:                }
075:            }
076:
077:            /*
078:             * This method is defined with "Requires_new"
079:             */
080:            public String txRequiresNew() {
081:
082:                log.debug("TxSessionBean.txRequiresNew() called");
083:
084:                try {
085:                    Object tx = getDaTransaction();
086:                    if (tx == null)
087:                        throw new Error("RequiresNew sees no transaction");
088:                    else
089:                        return ("requiresNew sees a transaction " + tx
090:                                .hashCode());
091:                } catch (Exception e) {
092:                    log.debug("failed", e);
093:                    return e.getMessage();
094:                }
095:            }
096:
097:            /*
098:             * testSupports is defined with Supports
099:             */
100:
101:            public String txSupports() {
102:
103:                log.debug("TxSessionBean.txSupports() called");
104:
105:                try {
106:
107:                    Object tx = getDaTransaction();
108:
109:                    if (tx == null)
110:                        return "supports sees no transaction";
111:                    else
112:                        return "supports sees a transaction " + tx.hashCode();
113:                } catch (Exception e) {
114:                    log.debug("failed", e);
115:                    return e.getMessage();
116:                }
117:            }
118:
119:            /*
120:             * This method is defined with "Mandatory"
121:             */
122:            public String txMandatory() {
123:
124:                log.debug("TxSessionBean.txMandatory() called");
125:
126:                try {
127:                    Object tx = getDaTransaction();
128:                    if (tx == null)
129:                        throw new Error("Mandatory sees no transaction");
130:                    else
131:                        return ("mandatory sees a transaction " + tx.hashCode());
132:                } catch (Exception e) {
133:                    log.debug("failed", e);
134:                    return e.getMessage();
135:                }
136:            }
137:
138:            /*
139:             * This method is defined with "Never"
140:             */
141:            public String txNever() {
142:
143:                log.debug("TxSessionBean.txNever() called");
144:
145:                try {
146:                    Object tx = getDaTransaction();
147:                    if (tx == null)
148:                        return "never sees no transaction";
149:                    else
150:                        throw new Error("txNever sees a transaction");
151:                } catch (Exception e) {
152:                    log.debug("failed", e);
153:                    return e.getMessage();
154:                }
155:            }
156:
157:            /*
158:             * This method is defined with "TxNotSupported"
159:             */
160:
161:            public String txNotSupported() {
162:
163:                log.debug("TxSessionBean.txNotSupported() called");
164:
165:                try {
166:                    Object tx = getDaTransaction();
167:                    if (tx == null)
168:                        return "notSupported sees no transaction";
169:                    else
170:                        throw new Error("txNotSupported sees a transaction");
171:                } catch (Exception e) {
172:                    log.debug("failed", e);
173:                    return e.getMessage();
174:                }
175:            }
176:
177:            /*
178:             * This method is defined with "Required" and it passes it to a Supports Tx
179:             */
180:            public String requiredToSupports() throws RemoteException {
181:
182:                log.debug("TxSessionBean.requiredToSupports() called");
183:
184:                String message;
185:                Object tx = getDaTransaction();
186:                if (tx == null)
187:                    throw new Error("Required doesn't see a transaction");
188:                else
189:                    message = "Required sees a transaction " + tx.hashCode()
190:                            + " Supports should see the same ";
191:
192:                message = message
193:                        + ((TxSession) sessionContext.getEJBObject())
194:                                .txSupports();
195:
196:                // And after invocation we should have the same transaction
197:                tx = getDaTransaction();
198:                if (tx == null)
199:                    throw new Error(
200:                            "Required doesn't see a transaction COMING BACK");
201:                else
202:                    return message
203:                            + " on coming back Required sees a transaction "
204:                            + tx.hashCode();
205:
206:            }
207:
208:            /*
209:             * This method is defined with "Required" and it passes it to a NotSupported Tx
210:             */
211:            public String requiredToNotSupported() throws RemoteException {
212:
213:                log.debug("TxSessionBean.requiredToNotSupported() called");
214:
215:                String message;
216:                Object tx = getDaTransaction();
217:                if (tx == null)
218:                    throw new Error("Required doesn't see a transaction");
219:                else
220:                    message = "Required sees a transaction " + tx.hashCode()
221:                            + " NotSupported should see the same ";
222:
223:                message = message
224:                        + ((TxSession) sessionContext.getEJBObject())
225:                                .txNotSupported();
226:
227:                // And after invocation we should have the same transaction
228:                tx = getDaTransaction();
229:                if (tx == null)
230:                    throw new Error(
231:                            "Required doesn't see a transaction COMING BACK");
232:                else
233:                    return message
234:                            + " on coming back Required sees a transaction "
235:                            + tx.hashCode();
236:            }
237:
238:            public String requiredToRequiresNew() throws RemoteException {
239:
240:                log.debug("TxSessionBean.requiredToRequiresNew() called");
241:
242:                String message;
243:                Object tx = getDaTransaction();
244:                if (tx == null)
245:                    throw new Error("Required doesn't see a transaction");
246:                else
247:                    message = "Required sees a transaction " + tx.hashCode()
248:                            + " Requires new should see a new transaction ";
249:
250:                message = message
251:                        + ((TxSession) sessionContext.getEJBObject())
252:                                .txRequiresNew();
253:
254:                // And after invocation we should have the same transaction
255:                tx = getDaTransaction();
256:                if (tx == null)
257:                    throw new Error(
258:                            "Required doesn't see a transaction COMING BACK");
259:                else
260:                    return message
261:                            + " on coming back Required sees a transaction "
262:                            + tx.hashCode();
263:            }
264:
265:            private Object getDaTransaction() {
266:
267:                try {
268:
269:                    return ((javax.transaction.TransactionManager) new InitialContext()
270:                            .lookup("java:/TransactionManager"))
271:                            .getTransaction();
272:                } catch (Exception e) {
273:                    return null;
274:                }
275:            }
276:
277:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.