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


001:        // MosconeST.java
002:        // Stateful Session Bean
003:
004:        package org.objectweb.jonas.jtests.beans.bmt;
005:
006:        import java.rmi.RemoteException;
007:        import java.sql.Connection;
008:        import java.sql.ResultSet;
009:        import java.sql.SQLException;
010:        import java.sql.Statement;
011:        import java.sql.SQLException;
012:
013:        import javax.ejb.CreateException;
014:        import javax.ejb.EJBException;
015:        import javax.ejb.SessionBean;
016:        import javax.ejb.SessionContext;
017:        import javax.naming.Context;
018:        import javax.naming.InitialContext;
019:        import javax.naming.NamingException;
020:        import javax.rmi.PortableRemoteObject;
021:        import javax.sql.DataSource;
022:        import javax.transaction.NotSupportedException;
023:        import javax.transaction.SystemException;
024:        import javax.transaction.UserTransaction;
025:
026:        import org.objectweb.jonas.common.Log;
027:        import org.objectweb.util.monolog.api.BasicLevel;
028:        import org.objectweb.util.monolog.api.Logger;
029:
030:        /**
031:         * Stateful Session bean that manages transactions inside the bean.
032:         * This type of bean must NOT implement SessionSynchronization.
033:         */
034:        public class MosconeST implements  SessionBean {
035:
036:            static private Logger logger = null;
037:            SessionContext ejbContext;
038:
039:            // state of the sessionbean
040:            Context ictx = null;
041:            UserTransaction ut = null;
042:            Connection cnx = null;
043:            ResultSet rs = null;
044:            Statement st = null;
045:
046:            // ------------------------------------------------------------------
047:            // SessionBean implementation
048:            // ------------------------------------------------------------------
049:
050:            /** 
051:             * Set the associated session context. The container calls this method
052:             * after the instance creation. 
053:             * The enterprise Bean instance should store the reference to the context
054:             * object in an instance variable. 
055:             * This method is called with no transaction context.
056:             *
057:             * @param sessionContext A SessionContext interface for the instance.
058:             * @throws EJBException Thrown by the method to indicate a failure caused by
059:             * a system-level error.
060:             */
061:            public void setSessionContext(SessionContext ctx) {
062:                if (logger == null)
063:                    logger = Log.getLogger("org.objectweb.jonas_tests");
064:                logger.log(BasicLevel.DEBUG, "");
065:                ejbContext = ctx;
066:            }
067:
068:            /**
069:             * A container invokes this method before it ends the life of the session object. 
070:             * This happens as a result of a client's invoking a remove operation, or when a 
071:             *  container decides to terminate the session object after a timeout. 
072:             * This method is called with no transaction context. 
073:             *
074:             * @throws EJBException Thrown by the method to indicate a failure caused by
075:             * a system-level error.
076:             */
077:            public void ejbRemove() {
078:                logger.log(BasicLevel.DEBUG, "");
079:            }
080:
081:            private void getConnection() throws RemoteException {
082:                try {
083:                    ictx = new InitialContext();
084:                    DataSource ds = (DataSource) PortableRemoteObject.narrow(
085:                            ictx.lookup("jdbc_1"), DataSource.class);
086:                    cnx = ds.getConnection();
087:                } catch (Exception e) {
088:                    throw new RemoteException("cannot get connection: " + e);
089:                }
090:            }
091:
092:            private void closeConnection() throws RemoteException {
093:                try {
094:                    if (cnx != null) {
095:                        cnx.close();
096:                    }
097:                } catch (Exception e) {
098:                    throw new RemoteException("cannot close connection: " + e);
099:                }
100:            }
101:
102:            /**
103:             * The Session bean must define 1 or more ejbCreate methods.
104:             *
105:             * @throws CreateException Failure to create a session EJB object.
106:             */
107:            public void ejbCreate() throws CreateException {
108:                logger.log(BasicLevel.DEBUG, "");
109:            }
110:
111:            /**
112:             * A container invokes this method on an instance before the instance
113:             * becomes disassociated with a specific EJB object.
114:             */
115:            public void ejbPassivate() {
116:                logger.log(BasicLevel.DEBUG, "");
117:            }
118:
119:            /**
120:             * A container invokes this method when the instance is taken out of 
121:             * the pool of available instances to become associated with a specific 
122:             * EJB object.
123:             */
124:            public void ejbActivate() {
125:                logger.log(BasicLevel.DEBUG, "");
126:            }
127:
128:            // ------------------------------------------------------------------
129:            // Moscone implementation
130:            // ------------------------------------------------------------------
131:
132:            /**
133:             * The following method start a transaction that will be continued
134:             * in other methods of this bean.
135:             */
136:            public void tx_start() throws RemoteException {
137:                logger.log(BasicLevel.DEBUG, "");
138:
139:                // Obtain the UserTransaction interface
140:                try {
141:                    ut = ejbContext.getUserTransaction();
142:                } catch (IllegalStateException e) {
143:                    logger.log(BasicLevel.ERROR, "Can't get UserTransaction");
144:                    throw new RemoteException("Can't get UserTransaction:", e);
145:                }
146:
147:                // Start a global transaction
148:                try {
149:                    ut.begin();
150:                } catch (NotSupportedException e) {
151:                    logger.log(BasicLevel.ERROR, "Can't start Transaction");
152:                    throw new RemoteException("Can't start Transaction:", e);
153:                } catch (SystemException e) {
154:                    logger.log(BasicLevel.ERROR, "Can't start Transaction");
155:                    throw new RemoteException("Can't start Transaction:", e);
156:                }
157:            }
158:
159:            /**
160:             * This method commits the current transaction, started previously by tx_start().
161:             */
162:            public void tx_commit() throws RemoteException {
163:                logger.log(BasicLevel.DEBUG, "");
164:
165:                // Commit this GLOBAL transaction
166:                try {
167:                    ut.commit();
168:                } catch (Exception e) {
169:                    logger.log(BasicLevel.ERROR, "Can't commit Transaction");
170:                    throw new RemoteException("Can't commit Transaction:", e);
171:                }
172:            }
173:
174:            /**
175:             * This method rolls back the current transaction, started previously by tx_start().
176:             */
177:            public void tx_rollback() throws RemoteException {
178:                logger.log(BasicLevel.DEBUG, "");
179:
180:                // Roll back this GLOBAL transaction
181:                try {
182:                    ut.rollback();
183:                } catch (Exception e) {
184:                    logger.log(BasicLevel.ERROR, "Can't rollback Transaction");
185:                    throw new RemoteException("Can't rollback Transaction:", e);
186:                }
187:            }
188:
189:            /**
190:             * This method open a connection before starting transactions.
191:             */
192:            public void moscone1() throws RemoteException {
193:                logger.log(BasicLevel.DEBUG, "");
194:
195:                getConnection();
196:
197:                // Obtain the UserTransaction interface
198:                try {
199:                    ut = ejbContext.getUserTransaction();
200:                } catch (IllegalStateException e) {
201:                    logger.log(BasicLevel.ERROR, "Can't get UserTransaction");
202:                    throw new RemoteException("Can't get UserTransaction:", e);
203:                }
204:
205:                // Start a global transaction
206:                try {
207:                    ut.begin();
208:                } catch (NotSupportedException e) {
209:                    logger.log(BasicLevel.ERROR, "Can't start Transaction");
210:                    throw new RemoteException("Can't start Transaction:", e);
211:                } catch (SystemException e) {
212:                    logger.log(BasicLevel.ERROR, "Can't start Transaction");
213:                    throw new RemoteException("Can't start Transaction:", e);
214:                }
215:
216:                // work with connection.
217:                try {
218:                    String ret = null;
219:                    st = cnx.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
220:                            ResultSet.CONCUR_READ_ONLY);
221:                    rs = st.executeQuery("SELECT * FROM JT2_MARCHE");
222:                    if (rs.first()) {
223:                        do {
224:                            ret += rs.getInt("IDMAR") + ":"
225:                                    + rs.getString("NOM") + "\n";
226:                        } while (rs.next());
227:                    }
228:                    st.close();
229:                } catch (SQLException e) {
230:                    throw new RemoteException("Error working on database: " + e);
231:                }
232:
233:                // Commit this GLOBAL transaction
234:                try {
235:                    ut.commit();
236:                } catch (Exception e) {
237:                    logger.log(BasicLevel.ERROR, "Can't commit Transaction");
238:                    throw new RemoteException("Can't commit Transaction:", e);
239:                }
240:
241:                closeConnection();
242:            }
243:
244:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.