1 22 package org.jboss.test.entity.ejb; 23 24 import java.rmi.RemoteException ; 25 26 import javax.ejb.CreateException ; 27 import javax.ejb.EJBException ; 28 import javax.ejb.SessionBean ; 29 import javax.ejb.SessionContext ; 30 import javax.naming.InitialContext ; 31 32 import org.jboss.test.entity.interfaces.EntitySession; 33 import org.jboss.test.entity.interfaces.EntitySessionHome; 34 import org.jboss.test.entity.interfaces.Pathological; 35 import org.jboss.test.entity.interfaces.PathologicalEntity; 36 import org.jboss.test.entity.interfaces.PathologicalEntityHome; 37 38 44 public class EntitySessionBean 45 implements SessionBean 46 { 47 private transient SessionContext ctx; 48 49 public void createPathological(String name, boolean pathological) 50 { 51 Pathological.setPathological(pathological); 52 try 53 { 54 PathologicalEntityHome home = getPathologicalEJB(); 55 home.create(name); 56 } 57 catch (Throwable e) 58 { 59 check(e); 60 } 61 finally 62 { 63 Pathological.setPathological(false); 64 } 65 } 66 67 public void removeHomePathological(String name, boolean pathological) 68 { 69 Pathological.setPathological(pathological); 70 try 71 { 72 PathologicalEntityHome home = getPathologicalEJB(); 73 home.remove(name); 74 } 75 catch (Throwable e) 76 { 77 check(e); 78 } 79 finally 80 { 81 Pathological.setPathological(false); 82 } 83 } 84 85 public void removePathological(String name, boolean pathological) 86 { 87 try 88 { 89 PathologicalEntityHome home = getPathologicalEJB(); 90 PathologicalEntity bean = home.findByPrimaryKey(name); 91 Pathological.setPathological(pathological); 92 bean.remove(); 93 } 94 catch (Throwable e) 95 { 96 check(e); 97 } 98 finally 99 { 100 Pathological.setPathological(false); 101 } 102 } 103 104 public void findPathological(String name, boolean pathological) 105 { 106 Pathological.setPathological(pathological); 107 try 108 { 109 PathologicalEntityHome home = getPathologicalEJB(); 110 home.findByPrimaryKey(name); 111 } 112 catch (Throwable e) 113 { 114 check(e); 115 } 116 finally 117 { 118 Pathological.setPathological(false); 119 } 120 } 121 122 public void getPathological(String name, boolean pathological) 123 { 124 try 125 { 126 PathologicalEntityHome home = getPathologicalEJB(); 127 PathologicalEntity bean = home.findByPrimaryKey(name); 128 Pathological.setPathological(pathological); 129 bean.getSomething(); 130 } 131 catch (Throwable e) 132 { 133 check(e); 134 } 135 finally 136 { 137 Pathological.setPathological(false); 138 } 139 } 140 141 public void setPathological(String name, boolean pathological) 142 { 143 try 144 { 145 PathologicalEntityHome home = getPathologicalEJB(); 146 PathologicalEntity bean = home.findByPrimaryKey(name); 147 Pathological.setPathological(pathological); 148 bean.setSomething("something"); 149 } 150 catch (Throwable e) 151 { 152 check(e); 153 } 154 finally 155 { 156 Pathological.setPathological(false); 157 } 158 } 159 160 public void ejbCreate() 161 throws CreateException 162 { 163 } 164 165 public void setSessionContext(SessionContext ctx) 166 { 167 this.ctx = ctx; 168 } 169 170 public void ejbActivate() 171 { 172 } 173 174 public void ejbPassivate() 175 { 176 } 177 178 public void ejbRemove() 179 { 180 } 181 182 private void check(Throwable e) 183 { 184 while (true) 185 { 186 if (e instanceof EJBException ) 187 e = ((EJBException ) e).getCausedByException(); 188 else if (e instanceof RemoteException ) 189 e = ((RemoteException ) e).detail; 190 else if (e instanceof IllegalStateException ) 191 throw (IllegalStateException ) e; 192 else 193 return; 194 } 195 } 196 197 private PathologicalEntityHome getPathologicalEJB() 198 throws Exception 199 { 200 return (PathologicalEntityHome) new InitialContext ().lookup("java:comp/env/ejb/PathologicalEJB"); 201 } 202 } 203 | Popular Tags |