KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > easybeans > tests > common > ejbs > stateful > beanmanaged > transaction > SFSBBeanManagedException


1 /**
2  * EasyBeans
3  * Copyright (C) 2006 Bull S.A.S.
4  * Contact: easybeans@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: SFSBBeanManagedException.java 989 2006-07-31 12:23:28Z pinheirg $
23  * --------------------------------------------------------------------------
24  */

25 package org.objectweb.easybeans.tests.common.ejbs.stateful.beanmanaged.transaction;
26
27 import java.sql.SQLException JavaDoc;
28
29 import javax.ejb.Remote JavaDoc;
30 import javax.ejb.Stateful JavaDoc;
31 import javax.ejb.TransactionManagement JavaDoc;
32 import javax.ejb.TransactionManagementType JavaDoc;
33 import javax.naming.NamingException JavaDoc;
34 import javax.transaction.HeuristicMixedException JavaDoc;
35 import javax.transaction.HeuristicRollbackException JavaDoc;
36 import javax.transaction.NotSupportedException JavaDoc;
37 import javax.transaction.RollbackException JavaDoc;
38 import javax.transaction.SystemException JavaDoc;
39 import javax.transaction.UserTransaction JavaDoc;
40
41 import org.objectweb.easybeans.tests.common.db.TableManager;
42 import org.objectweb.easybeans.tests.common.exception.RollbackAppRuntimeException;
43 import org.objectweb.easybeans.tests.common.exception.TransactionRuntimeException;
44 import org.objectweb.easybeans.tests.common.helper.TransactionHelper;
45
46 /**
47  * Used to test the Exceptions and the bean-managed transaction.
48  * @author Gisele Pinheiro Souza
49  * @author Eduardo Studzinski Estima de Castro
50  *
51  */

52 @Stateful JavaDoc
53 @TransactionManagement JavaDoc(TransactionManagementType.BEAN)
54 @Remote JavaDoc
55 public class SFSBBeanManagedException implements ItfBeanManagedException {
56
57     /**
58      * Transaction used during the database operations.
59      */

60     private UserTransaction JavaDoc utx = null;
61
62     /**
63      * Class used to create the tables.
64      */

65     private TableManager tableManager = null;
66
67     /**
68      * Creates an instance of the tableManager.
69      * @param dbName the database name.
70      * @throws NamingException if a lookup error occurs.
71      */

72     public void startup(final String JavaDoc dbName) throws NamingException JavaDoc{
73         tableManager = new TableManager(dbName);
74     }
75     /**
76      * Begins a transaction, inserts the data in the database, throws an
77      * application exception and tries to commit.
78      * @throws SQLException if a database error occurs.
79      * @throws NamingException if a lookup error occurs.
80      * @throws SystemException if an unexpected error occurs.
81      * @throws NotSupportedException if the resquest cannot be made.
82      * @throws HeuristicRollbackException if a heuristic decision was made and
83      * some relevant update was rolled back.
84      * @throws RollbackException if the transaction was rolled back instead of
85      * committed.
86      * @throws HeuristicMixedException if a heuristic decision was made and some
87      * relevant update was commited and others rolled back.
88      * @throws IllegalStateException if the bean is not associated with a
89      * transaction.
90      * @throws SecurityException if the bean is not allowed to commit.
91      */

92     public void insertTableWithAppException() throws NamingException JavaDoc, SQLException JavaDoc, NotSupportedException JavaDoc, SystemException JavaDoc,
93             IllegalStateException JavaDoc, SecurityException JavaDoc, HeuristicMixedException JavaDoc, HeuristicRollbackException JavaDoc, RollbackException JavaDoc {
94         utx = TransactionHelper.getUserTransaction();
95         try {
96             utx.begin();
97             tableManager.insertTable(TABLE);
98             throw new RollbackAppRuntimeException(new Throwable JavaDoc("Applciation exception with rollback = true"));
99         } finally {
100             utx.commit();
101         }
102     }
103
104     /**
105      * Begins a transaction, inserts the data in the database, throws a
106      * runtime exception and tries to commit.
107      * @throws SQLException if a database error occurs.
108      * @throws NamingException if a lookup error occurs.
109      * @throws SystemException if an unexpected error occurs.
110      * @throws NotSupportedException if the resquest cannot be made.
111      * @throws HeuristicRollbackException if a heuristic decision was made and
112      * some relevant update was rolled back.
113      * @throws RollbackException if the transaction was rolled back instead of
114      * committed.
115      * @throws HeuristicMixedException if a heuristic decision was made and some
116      * relevant update was commited and others rolled back.
117      * @throws IllegalStateException if the bean is not associated with a
118      * transaction.
119      * @throws SecurityException if the bean is not allowed to commit.
120
121      */

122     public void insertTableWithRuntimeException() throws NamingException JavaDoc, SQLException JavaDoc, NotSupportedException JavaDoc, SystemException JavaDoc,
123             IllegalStateException JavaDoc, SecurityException JavaDoc, HeuristicMixedException JavaDoc, HeuristicRollbackException JavaDoc, RollbackException JavaDoc {
124         utx = TransactionHelper.getUserTransaction();
125         try {
126             utx.begin();
127             tableManager.insertTable(TABLE);
128             throw new TransactionRuntimeException(null);
129         } finally {
130             utx.commit();
131         }
132     }
133
134     /**
135      * Does nothing.
136      *
137      */

138     public void emptyMethod(){
139
140     }
141 }
142
Popular Tags