1 25 26 package lb; 27 28 import javax.ejb.CreateException; 29 import javax.ejb.DuplicateKeyException; 30 import javax.ejb.EJBException; 31 import javax.ejb.EntityBean; 32 import javax.ejb.EntityContext; 33 import javax.ejb.RemoveException; 34 35 39 public class ManacEC implements EntityBean { 40 41 EntityContext ejbContext; 42 43 public String name; 48 49 public int num; 50 51 public int balance; 52 53 57 66 public void setEntityContext(EntityContext ctx) { 67 ejbContext = ctx; 68 } 69 70 79 public void unsetEntityContext() { 80 ejbContext = null; 81 } 82 83 95 public void ejbRemove() throws RemoveException { 96 } 97 98 105 public void ejbLoad() { 106 if (balance < 0) { 107 System.out.println(name + " : Bad balance loaded"); 108 throw new EJBException("ejbLoad: Balance " + name + " was negative =" + balance); 109 } 110 } 111 112 119 public void ejbStore() { 120 if (balance < 0) { 121 System.out.println(name + " : Bad balance stored"); 122 throw new EJBException("ejbStore: Balance " + name + " was negative =" + balance); 123 } 124 } 125 126 131 public java.lang.String ejbCreate(int num, String name, int ib) throws CreateException, DuplicateKeyException { 132 133 this.num = num; 135 this.name = new String(name); 136 this.balance = ib; 137 138 return null; 140 } 141 142 146 public void ejbPostCreate(int num, String name, int ib) throws CreateException { 147 } 148 149 154 public java.lang.String ejbCreateWithDefaultName(int num, int ib) throws CreateException, DuplicateKeyException { 155 156 this.num = num; 158 this.name = "M" + (new Integer(num)).toString(); 159 this.balance = ib; 160 161 return null; 163 } 164 165 169 public void ejbPostCreateWithDefaultName(int num, int ib) throws CreateException { 170 } 171 172 176 public void ejbPassivate() { 177 balance = -80000; 180 } 181 182 187 public void ejbActivate() { 188 } 189 190 194 197 public int getBalance() { 198 return balance; 199 } 200 201 204 public void credit(int v) { 205 balance += v; 206 } 207 208 211 public void debit(int v) { 212 balance -= v; 213 if (balance < 0) { 214 System.out.println(name + " : set rollback only."); 215 ejbContext.setRollbackOnly(); 216 balance = -90000; } 219 } 220 221 public String getName() { 222 return name; 223 } 224 } | Popular Tags |