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


001:        // TransactedCASLR.java
002:        // Stateful Session bean
003:
004:        package org.objectweb.jonas.jtests.beans.jca15;
005:
006:        import java.rmi.RemoteException;
007:        import javax.ejb.CreateException;
008:        import javax.ejb.EJBException;
009:        import javax.ejb.RemoveException;
010:        import javax.ejb.EJBObject;
011:        import javax.ejb.SessionBean;
012:        import javax.ejb.SessionContext;
013:        import javax.naming.Context;
014:        import javax.naming.InitialContext;
015:        import javax.naming.NamingException;
016:        import javax.sql.DataSource;
017:        import ersatz.resourceadapter.*;
018:        import javax.resource.cci.Connection;
019:        import javax.resource.cci.LocalTransaction;
020:        import javax.resource.spi.ManagedConnection;
021:        import javax.resource.spi.ConnectionEvent;
022:        import javax.resource.spi.ConnectionManager;
023:        import javax.transaction.xa.XAResource;
024:        import javax.transaction.xa.Xid;
025:        import javax.transaction.SystemException;
026:        import javax.transaction.NotSupportedException;
027:        import javax.transaction.RollbackException;
028:        import javax.transaction.HeuristicRollbackException;
029:        import javax.transaction.HeuristicMixedException;
030:
031:        /**
032:         *
033:         */
034:        public class TransactedCASLR implements  SessionBean {
035:
036:            private SessionContext ejbContext;
037:            private ManagedConnectionImpl mcf = null; //Managed Connection Factory
038:            private ConnectionSpecImpl csp = null; //ConnectionSpec
039:            private ConnectionFactoryImpl cccf = null; //Common Client Connection Factory
040:            private ConnectionImpl conn = null;
041:            private InitialContext ic = null;
042:            private String cName = "TransactedCASLR";
043:            public boolean NoTransaction = false;
044:            public boolean LoTransaction = false;
045:            public boolean XATransaction = false;
046:            final public int CLOSE_HANDLE = 0;
047:            final public int CLOSE_PHYSICAL = 1;
048:            String xidTest;
049:
050:            // ------------------------------------------------------------------
051:            // SessionBean implementation
052:            // ------------------------------------------------------------------
053:
054:            public void setSessionContext(SessionContext ctx) {
055:                Utility.log(cName + ".setSessionContext");
056:                ejbContext = ctx;
057:            }
058:
059:            public void ejbRemove() {
060:                Utility.log("");
061:            }
062:
063:            public void ejbCreate() throws CreateException {
064:                Utility.log("");
065:            }
066:
067:            public void ejbPassivate() {
068:                Utility.log("");
069:            }
070:
071:            public void ejbActivate() {
072:                Utility.log("");
073:            }
074:
075:            /**
076:             * closeUp
077:             */
078:            public void closeUp(int closeType) {
079:                Utility.log(cName + ".closeUp (enter) closeType=" + closeType);
080:                try {
081:                    if (closeType == CLOSE_PHYSICAL) {
082:                        // The CONNECTION_ERROR_OCCURRED indicates that the associated 
083:                        // ManagedConnectionImpl instance is now invalid and unusable.
084:                        conn.close(ConnectionEvent.CONNECTION_ERROR_OCCURRED);
085:                        Utility
086:                                .log(cName
087:                                        + ".closeUp (exit) : closed physical connection closeType="
088:                                        + closeType
089:                                        + " ConnectionEvent.CONNECTION_ERROR_OCCURRED="
090:                                        + ConnectionEvent.CONNECTION_ERROR_OCCURRED);
091:                    } else {
092:                        // The CONNECTION_CLOSED indicates that connection handle
093:                        // is closed, but physical connection still exists
094:                        conn.close();
095:                        Utility
096:                                .log(cName
097:                                        + ".closeUp (exit) : closed connection closeType="
098:                                        + closeType);
099:                    }
100:                } catch (Exception e) {
101:                    Utility.log(cName + ".closeUp (exit) error: close "
102:                            + "handle/physical connection failed closeType="
103:                            + closeType);
104:                }
105:            }
106:
107:            // ------------------------------------------------------------------
108:            // transacted implementation
109:            // ------------------------------------------------------------------
110:
111:            /**
112:             * method1
113:             */
114:            public void method1(String rar_jndi_name, String testName)
115:                    throws Exception {
116:                Utility.log("============================ " + testName);
117:
118:                if ("eis/ErsatzXATransaction".equals(rar_jndi_name))
119:                    XATransaction = true;
120:                else if ("eis/ErsatzLoTransaction".equals(rar_jndi_name))
121:                    LoTransaction = true;
122:                else
123:                    NoTransaction = true;
124:
125:                try {
126:                    ic = new InitialContext();
127:                } catch (Exception e1) {
128:                    Utility
129:                            .log(cName
130:                                    + ".method1 error: InitialContext failed");
131:                    throw e1;
132:                }
133:                try {
134:                    cccf = (ConnectionFactoryImpl) ic.lookup(rar_jndi_name);
135:                    Utility.log(cName + ".method1 : found " + rar_jndi_name);
136:                } catch (Exception e2) {
137:                    Utility.log(cName + ".method1 error: lookup failed for "
138:                            + rar_jndi_name);
139:                    throw e2;
140:                }
141:
142:                try {
143:                    csp = new ConnectionSpecImpl(); // get a new ConnectionSpecImpl
144:
145:                } catch (Exception e3) {
146:                    Utility
147:                            .log(cName
148:                                    + ".method1 : new connection spec failed");
149:                    throw e3;
150:                }
151:                try {
152:                    conn = (ConnectionImpl) cccf.getConnection();
153:                    Utility
154:                            .log(cName + ".method1 : getConnection conn="
155:                                    + conn);
156:                    if (conn == null) {
157:                        Utility
158:                                .log(cName
159:                                        + ".method1 error: getConnection returned null connection.");
160:                        throw new Exception("");
161:                    }
162:                } catch (Exception e4) {
163:                    Utility.log(cName + ".method1 error: getConnection failed "
164:                            + e4.toString());
165:                    throw e4;
166:                }
167:                if (testName.equals("testIsXaresource")) {
168:                    try {
169:                        xidTest = doXid();
170:                    } catch (Exception e) {
171:                        throw e;
172:                    }
173:                }
174:                if (testName.equals("testIsXAend2")) {
175:                    try {
176:                        closeUp(CLOSE_PHYSICAL);
177:                        xidTest = doXid();
178:                    } catch (Exception e) {
179:                        throw e;
180:                    }
181:                }
182:            }
183:
184:            public String getXid() {
185:                return xidTest; // xidTest == OK | FAIL
186:            }
187:
188:            public String doXid() throws Exception {
189:                String ret;
190:                Utility.log(cName + ".doXid [enter]");
191:                if (conn == null) {
192:                    Utility.log(cName + ".doXid [exit] error: Connection=null");
193:                    return "FAIL";
194:                }
195:                ConnectionImpl conni = (ConnectionImpl) conn;
196:                try {
197:                    ManagedConnectionImpl mc = (ManagedConnectionImpl) conni
198:                            .getMC(); //get ManagedConnectionImpl
199:                    if (mc == null) {
200:                        Utility
201:                                .log(cName
202:                                        + ".doXid mc==null Should be null in testIsXAend2");
203:                        ret = "FAIL";
204:                    } else {
205:                        XAResourceImpl xar = mc.getCurrentXar();
206:                        if (xar == null) {
207:                            Utility.log(cName
208:                                    + ".doXid error: failed xar==null");
209:                            ret = "FAIL";
210:                        } else {
211:                            Xid xid = xar.getCurrentXid();
212:                            if (xid == null) {
213:                                Utility.log(cName + ".doXid error: xid=" + xid);
214:                                ret = "FAIL";
215:                            } else {
216:                                ret = "OK";
217:                            }
218:                        }
219:                    }
220:                    Utility.log(cName + ".doXid [exit] with " + ret);
221:                    return ret;
222:                } catch (IllegalStateException ise) {
223:                    String s = cName
224:                            + ".doXid error: failed IllegalStateException="
225:                            + ise;
226:                    Utility.log(s);
227:                    throw new Exception(s);
228:                } catch (Exception e) {
229:                    String s = cName + ".doXid error: failed " + e;
230:                    Utility.log(s);
231:                    throw new Exception(s);
232:                }
233:            }
234:
235:            /**
236:             * After the newly created ManagedConnectionFactory instance has been configured with
237:             * its property set, the application server creates a new ConnectionManager instance.
238:             * true returned if ConnectionManager is valid
239:             */
240:            public boolean getCMInstance() throws Exception {
241:                ConnectionManager cm;
242:                cm = cccf.getCM();
243:                if (cm == null) { // ConnectionManager not null
244:                    Utility
245:                            .log(cName
246:                                    + ".getCMInstance error: ConnectionManager is null");
247:                    return false;
248:                } else {
249:                    Utility.log(cName
250:                            + ".getCMInstance ConnectionManager is o.k.");
251:                    return true;
252:                }
253:            }
254:
255:            LocalTransactionImpl lt = null;
256:
257:            public void beginLoTransaction() {
258:                Utility.log(cName + ".beginLoTransaction (enter)");
259:                try {
260:                    LocalTransaction l = conn.getLocalTransaction();
261:                    lt = (LocalTransactionImpl) l;
262:                    lt.begin();
263:                    int s = lt.getTxState();
264:                    Utility
265:                            .log(cName + ".beginLoTransaction (exit) State="
266:                                    + s);
267:                } catch (Exception e) {
268:                    Utility.log(cName + ".beginLoTransaction (exit) error:"
269:                            + " " + e.toString());
270:
271:                }
272:            }
273:
274:            public void commitLoTransaction() throws Exception {
275:                Utility.log(cName + ".commitLoTransaction (enter)");
276:                try {
277:                    if (lt == null) {
278:                        Exception e = new Exception(
279:                                "Undefined LocalTransaction");
280:                        throw e;
281:                    }
282:                    lt.commit();
283:                    int s = lt.getTxState();
284:                    Utility.log(cName + ".commitLoTransaction (exit) =" + s);
285:                } catch (Exception e) {
286:                    Utility.log(cName
287:                            + ".commitLoTransaction (exit) error: State error."
288:                            + " " + e.getMessage());
289:                    throw e;
290:                }
291:                lt = null;
292:            }
293:
294:            public void rollbackLoTransaction() {
295:                Utility.log(cName + ".rollbackLoTransaction (enter)");
296:                try {
297:                    if (lt == null) {
298:                        Exception e = new Exception(
299:                                "Undefined LocalTransaction");
300:                        throw e;
301:                    }
302:                    lt.rollback();
303:                    int s = lt.getTxState();
304:                    Utility.log(cName + ".rollbackLoTransaction (exit) State="
305:                            + s);
306:                } catch (Exception e) {
307:                    Utility
308:                            .log(cName
309:                                    + ".rollbackLoTransaction (exit) error: State error"
310:                                    + " " + e.getMessage());
311:
312:                }
313:                lt = null;
314:            }
315:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.