1 28 29 package sampleappli; 32 33 import java.rmi.RemoteException; 34 35 import javax.ejb.CreateException; 36 import javax.ejb.DuplicateKeyException; 37 import javax.ejb.EJBException; 38 import javax.ejb.EntityBean; 39 import javax.ejb.EntityContext; 40 import javax.ejb.FinderException; 41 import javax.ejb.ObjectNotFoundException; 42 import javax.ejb.RemoveException; 43 import javax.naming.Context; 44 import javax.naming.InitialContext; 45 import javax.naming.NamingException; 46 import javax.sql.DataSource; 47 import javax.transaction.NotSupportedException; 48 49 52 public class StockBean implements EntityBean { 53 54 EntityContext ejbContext; 55 56 public String stockid; 61 62 public int stockqty; 63 64 68 77 public void setEntityContext(EntityContext ctx) { 78 ejbContext = ctx; 79 } 80 81 90 public void unsetEntityContext() { 91 ejbContext = null; 92 } 93 94 106 public void ejbRemove() throws RemoveException { 107 } 108 109 116 public void ejbLoad() { 117 } 118 119 126 public void ejbStore() { 127 } 128 129 133 public void ejbPostCreate(String id, int qty) throws CreateException { 134 } 135 136 141 public java.lang.String ejbCreate(String id, int qty) throws CreateException, DuplicateKeyException { 142 143 stockid = id; 145 stockqty = qty; 146 147 return null; 149 } 150 151 155 public void ejbPassivate() { 156 } 157 158 163 public void ejbActivate() { 164 } 165 166 170 173 public void increaseQuantity(int qty) { 174 stockqty += qty; 175 } 176 177 180 public void decreaseQuantity(int qty) throws RemoteException { 181 stockqty = stockqty - qty; 182 if (stockqty < 0) { 183 throw new RemoteException("Negative stock"); 184 } 185 } 186 187 190 public int getQuantity() throws RemoteException { 191 return stockqty; 192 } 193 194 197 public void setQuantity(int qty) throws RemoteException { 198 stockqty = qty; 199 } 200 201 204 public String getId() throws RemoteException { 205 return stockid; 206 } 207 } | Popular Tags |