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


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