1 28 29 package sb; 30 31 import javax.ejb.EJBException; 32 import javax.ejb.SessionBean; 33 import javax.ejb.SessionContext; 34 import javax.ejb.SessionSynchronization; 35 import javax.naming.InitialContext; 36 import javax.naming.NamingException; 37 38 42 public class OpBean implements SessionBean, SessionSynchronization { 43 44 47 private int total = 0; 48 49 52 private int newtotal = 0; 53 54 57 private String clientUser = null; 58 59 60 61 62 67 public void ejbCreate(String user) { 68 69 total = 0; 70 newtotal = total; clientUser = user; 72 } 73 74 78 79 94 public void ejbActivate() throws EJBException, java.rmi.RemoteException { 95 } 97 98 115 public void ejbPassivate() throws EJBException, java.rmi.RemoteException { 116 } 118 119 134 public void ejbRemove() throws EJBException, java.rmi.RemoteException { 135 } 137 138 154 public void setSessionContext(SessionContext sessionContext) throws EJBException, java.rmi.RemoteException { 155 156 } 157 158 162 163 180 public void afterBegin() throws EJBException, java.rmi.RemoteException { 181 newtotal = total; 182 } 183 184 202 public void beforeCompletion() throws EJBException, java.rmi.RemoteException { 203 205 try { 208 InitialContext ictx = new InitialContext(); 209 String value = (String) ictx.lookup("java:comp/env/prop1"); 210 } catch (NamingException e) { 212 throw new EJBException(e); 213 } 214 } 215 216 233 public void afterCompletion(boolean committed) throws EJBException, java.rmi.RemoteException { 234 if (committed) { 235 total = newtotal; 236 } else { 237 newtotal = total; 238 } 239 } 240 241 242 243 247 public void buy(int s) { 248 newtotal = newtotal + s; 249 return; 250 } 251 252 256 public int read() { 257 return newtotal; 258 } 259 } | Popular Tags |