1 4 package org.objectweb.jonas.jtests.beans.j2eeca; 5 6 import javax.ejb.CreateException ; 7 import javax.ejb.SessionBean ; 8 import javax.ejb.SessionContext ; 9 import javax.naming.InitialContext ; 10 import javax.resource.cci.LocalTransaction ; 11 import javax.resource.spi.ConnectionEvent ; 12 import javax.transaction.xa.Xid ; 13 14 import org.objectweb.jonas.common.Log; 15 import org.objectweb.util.monolog.api.BasicLevel; 16 import org.objectweb.util.monolog.api.Logger; 17 18 import fictional.resourceadapter.CommonClient; 19 import fictional.resourceadapter.ConnectionImpl; 20 import fictional.resourceadapter.JtestResourceAdapter; 21 import fictional.resourceadapter.LocalTransactionImpl; 22 import fictional.resourceadapter.XAResourceImpl; 23 24 25 28 public class transactedCASLR implements SessionBean { 29 30 static private Logger logger = null; 31 SessionContext ejbContext; 32 private JtestResourceAdapter mcf = null; private CommonClient csp = null; private CommonClient cccf = null; private ConnectionImpl conn = null; 36 InitialContext ic=null; 37 String cName = "transactedCASLR"; 38 final public int NoTransaction = 0; 39 final public int LoTransaction = 1; 40 final public int XATransaction = 2; 41 final public int CLOSE_HANDLE = 0; 42 final public int CLOSE_PHYSICAL = 1; 43 public int TransactionType = 0; 44 45 49 50 public void setSessionContext(SessionContext ctx) { 51 if (logger == null) { 52 logger = Log.getLogger("org.objectweb.jonas.jtests.j2eeca"); 53 } 54 logger.log(BasicLevel.DEBUG, cName+".setSessionContext"); 55 ejbContext = ctx; 56 } 57 58 59 public void ejbRemove() { 60 logger.log(BasicLevel.DEBUG, ""); 61 } 62 63 64 public void ejbCreate() throws CreateException { 65 logger.log(BasicLevel.DEBUG, ""); 66 } 67 68 public void ejbPassivate() { 69 logger.log(BasicLevel.DEBUG, ""); 70 } 71 72 public void ejbActivate() { 73 logger.log(BasicLevel.DEBUG, ""); 74 } 75 78 public void closeUp(int closeType) { 79 logger.log(BasicLevel.DEBUG, cName+ 80 ".closeUp (enter) closeType="+closeType); 81 try { 82 if (closeType==CLOSE_PHYSICAL) { 83 conn.close(ConnectionEvent.CONNECTION_ERROR_OCCURRED); 86 logger.log(BasicLevel.DEBUG, cName+ 87 ".closeUp (exit) : closed physical connection closeType="+closeType+ 88 " ConnectionEvent.CONNECTION_ERROR_OCCURRED="+ 89 ConnectionEvent.CONNECTION_ERROR_OCCURRED); 90 } else { 91 conn.close(); 94 logger.log(BasicLevel.DEBUG, cName+ 95 ".closeUp (exit) : closed connection closeType="+closeType); 96 } 97 } catch (Exception e) { 98 logger.log(BasicLevel.DEBUG, cName+".closeUp (exit) error: close "+ 99 "handle/physical connection failed closeType="+closeType); 100 } 101 } 102 103 107 110 public void method1(String rar_jndi_name, String testName) 111 throws Exception 112 { 113 logger.log(BasicLevel.DEBUG, "============================ "+testName); 114 115 if ("FictionalXATransaction".equals(rar_jndi_name)) 116 TransactionType = XATransaction; 117 else if ("FictionalLoTransaction".equals(rar_jndi_name)) 118 TransactionType = LoTransaction; 119 else 120 TransactionType = NoTransaction; 121 122 try { 123 ic = new InitialContext (); 124 } catch (Exception e1) { 125 logger.log(BasicLevel.DEBUG, cName+".method1 error: InitialContext failed"); 126 throw e1; 127 } 128 try { 129 cccf = (CommonClient)ic.lookup(rar_jndi_name); 130 logger.log(BasicLevel.DEBUG, cName+".method1 : found "+rar_jndi_name); 131 } catch (Exception e2) { 132 logger.log(BasicLevel.DEBUG, cName+".method1 error: lookup failed for "+rar_jndi_name); 133 throw e2; 134 } 135 136 try { 137 csp = new CommonClient(); 139 } catch (Exception e3) { 140 logger.log(BasicLevel.DEBUG, cName+".method1 : new connection spec failed"); 141 throw e3; 142 } 143 try { 144 conn = (ConnectionImpl)cccf.getConnection(); 145 logger.log(BasicLevel.DEBUG, cName+".method1 : getConnection conn="+conn); 146 if (conn==null) { 147 logger.log(BasicLevel.DEBUG, cName+".method1 error: getConnection returned null connection."); 148 throw new Exception (""); 149 } 150 } catch (Exception e4) { 151 logger.log(BasicLevel.DEBUG, cName+".method1 error: getConnection failed " 152 +e4.toString()); 153 throw e4; 154 } 155 } 156 public String getXid() { 157 ConnectionImpl conni = (ConnectionImpl)conn; 158 try { 159 JtestResourceAdapter mc = (JtestResourceAdapter)conni.getMC(); XAResourceImpl xar = mc.getCurrentXar(); 161 if (xar==null) { 162 logger.log(BasicLevel.DEBUG, cName+".getXid error: failed xar==null"); 163 return "FAIL"; 164 } else { 165 Xid xid = xar.getCurrentXid(); 166 logger.log(BasicLevel.DEBUG, cName+".getXid "); 167 return "OK"; 168 } 169 } catch (Exception e) { 170 logger.log(BasicLevel.DEBUG, cName+".getXid error: failed"); 171 return "FAIL"; 172 } 173 } 174 179 public boolean getCMInstance() 180 { 181 mcf = (JtestResourceAdapter) cccf.getMcf(); if (mcf.getCM()==null) { logger.log(BasicLevel.DEBUG, cName+".getCMInstance error: ConnectionManager is null"); 184 return false; 185 } 186 else { 187 logger.log(BasicLevel.DEBUG, cName+".getCMInstance ConnectionManager is o.k."); 188 return true; 189 } 190 } 191 LocalTransactionImpl lt=null; 192 public void beginLoTransaction() { 193 logger.log(BasicLevel.DEBUG, cName+".beginLoTransaction (enter)"); 194 try { 195 LocalTransaction l = conn.getLocalTransaction(); 196 lt = (LocalTransactionImpl) l; 197 lt.begin(); 198 int s=lt.getTxState(); 199 logger.log(BasicLevel.DEBUG, cName+".beginLoTransaction (exit) State="+s); 200 } catch (Exception e) { 201 logger.log(BasicLevel.DEBUG, cName+".beginLoTransaction (exit) error:" 202 +" "+e.toString()); 203 204 } 205 } 206 public void commitLoTransaction() throws Exception 207 { 208 logger.log(BasicLevel.DEBUG, cName+".commitLoTransaction (enter)"); 209 try { 210 if (lt==null) { 211 Exception e = new Exception ("Undefined LocalTransaction"); 212 throw e; 213 } 214 lt.commit(); 215 int s=lt.getTxState(); 216 logger.log(BasicLevel.DEBUG, cName+".commitLoTransaction (exit) ="+s); 217 } catch (Exception e) { 218 logger.log(BasicLevel.DEBUG, cName+".commitLoTransaction (exit) error: State error." 219 +" "+e.getMessage()); 220 throw e; 221 } 222 lt=null; 223 } 224 public void rollbackLoTransaction() { 225 logger.log(BasicLevel.DEBUG, cName+".rollbackLoTransaction (enter)"); 226 try { 227 if (lt==null) { 228 Exception e = new Exception ("Undefined LocalTransaction"); 229 throw e; 230 } 231 lt.rollback(); 232 int s=lt.getTxState(); 233 logger.log(BasicLevel.DEBUG, cName+".rollbackLoTransaction (exit) State="+s); 234 } catch (Exception e) { 235 logger.log(BasicLevel.DEBUG, cName+".rollbackLoTransaction (exit) error: State error" 236 +" "+e.getMessage()); 237 238 } 239 lt=null; 240 } 241 } 242 243 | Popular Tags |