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


001:        /*
002:         * JOnAS: Java(TM) Open Application Server
003:         * Copyright (C) 1999 Bull S.A.
004:         * Contact: jonas-team@objectweb.org
005:         * 
006:         * This library is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU Lesser General Public
008:         * License as published by the Free Software Foundation; either
009:         * version 2.1 of the License, or any later version.
010:         * 
011:         * This library is distributed in the hope that it will be useful,
012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         * Lesser General Public License for more details.
015:         * 
016:         * You should have received a copy of the GNU Lesser General Public
017:         * License along with this library; if not, write to the Free Software
018:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
019:         * USA
020:         *
021:         * --------------------------------------------------------------------------
022:         * $Id: SimpleSY.java 5996 2004-12-17 15:09:45Z joaninh $
023:         * --------------------------------------------------------------------------
024:         */
025:
026:        package org.objectweb.jonas.jtests.beans.transacted;
027:
028:        import javax.ejb.CreateException;
029:        import javax.ejb.EJBException;
030:        import javax.ejb.RemoveException;
031:        import javax.ejb.SessionSynchronization;
032:        import javax.naming.Context;
033:        import javax.naming.InitialContext;
034:        import javax.naming.NamingException;
035:        import javax.rmi.PortableRemoteObject;
036:
037:        import org.objectweb.util.monolog.api.BasicLevel;
038:
039:        /*
040:         * Stateful session bean
041:         */
042:        public class SimpleSY extends SimpleSL implements 
043:                SessionSynchronization {
044:
045:            private boolean rollbackonly = false;
046:            private Context ictx = null;
047:            private SimpleELocalHome lhome = null;
048:
049:            // ------------------------------------------------------------------
050:            // SynchroSimple implementation
051:            // ------------------------------------------------------------------
052:
053:            /**
054:             * Ask bean to set transaction rollback only
055:             */
056:            public void setRollbackOnly() {
057:                logger.log(BasicLevel.DEBUG, "");
058:                rollbackonly = true;
059:            }
060:
061:            /**
062:             * REQUIRED -> should return true.
063:             */
064:            public boolean call_requires_new_local() {
065:                logger.log(BasicLevel.DEBUG, "");
066:                SimpleLocal loc = getLocalBean();
067:                boolean tx = loc.opwith_requires_new();
068:                if (!tx) {
069:                    logger.log(BasicLevel.ERROR,
070:                            "opwith_requires_new was outside tx");
071:                    return false; // error
072:                }
073:                try {
074:                    loc.remove(); // cleaning
075:                } catch (RemoveException e) {
076:                    logger.log(BasicLevel.ERROR, "cannot remove local bean");
077:                }
078:                return isAssociated();
079:            }
080:
081:            /**
082:             * REQUIRED -> should return true.
083:             */
084:            public boolean call_notsupported_local() {
085:                logger.log(BasicLevel.DEBUG, "");
086:                SimpleLocal loc = getLocalBean();
087:                boolean tx = loc.opwith_notsupported();
088:                if (tx) {
089:                    logger.log(BasicLevel.ERROR,
090:                            "opwith_notsupported was in tx");
091:                    return false; // error
092:                }
093:                try {
094:                    loc.remove(); // cleaning
095:                } catch (RemoveException e) {
096:                    logger.log(BasicLevel.ERROR, "cannot remove local bean");
097:                }
098:                return isAssociated();
099:            }
100:
101:            // ------------------------------------------------------------------
102:            // SessionSynchronization implementation
103:            // ------------------------------------------------------------------
104:
105:            /** 
106:             * The afterBegin method notifies a session Bean instance that a new 
107:             * transaction has started, and that the subsequent business methods on
108:             * the instance will be invoked in the context of the transaction. 
109:             * This method executes in the proper transaction context. 
110:             *
111:             * @throws EJBException Thrown if the instance could not perform
112:             * the function requested by the container because of a system-level error.
113:             */
114:            public void afterBegin() {
115:                logger.log(BasicLevel.DEBUG, "");
116:            }
117:
118:            /** 
119:             * The beforeCompletion method notifies a session Bean instance that a
120:             * transaction is about to be committed. 
121:             * This method executes in the proper transaction context. 
122:             * Note: The instance may still cause the container to rollback the transaction
123:             * by invoking the setRollbackOnly() method on the instance context, or by throwing
124:             * an exception. 
125:             *   
126:             * @throws EJBException Thrown by the method to indicate a failure caused by a
127:             * system-level error.
128:             */
129:            public void beforeCompletion() {
130:                logger.log(BasicLevel.DEBUG, "");
131:                if (rollbackonly) {
132:                    sessionContext.setRollbackOnly();
133:                }
134:            }
135:
136:            /** 
137:             * The afterCompletion method notifies a session Bean instance that a
138:             * transaction commit protocol has completed, and tells the instance whether
139:             * the transaction has been committed or rolled back. 
140:             * This method executes with no transaction context. 
141:             *
142:             * @param : committed - True if the transaction has been committed, false if
143:             * it has been rolled back.
144:             * 
145:             * @throws EJBException Thrown by the method to indicate a failure caused by a
146:             * system-level error.
147:             */
148:            public void afterCompletion(boolean committed) {
149:                logger.log(BasicLevel.DEBUG, "");
150:            }
151:
152:            // ------------------------------------------------------------------
153:            // private methods
154:            // ------------------------------------------------------------------
155:
156:            /**
157:             * init non persistent bean data.
158:             * This should be called when instance is created or activated.
159:             */
160:            private void stateUpdate() throws NamingException {
161:                // Get initial Context
162:                if (ictx == null) {
163:                    ictx = new InitialContext();
164:                }
165:                // lookup paperhome in JNDI
166:                if (lhome == null) {
167:                    lhome = (SimpleELocalHome) ictx
168:                            .lookup("java:comp/env/ejb/SimpleEC");
169:                }
170:            }
171:
172:            /**
173:             * get local bean
174:             */
175:            private SimpleLocal getLocalBean() {
176:                SimpleLocal ret = null;
177:                try {
178:                    stateUpdate();
179:                } catch (NamingException e) {
180:                    logger.log(BasicLevel.ERROR,
181:                            "getLocalBean raised exception " + e);
182:                    throw new EJBException("Error in getLocalBean:" + e);
183:                }
184:                try {
185:                    ret = lhome.create(123);
186:                } catch (CreateException e) {
187:                    logger.log(BasicLevel.ERROR,
188:                            "Cannot create local entity bean " + e);
189:                    throw new EJBException("Cannot create local entity bean:"
190:                            + e);
191:                }
192:                return ret;
193:            }
194:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.