1 22 package org.jboss.test.testbean.bean; 23 24 import java.rmi.*; 25 import javax.ejb.*; 26 import javax.naming.InitialContext ; 27 import javax.naming.Context ; 28 import org.jboss.test.testbean.interfaces.BMTStateful; 29 import javax.transaction.UserTransaction ; 30 import javax.transaction.Status ; 31 32 33 public class BMTStatelessBean implements SessionBean { 34 org.jboss.logging.Logger log = org.jboss.logging.Logger.getLogger(getClass()); 35 36 private SessionContext sessionContext; 37 38 public void ejbCreate() throws RemoteException, CreateException { 39 log.debug("BMTStatelessBean.ejbCreate() called"); 40 } 41 42 public void ejbActivate() throws RemoteException { 43 log.debug("BMTStatelessBean.ejbActivate() called"); 44 } 45 46 public void ejbPassivate() throws RemoteException { 47 log.debug("BMTStatelessBean.ejbPassivate() called"); 48 } 49 50 public void ejbRemove() throws RemoteException { 51 log.debug("BMTStatelessBean.ejbRemove() called"); 52 } 53 54 public void setSessionContext(SessionContext context) throws RemoteException { 55 sessionContext = context; 56 } 57 58 public String txExists() throws RemoteException { 59 String result = ""; 60 try { 61 UserTransaction ut1 = sessionContext.getUserTransaction(); 62 result += "Got UserTransaction via sessionContext.getUserTransaction()\n"; 63 64 UserTransaction ut2 = (UserTransaction )new InitialContext ().lookup("java:comp/UserTransaction"); 65 result += "Got UserTransaction via lookup(java:comp/UserTransaction)\n"; 66 return result; 67 } catch (Exception e) { 68 throw new RemoteException(e.getMessage()); 69 } 70 } 71 72 73 public String txCommit() throws RemoteException { 74 try { 75 UserTransaction tx = sessionContext.getUserTransaction(); 76 77 String result = "Got transaction : " + statusName(tx.getStatus()) + "\n"; 78 tx.begin(); 79 result += "tx.begin(): " + statusName(tx.getStatus()) + "\n"; 80 tx.commit(); 81 result += "tx.commit(): " + statusName(tx.getStatus()) + "\n"; 82 83 return result; 84 85 } catch (Exception e) { 86 log.debug("failed", e); 87 throw new RemoteException(e.getMessage()); 88 } 89 90 } 91 92 public String txRollback() throws RemoteException { 93 try { 94 UserTransaction tx = sessionContext.getUserTransaction(); 95 96 String result = "Got transaction : " + statusName(tx.getStatus()) + "\n"; 97 tx.begin(); 98 result += "tx.begin(): " + statusName(tx.getStatus()) + "\n"; 99 tx.rollback(); 100 result += "tx.rollback(): " + statusName(tx.getStatus()) + "\n"; 101 102 return result; 103 104 } catch (Exception e) { 105 throw new RemoteException(e.getMessage()); 106 } 107 } 108 109 110 111 public String txBegin() throws RemoteException { 113 try { 114 UserTransaction tx = sessionContext.getUserTransaction(); 115 116 tx.begin(); 117 return "status: " + statusName(tx.getStatus()); 118 } catch (Exception e) { 119 throw new RemoteException(e.getMessage()); 120 } 121 122 } 123 124 private String statusName(int s) { 125 switch (s) { 126 case Status.STATUS_ACTIVE: return "STATUS_ACTIVE"; 127 case Status.STATUS_COMMITTED: return "STATUS_COMMITED"; 128 case Status.STATUS_COMMITTING: return "STATUS_COMMITTING"; 129 case Status.STATUS_MARKED_ROLLBACK: return "STATUS_MARKED_ROLLBACK"; 130 case Status.STATUS_NO_TRANSACTION: return "STATUS_NO_TRANSACTION"; 131 case Status.STATUS_PREPARED: return "STATUS_PREPARED"; 132 case Status.STATUS_PREPARING: return "STATUS_PREPARING"; 133 case Status.STATUS_ROLLEDBACK: return "STATUS_ROLLEDBACK"; 134 case Status.STATUS_ROLLING_BACK: return "STATUS_ROLLING_BACK"; 135 case Status.STATUS_UNKNOWN: return "STATUS_UNKNOWN"; 136 } 137 return "REALLY_UNKNOWN"; 138 } 139 140 } 141 | Popular Tags |