1 25 package org.objectweb.easybeans.tests.transaction.containermanaged.base; 26 27 import java.sql.SQLException ; 28 29 import javax.ejb.NoSuchEJBException ; 30 import javax.naming.NamingException ; 31 import javax.transaction.Status ; 32 import javax.transaction.SystemException ; 33 import javax.transaction.UserTransaction ; 34 35 import org.objectweb.easybeans.log.JLog; 36 import org.objectweb.easybeans.log.JLogFactory; 37 import org.objectweb.easybeans.tests.common.ejbs.base.transaction.ItfContainerTransaction; 38 import org.objectweb.easybeans.tests.common.ejbs.stateless.containermanaged.ItfDatabaseManager; 39 import org.objectweb.easybeans.tests.common.ejbs.stateless.containermanaged.SLSBDatabaseManager; 40 import org.objectweb.easybeans.tests.common.helper.EJBHelper; 41 import org.objectweb.easybeans.tests.common.helper.TransactionHelper; 42 43 49 public final class ExceptionHandleUtil { 50 51 52 55 private static JLog logger = JLogFactory.getLog(ExceptionHandleUtil.class); 56 57 61 private ExceptionHandleUtil(){ 62 63 } 64 65 70 private static ItfDatabaseManager getBean() throws Exception { 71 return EJBHelper.getBeanRemoteInstance(SLSBDatabaseManager.class, ItfDatabaseManager.class); 72 73 } 74 80 public static void verifyTable(final String database, final String tableName) throws Exception { 81 getBean().verifyTable(database, tableName); 82 } 83 84 90 public static boolean isDiscarded(final ItfContainerTransaction bean) throws Exception { 91 boolean bolResult = false; 92 try { 93 bean.getUserTransactionWithLookup(); 94 } catch (NoSuchEJBException e) { 95 bolResult = true; 96 logger.debug("The bean threw an expected error during the execution {0}", e); 97 } 98 return bolResult; 99 } 100 101 102 108 public static void deleteTable(final String dbName, final String tableName) throws Exception { 109 try { 111 getBean().deleteTable(dbName, tableName); 112 } catch (SQLException e) { 113 logger.debug("The table delete threw an error during the execution {0}", e); 114 } catch (NamingException e) { 115 logger.debug("The table delete threw an error during the execution {0}", e); 116 } 117 } 118 122 public static void cleanTransaction() throws Exception { 123 UserTransaction utx = TransactionHelper.getInternalUserTransaction(); 124 try { 125 if (transactionIsActive()) { 126 utx.rollback(); 127 } 128 } catch (Exception e) { 129 throw new Exception ("Cannot clean the transaction. The test cannot be started", e); 130 } 131 } 132 133 139 public static boolean transactionIsActive() throws SystemException , NamingException { 140 UserTransaction utx = TransactionHelper.getInternalUserTransaction(); 141 boolean bolResult = false; 142 if (utx != null) { 143 if (utx.getStatus() == Status.STATUS_ACTIVE) { 144 bolResult = true; 145 } 146 } 147 return bolResult; 148 } 149 150 155 public static UserTransaction getUserTransaction() throws NamingException { 156 UserTransaction utx = TransactionHelper.getInternalUserTransaction(); 157 return utx; 158 } 159 } 160 | Popular Tags |