Source Code Cross Referenced for SFSBBeanManagedTransaction.java in  » J2EE » ow2-easybeans » org » ow2 » easybeans » tests » common » ejbs » stateful » beanmanaged » transaction » 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 » ow2 easybeans » org.ow2.easybeans.tests.common.ejbs.stateful.beanmanaged.transaction 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * EasyBeans
003:         * Copyright (C) 2006 Bull S.A.S.
004:         * Contact: easybeans@ow2.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: SFSBBeanManagedTransaction.java 1970 2007-10-16 11:49:25Z benoitf $
023:         * --------------------------------------------------------------------------
024:         */package org.ow2.easybeans.tests.common.ejbs.stateful.beanmanaged.transaction;
025:
026:        import java.sql.SQLException;
027:
028:        import javax.annotation.Resource;
029:        import javax.ejb.Remote;
030:        import javax.ejb.SessionContext;
031:        import javax.ejb.Stateful;
032:        import javax.ejb.TransactionManagement;
033:        import javax.ejb.TransactionManagementType;
034:        import javax.naming.NamingException;
035:        import javax.transaction.HeuristicMixedException;
036:        import javax.transaction.HeuristicRollbackException;
037:        import javax.transaction.NotSupportedException;
038:        import javax.transaction.RollbackException;
039:        import javax.transaction.Status;
040:        import javax.transaction.SystemException;
041:        import javax.transaction.UserTransaction;
042:
043:        import org.ow2.easybeans.tests.common.db.TableManager;
044:        import org.ow2.easybeans.tests.common.exception.TransactionException;
045:        import org.ow2.easybeans.tests.common.helper.TransactionHelper;
046:
047:        /**
048:         * Inserts the table test in the database. This class uses usertransactions for
049:         * making the operations.
050:         * @author Gisele Pinheiro Souza
051:         * @author Eduardo Studzinski Estima de Castro
052:         */
053:        @Stateful(name="SFSBBeanManagedTransaction")
054:        @Remote(ItfBeanManagedTransaction.class)
055:        @TransactionManagement(value=TransactionManagementType.BEAN)
056:        public class SFSBBeanManagedTransaction implements 
057:                ItfBeanManagedTransaction {
058:
059:            /**
060:             * The bean sessionContext.
061:             */
062:            @Resource
063:            private SessionContext sessionContext;
064:
065:            /**
066:             * Transaction used during the database operations.
067:             */
068:            private UserTransaction utx = null;
069:
070:            /**
071:             * Class used to create the tables.
072:             */
073:            private TableManager tableManager = null;
074:
075:            /**
076:             * Says if the table must be created. Used to tests if the container accepts
077:             * the transaction order.
078:             */
079:            private boolean bolOnlyCreateTrans = false;
080:
081:            /**
082:             * Deletes the table called test. The bean transaction is started and
083:             * commited in this method.
084:             * @throws SQLException if a database error occurs.
085:             * @throws NamingException if a lookup error occurs.
086:             * @throws SystemException if an unexpected error occurs.
087:             * @throws NotSupportedException if the resquest cannot be made.
088:             * @throws HeuristicRollbackException if a heuristic decision was made and
089:             *         some relevant update was rolled back.
090:             * @throws RollbackException if the transaction was rolled back instead of
091:             *         committed.
092:             * @throws HeuristicMixedException if a heuristic decision was made and some
093:             *         relevant update was commited and others rolled back.
094:             * @throws TransactionException if a rollback was executed.
095:             */
096:            public void dropTableWithBeginCommitTransaction()
097:                    throws SQLException, NamingException, SystemException,
098:                    NotSupportedException, HeuristicRollbackException,
099:                    RollbackException, HeuristicMixedException,
100:                    TransactionException {
101:                utx.begin();
102:                try {
103:                    if (!bolOnlyCreateTrans) {
104:                        tableManager.deleteTable(TABLE);
105:                    }
106:                    utx.commit();
107:                } catch (Exception e) {
108:                    utx.rollback();
109:                    throw new TransactionException("Error during commit.", e);
110:                }
111:
112:            }
113:
114:            /**
115:             * Deletes the table called test. The transaction is not open, but it is
116:             * commited in this method.
117:             * @throws SQLException if a database error occurs.
118:             * @throws NamingException if a lookup error occurs.
119:             * @throws SystemException if an unexpected error occurs.
120:             * @throws NotSupportedException if the resquest cannot be made.
121:             * @throws HeuristicRollbackException if a heuristic decision was made and
122:             *         some relevant update was rolled back.
123:             * @throws RollbackException if the transaction was rolled back instead of
124:             *         committed.
125:             * @throws HeuristicMixedException if a heuristic decision was made and some
126:             *         relevant update was commited and others rolled back.
127:             * @throws TransactionException if a rollback was executed.
128:             */
129:            public void dropTableWithoutBeginTransaction() throws SQLException,
130:                    NamingException, SystemException, NotSupportedException,
131:                    HeuristicRollbackException, RollbackException,
132:                    HeuristicMixedException, TransactionException {
133:                try {
134:                    if (!bolOnlyCreateTrans) {
135:                        tableManager.deleteTable(TABLE);
136:                    }
137:                    utx.commit();
138:                } catch (Exception e) {
139:                    utx.rollback();
140:                    throw new TransactionException("Error during commit.", e);
141:                }
142:            }
143:
144:            /**
145:             * Inserts the table called test. The transaction is open and commited in
146:             * this method.
147:             * @throws SQLException if a database error occurs.
148:             * @throws NamingException if a lookup error occurs.
149:             * @throws SystemException if an unexpected error occurs.
150:             * @throws NotSupportedException if the resquest cannot be made.
151:             * @throws HeuristicRollbackException if a heuristic decision was made and
152:             *         some relevant update was rolled back.
153:             * @throws RollbackException if the transaction was rolled back instead of
154:             *         committed.
155:             * @throws HeuristicMixedException if a heuristic decision was made and some
156:             *         relevant update was commited and others rolled back.
157:             * @throws TransactionException if a rollback was executed.
158:             */
159:            public void insertTableWithBeginCommitTransaction()
160:                    throws SQLException, NamingException, SystemException,
161:                    NotSupportedException, HeuristicRollbackException,
162:                    RollbackException, HeuristicMixedException,
163:                    TransactionException {
164:
165:                utx.begin();
166:                try {
167:                    if (!bolOnlyCreateTrans) {
168:                        tableManager.insertTable(TABLE);
169:                    }
170:                    utx.commit();
171:                } catch (Exception e) {
172:                    utx.rollback();
173:                    throw new TransactionException("Error during commit.", e);
174:                }
175:            }
176:
177:            /**
178:             * Inserts the table called test. The transaction will be open, but it will not
179:             * be commited in this method.
180:             * @throws SQLException if a database error occurs.
181:             * @throws NamingException if a lookup error occurs.
182:             * @throws SystemException if an unexpected error occurs.
183:             * @throws NotSupportedException if the resquest cannot be made.
184:             */
185:            public void insertTableWithoutCommitTransaction()
186:                    throws SQLException, NamingException, SystemException,
187:                    NotSupportedException {
188:                utx.begin();
189:                if (!bolOnlyCreateTrans) {
190:                    tableManager.insertTable(TABLE);
191:                }
192:            }
193:
194:            /**
195:             * Creates the table called test.The bean transaction is started and
196:             * commited in this method and, also, there is a nested transaction.
197:             * @throws SQLException if a database error occurs.
198:             * @throws NamingException if a lookup error occurs.
199:             * @throws SystemException if an unexpected error occurs.
200:             * @throws NotSupportedException if the resquest cannot be made.
201:             * @throws HeuristicRollbackException if a heuristic decision was made and
202:             *         some relevant update was rolled back.
203:             * @throws RollbackException if the transaction was rolled back instead of
204:             *         committed.
205:             * @throws HeuristicMixedException if a heuristic decision was made and some
206:             *         relevant update was commited and others rolled back.
207:             * @throws TransactionException if a rollback was executed.
208:             */
209:            public void insertTableWithNestedTrans() throws SQLException,
210:                    NamingException, SystemException, NotSupportedException,
211:                    HeuristicRollbackException, RollbackException,
212:                    HeuristicMixedException, TransactionException {
213:                // does a begin in the bean transaction
214:                utx.begin();
215:                // creates a new transaction
216:                UserTransaction utxNested = TransactionHelper
217:                        .getUserTransaction();
218:
219:                // does a begin in other transaction
220:                utxNested.begin();
221:                // creates the table
222:                if (!bolOnlyCreateTrans) {
223:                    tableManager.insertTable(TABLE);
224:                }
225:                // does the commit in the nested transaction
226:                utxNested.commit();
227:                // does the commit in the bean transaction
228:                utx.commit();
229:
230:            }
231:
232:            /**
233:             * Creates the table called test.A new transaction is created and it makes
234:             * the begin and commit transaction. The bean transaction is not started or
235:             * commited in this method.
236:             * @throws SQLException if a database error occurs.
237:             * @throws NamingException if a lookup error occurs.
238:             * @throws SystemException if an unexpected error occurs.
239:             * @throws NotSupportedException if the resquest cannot be made.
240:             * @throws HeuristicRollbackException if a heuristic decision was made and
241:             *         some relevant update was rolled back.
242:             * @throws RollbackException if the transaction was rolled back instead of
243:             *         committed.
244:             * @throws HeuristicMixedException if a heuristic decision was made and some
245:             *         relevant update was commited and others rolled back.
246:             * @throws TransactionException if a rollback was executed.
247:             */
248:            public void insertTableWithNewTransaction() throws SQLException,
249:                    NamingException, SystemException, NotSupportedException,
250:                    HeuristicRollbackException, RollbackException,
251:                    HeuristicMixedException, TransactionException {
252:                // creates a new transaction
253:                UserTransaction utxNested = TransactionHelper
254:                        .getUserTransaction();
255:
256:                // does a begin in other transaction
257:                utxNested.begin();
258:                try {
259:                    // creates the table
260:                    if (!bolOnlyCreateTrans) {
261:                        tableManager.insertTable(TABLE);
262:                    }
263:                    // does the commit in the nested transaction
264:                    // does the commit in the nested transaction
265:                    utxNested.commit();
266:                } catch (Exception e) {
267:                    utxNested.rollback();
268:                    if (this .getTransactionStatus() != Status.STATUS_NO_TRANSACTION) {
269:                        utx.rollback();
270:                    }
271:                    throw new TransactionException("Error during commit.", e);
272:                }
273:            }
274:
275:            /**
276:             * Inserts the table called test. The transaction is openned and after
277:             * insert the table, an rollback is called.
278:             * @throws SQLException if a database error occurs.
279:             * @throws NamingException if a lookup error occurs.
280:             * @throws SystemException if an unexpected error occurs.
281:             * @throws NotSupportedException if the resquest cannot be made.
282:             */
283:            public void insertTableWithBeginRollback() throws SQLException,
284:                    NamingException, SystemException, NotSupportedException {
285:                utx.begin();
286:                if (!bolOnlyCreateTrans) {
287:                    tableManager.insertTable(TABLE);
288:                }
289:                utx.rollback();
290:            }
291:
292:            /**
293:             * Makes a rollback in the transaction.
294:             * @throws IllegalStateException if a transaction is not associated with a transaction.
295:             * @throws SecurityException if the transaction is not allowed to make a rollback.
296:             * @throws SystemException if an unexpected error occurs.
297:             */
298:            public void setRollback() throws IllegalStateException,
299:                    SecurityException, SystemException {
300:                utx.rollback();
301:            }
302:
303:            /**
304:             * Gets the transaction.
305:             * @param callOnlyTransaction if only the transactions must be called.
306:             * @param dbName the database where the table is inserted.
307:             * @throws SQLException if a database error occurs.
308:             * @throws NamingException if a lookup error occurs.
309:             */
310:            public void startup(final boolean callOnlyTransaction,
311:                    final String dbName) throws NamingException, SQLException {
312:                utx = TransactionHelper.getUserTransaction();
313:                bolOnlyCreateTrans = callOnlyTransaction;
314:                tableManager = new TableManager(dbName);
315:
316:            }
317:
318:            /**
319:             * Obtains the bean transaction status.
320:             * @return the bean transaction status.
321:             * @throws SystemException if an unexpected error occurs.
322:             */
323:            public int getTransactionStatus() throws SystemException {
324:                return utx.getStatus();
325:            }
326:
327:            /**
328:             * Makes a setRollbackOnly that must to throw en exception.
329:             * @throws NamingException if a lookup error occurs.
330:             * @throws IllegalStateException if the bean try to call the setRollBackOnly
331:             */
332:            public void setRollbackOnly() throws NamingException,
333:                    IllegalStateException {
334:                sessionContext.setRollbackOnly();
335:            }
336:
337:            /**
338:             * Makes a getRollbackOnly that must to throw en exception.
339:             * @throws NamingException if a lookup error occurs.
340:             * @throws IllegalStateException if the bean try to call the getRollBackOnly
341:             */
342:            public void getRollbackOnly() throws NamingException,
343:                    IllegalStateException {
344:                sessionContext.getRollbackOnly();
345:            }
346:        }
w___ww.j___a__va___2s___.__c__om__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.