1 22 23 24 package org.jboss.test.testbean.bean; 25 26 import java.rmi.*; 27 import javax.ejb.*; 28 import javax.naming.InitialContext ; 29 import javax.naming.Context ; 30 import org.jboss.test.testbean.interfaces.TxSession; 31 32 33 public class TxSessionBean implements SessionBean { 34 org.jboss.logging.Logger log = org.jboss.logging.Logger.getLogger(getClass()); 35 private SessionContext sessionContext; 36 37 public void ejbCreate() throws RemoteException, CreateException { 38 log.debug("TxSessionBean.ejbCreate() called"); 39 } 40 41 public void ejbActivate() throws RemoteException { 42 log.debug("TxSessionBean.ejbActivate() called"); 43 } 44 45 public void ejbPassivate() throws RemoteException { 46 log.debug("TxSessionBean.ejbPassivate() called"); 47 } 48 49 public void ejbRemove() throws RemoteException { 50 log.debug("TxSessionBean.ejbRemove() called"); 51 } 52 53 public void setSessionContext(SessionContext context) throws RemoteException { 54 sessionContext = context; 55 } 58 59 62 public String txRequired() { 63 64 log.debug("TxSessionBean.txRequired() called"); 65 66 try { 67 Object tx =getDaTransaction(); 68 if (tx == null) 69 throw new Error ("Required sees no transaction"); 70 else 71 return ("required sees a transaction "+tx.hashCode()); 72 } 73 catch (Exception e) {log.debug("failed", e); return e.getMessage();} 74 } 75 76 77 80 public String txRequiresNew() { 81 82 log.debug("TxSessionBean.txRequiresNew() called"); 83 84 try { 85 Object tx =getDaTransaction(); 86 if (tx == null) 87 throw new Error ("RequiresNew sees no transaction"); 88 else 89 return ("requiresNew sees a transaction "+tx.hashCode()); 90 } 91 catch (Exception e) {log.debug("failed", e);return e.getMessage();} 92 } 93 94 97 98 public String txSupports() { 99 100 log.debug("TxSessionBean.txSupports() called"); 101 102 try { 103 104 Object tx =getDaTransaction(); 105 106 if (tx == null) 107 return "supports sees no transaction"; 108 else 109 return "supports sees a transaction "+tx.hashCode(); 110 } 111 catch (Exception e) {log.debug("failed", e);return e.getMessage();} 112 } 113 114 115 118 public String txMandatory() { 119 120 log.debug("TxSessionBean.txMandatory() called"); 121 122 try { 123 Object tx =getDaTransaction(); 124 if (tx == null) 125 throw new Error ("Mandatory sees no transaction"); 126 else 127 return ("mandatory sees a transaction "+tx.hashCode()); 128 } 129 catch (Exception e) {log.debug("failed", e);return e.getMessage();} 130 } 131 132 135 public String txNever() { 136 137 log.debug("TxSessionBean.txNever() called"); 138 139 try { 140 Object tx =getDaTransaction(); 141 if (tx == null) 142 return "never sees no transaction"; 143 else 144 throw new Error ("txNever sees a transaction"); 145 } 146 catch (Exception e) {log.debug("failed", e);return e.getMessage();} 147 } 148 151 152 public String txNotSupported() { 153 154 log.debug("TxSessionBean.txNotSupported() called"); 155 156 try { 157 Object tx =getDaTransaction(); 158 if (tx == null) 159 return "notSupported sees no transaction"; 160 else 161 throw new Error ("txNotSupported sees a transaction"); 162 } 163 catch (Exception e) {log.debug("failed", e);return e.getMessage();} 164 } 165 166 169 public String requiredToSupports() throws RemoteException { 170 171 log.debug("TxSessionBean.requiredToSupports() called"); 172 173 String message; 174 Object tx =getDaTransaction(); 175 if (tx == null) 176 throw new Error ("Required doesn't see a transaction"); 177 else 178 message = "Required sees a transaction "+tx.hashCode()+ " Supports should see the same "; 179 180 message = message + ((TxSession) sessionContext.getEJBObject()).txSupports(); 181 182 tx =getDaTransaction(); 184 if (tx == null) 185 throw new Error ("Required doesn't see a transaction COMING BACK"); 186 else 187 return message + " on coming back Required sees a transaction "+tx.hashCode() ; 188 189 } 190 191 194 public String requiredToNotSupported() throws RemoteException { 195 196 log.debug("TxSessionBean.requiredToNotSupported() called"); 197 198 String message; 199 Object tx =getDaTransaction(); 200 if (tx == null) 201 throw new Error ("Required doesn't see a transaction"); 202 else 203 message = "Required sees a transaction "+tx.hashCode()+ " NotSupported should see the same "; 204 205 206 message = message + ((TxSession) sessionContext.getEJBObject()).txNotSupported(); 207 208 tx =getDaTransaction(); 210 if (tx == null) 211 throw new Error ("Required doesn't see a transaction COMING BACK"); 212 else 213 return message + " on coming back Required sees a transaction "+tx.hashCode() ; 214 } 215 216 public String requiredToRequiresNew() throws RemoteException{ 217 218 log.debug("TxSessionBean.requiredToRequiresNew() called"); 219 220 String message; 221 Object tx =getDaTransaction(); 222 if (tx == null) 223 throw new Error ("Required doesn't see a transaction"); 224 else 225 message = "Required sees a transaction "+tx.hashCode()+ " Requires new should see a new transaction "; 226 227 message = message + ((TxSession) sessionContext.getEJBObject()).txRequiresNew(); 228 229 tx =getDaTransaction(); 231 if (tx == null) 232 throw new Error ("Required doesn't see a transaction COMING BACK"); 233 else 234 return message + " on coming back Required sees a transaction "+tx.hashCode() ; 235 } 236 237 238 239 private Object getDaTransaction() { 240 241 try { 242 243 return ((javax.transaction.TransactionManager ) new InitialContext ().lookup("java:/TransactionManager")).getTransaction(); 244 } 245 catch (Exception e) { return null;} 246 } 247 248 } 249 | Popular Tags |