1 22 package org.jboss.test.jca.ejb; 23 24 import javax.ejb.EJBException ; 25 import javax.ejb.SessionBean ; 26 import javax.ejb.SessionContext ; 27 import javax.naming.InitialContext ; 28 import javax.transaction.UserTransaction ; 29 30 import org.jboss.logging.Logger; 31 import org.jboss.test.jca.adapter.TestConnection; 32 import org.jboss.test.jca.adapter.TestConnectionFactory; 33 34 48 public class UserTxSessionBean 49 implements SessionBean 50 { 51 52 53 private static final long serialVersionUID = 1L; 54 private SessionContext ctx; 55 private Logger log = Logger.getLogger(getClass()); 56 57 public UserTxSessionBean() 58 { 59 60 } 61 62 69 public boolean testUserTxJndi() 70 { 71 try 72 { 73 TestConnectionFactory tcf = (TestConnectionFactory)new InitialContext ().lookup("java:/JBossTestCF"); 74 TestConnection tc = (TestConnection)tcf.getConnection(); 75 UserTransaction ut = (UserTransaction )new InitialContext ().lookup("UserTransaction"); 76 ut.begin(); 77 boolean result = tc.isInTx(); 78 log.info("Jndi test, inTx: " + result); 79 ut.commit(); 80 tc.close(); 81 return result; 82 } 83 catch (Exception e) 84 { 85 throw new EJBException (e.getMessage()); 86 } 87 88 } 89 90 97 public boolean testUserTxSessionCtx() 98 { 99 try 100 { 101 TestConnectionFactory tcf = (TestConnectionFactory)new InitialContext ().lookup("java:/JBossTestCF"); 102 TestConnection tc = (TestConnection)tcf.getConnection(); 103 UserTransaction ut = ctx.getUserTransaction(); 104 ut.begin(); 105 boolean result = tc.isInTx(); 106 log.info("ctx test, inTx: " + result); 107 ut.commit(); 108 tc.close(); 109 return result; 110 } 111 catch (Exception e) 112 { 113 throw new EJBException (e.getMessage()); 114 } 115 116 } 117 118 121 public void testUnclosedError() throws Exception 122 { 123 TestConnectionFactory tcf = (TestConnectionFactory)new InitialContext ().lookup("java:/JBossTestCF"); 124 tcf.getConnection(); } 126 127 public void ejbCreate() 128 { 129 } 130 131 public void ejbActivate() 132 { 133 } 134 135 public void ejbPassivate() 136 { 137 } 138 139 public void ejbRemove() 140 { 141 } 142 143 public void setSessionContext(SessionContext ctx) 144 { 145 this.ctx = ctx; 146 } 147 148 public void unsetSessionContext() 149 { 150 this.ctx = null; 151 } 152 153 } 154 | Popular Tags |