1 25 package org.objectweb.easybeans.tests.common.ejbs.stateless.beanmanaged.transaction; 26 27 import java.sql.SQLException ; 28 29 import javax.ejb.EJBContext ; 30 import javax.ejb.Remote ; 31 import javax.ejb.Stateless ; 32 import javax.ejb.TransactionManagement ; 33 import javax.ejb.TransactionManagementType ; 34 import javax.naming.NamingException ; 35 import javax.transaction.HeuristicMixedException ; 36 import javax.transaction.HeuristicRollbackException ; 37 import javax.transaction.NotSupportedException ; 38 import javax.transaction.RollbackException ; 39 import javax.transaction.SystemException ; 40 import javax.transaction.UserTransaction ; 41 42 import org.objectweb.easybeans.tests.common.db.TableManager; 43 import org.objectweb.easybeans.tests.common.exception.TransactionException; 44 import org.objectweb.easybeans.tests.common.helper.EJBContextHelper; 45 import org.objectweb.easybeans.tests.common.helper.TransactionHelper; 46 47 53 @Stateless (name="SLSBBeanManagedTransaction") 54 @Remote (ItfBeanManagedTransaction.class) 55 @TransactionManagement (value = TransactionManagementType.BEAN) 56 public class SLSBBeanManagedTransaction implements ItfBeanManagedTransaction { 57 58 77 public void deleteTableWithBeginCommit(final boolean callOnlyTransaction, final String dbName) throws SQLException , 78 NamingException , SystemException , NotSupportedException , HeuristicRollbackException , RollbackException , 79 HeuristicMixedException , TransactionException { 80 UserTransaction utx = TransactionHelper.getUserTransaction(); 81 utx.begin(); 82 try { 83 if (!callOnlyTransaction) { 84 TableManager tableManager = new TableManager(dbName); 85 tableManager.deleteTable(TABLE); 86 } 87 utx.commit(); 88 } catch (Exception e) { 89 utx.rollback(); 90 throw new TransactionException("Error during commit.", e); 91 } 92 93 } 94 95 112 public void deleteTableWithoutBegin(final boolean callOnlyTransaction, final String dbName) throws SQLException , 113 NamingException , SystemException , NotSupportedException , HeuristicRollbackException , RollbackException , 114 HeuristicMixedException { 115 UserTransaction utx = TransactionHelper.getUserTransaction(); 116 if (!callOnlyTransaction) { 117 TableManager tableManager = new TableManager(dbName); 118 tableManager.deleteTable(TABLE); 119 } 120 utx.commit(); 121 122 } 123 124 142 public void insertTableWithBeginCommit(final boolean callOnlyTransaction, final String dbName) throws SQLException , 143 NamingException , SystemException , NotSupportedException , HeuristicRollbackException , RollbackException , 144 HeuristicMixedException , TransactionException { 145 UserTransaction utx = TransactionHelper.getUserTransaction(); 146 utx.begin(); 147 try { 148 if (!callOnlyTransaction) { 149 TableManager tableManager = new TableManager(dbName); 150 tableManager.insertTable(TABLE); 151 } 152 utx.commit(); 153 } catch (Exception e) { 154 utx.rollback(); 155 throw new TransactionException("Error during commit.", e); 156 } 157 158 } 159 160 172 public void insertTableWithoutCommit(final boolean callOnlyTransaction, final String dbName) throws SQLException , 173 NamingException , SystemException , NotSupportedException { 174 UserTransaction utx = TransactionHelper.getUserTransaction(); 175 utx.begin(); 176 if (!callOnlyTransaction) { 177 TableManager tableManager = new TableManager(dbName); 178 tableManager.insertTable(TABLE); 179 } 180 } 181 182 187 public void setRollbackOnly() throws NamingException , IllegalStateException { 188 EJBContext ejbContext = EJBContextHelper.getEJBContext(); 189 ejbContext.setRollbackOnly(); 190 } 191 192 197 public void getRollbackOnly() throws NamingException , IllegalStateException { 198 EJBContext ejbContext = EJBContextHelper.getEJBContext(); 199 ejbContext.getRollbackOnly(); 200 } 201 202 } 203 | Popular Tags |