1 25 26 package org.objectweb.jonas.jtests.beans.transacted; 27 28 import javax.ejb.CreateException ; 29 import javax.ejb.EJBException ; 30 import javax.ejb.RemoveException ; 31 import javax.ejb.SessionSynchronization ; 32 import javax.naming.Context ; 33 import javax.naming.InitialContext ; 34 import javax.naming.NamingException ; 35 import javax.rmi.PortableRemoteObject ; 36 37 import org.objectweb.util.monolog.api.BasicLevel; 38 39 42 public class SimpleSY extends SimpleSL implements SessionSynchronization { 43 44 private boolean rollbackonly = false; 45 private Context ictx = null; 46 private SimpleELocalHome lhome = null; 47 48 49 53 56 public void setRollbackOnly() { 57 logger.log(BasicLevel.DEBUG, ""); 58 rollbackonly = true; 59 } 60 61 64 public boolean call_requires_new_local() { 65 logger.log(BasicLevel.DEBUG, ""); 66 SimpleLocal loc = getLocalBean(); 67 boolean tx = loc.opwith_requires_new(); 68 if (!tx) { 69 logger.log(BasicLevel.ERROR, "opwith_requires_new was outside tx"); 70 return false; } 72 try { 73 loc.remove(); } catch (RemoveException e) { 75 logger.log(BasicLevel.ERROR, "cannot remove local bean"); 76 } 77 return isAssociated(); 78 } 79 80 83 public boolean call_notsupported_local() { 84 logger.log(BasicLevel.DEBUG, ""); 85 SimpleLocal loc = getLocalBean(); 86 boolean tx = loc.opwith_notsupported(); 87 if (tx) { 88 logger.log(BasicLevel.ERROR, "opwith_notsupported was in tx"); 89 return false; } 91 try { 92 loc.remove(); } catch (RemoveException e) { 94 logger.log(BasicLevel.ERROR, "cannot remove local bean"); 95 } 96 return isAssociated(); 97 } 98 99 103 112 public void afterBegin() { 113 logger.log(BasicLevel.DEBUG, ""); 114 } 115 116 117 128 public void beforeCompletion() { 129 logger.log(BasicLevel.DEBUG, ""); 130 if (rollbackonly) { 131 sessionContext.setRollbackOnly(); 132 } 133 } 134 135 136 148 public void afterCompletion(boolean committed) { 149 logger.log(BasicLevel.DEBUG, ""); 150 } 151 152 156 160 private void stateUpdate() throws NamingException { 161 if (ictx == null) { 163 ictx = new InitialContext (); 164 } 165 if (lhome == null) { 167 lhome = (SimpleELocalHome) ictx.lookup("java:comp/env/ejb/SimpleEC"); 168 } 169 } 170 171 174 private SimpleLocal getLocalBean() { 175 SimpleLocal ret = null; 176 try { 177 stateUpdate(); 178 } catch (NamingException e) { 179 logger.log(BasicLevel.ERROR, "getLocalBean raised exception "+e); 180 throw new EJBException ("Error in getLocalBean:"+e); 181 } 182 try { 183 ret = lhome.create(123); 184 } catch (CreateException e) { 185 logger.log(BasicLevel.ERROR, "Cannot create local entity bean "+e); 186 throw new EJBException ("Cannot create local entity bean:"+e); 187 } 188 return ret; 189 } 190 } 191 | Popular Tags |