1 25 26 package org.objectweb.jonas.jtests.beans.beanexc; 27 28 import javax.ejb.EntityBean ; 29 import javax.ejb.EntityContext ; 30 import javax.ejb.EJBContext ; 31 import javax.ejb.RemoveException ; 32 import javax.ejb.CreateException ; 33 34 import org.objectweb.jonas.common.Log; 35 import org.objectweb.util.monolog.api.BasicLevel; 36 37 42 public abstract class AccountEC2 extends AccountCommon implements EntityBean { 43 44 boolean forceToFailEjbStore; 45 protected EntityContext entityContext; 46 47 48 public abstract int getNumber(); 50 public abstract void setNumber(int n); 51 public abstract long getBalance(); 52 public abstract void setBalance(long d); 53 public abstract String getCustomer(); 54 public abstract void setCustomer(String c); 55 56 57 58 public EJBContext getContext() { 59 return entityContext; 60 } 61 62 public void ejbActivate() { 63 logger.log(BasicLevel.DEBUG, ""); 64 } 65 66 public void ejbPassivate() { 67 logger.log(BasicLevel.DEBUG, ""); 68 } 69 70 public void ejbLoad() { 71 logger.log(BasicLevel.DEBUG, ""); 72 } 73 74 public void ejbStore() { 75 logger.log(BasicLevel.DEBUG, ""); 76 if (forceToFailEjbStore) { 77 forceToFailEjbStore = false; 78 throw new RuntimeException ("RunTimeExceptionInEjbStore"); 79 } 80 } 81 82 88 public void ejbRemove() throws RemoveException { 89 logger.log(BasicLevel.DEBUG, ""); 90 AccountPK pk = (AccountPK) entityContext.getPrimaryKey(); 91 if ((pk.number >= 999990) && (pk.number <= 999999)) { 92 logger.log(BasicLevel.DEBUG, 93 "RemoveException throwned by bean provider in ejbRemove"); 94 throw new RemoveException ("RemoveException throwned by bean provider in ejbRemove"); 95 } 96 } 97 98 public void setEntityContext(EntityContext ctx) { 99 if (logger == null) { 100 logger = Log.getLogger(Log.JONAS_TESTS_PREFIX); 101 } 102 logger.log(BasicLevel.DEBUG, ""); 103 entityContext = ctx; 104 } 105 106 public void unsetEntityContext() { 107 logger.log(BasicLevel.DEBUG, ""); 108 entityContext = null; 109 } 110 111 public AccountPK ejbCreate(int val_number, String val_customer, long val_balance) throws CreateException { 112 logger.log(BasicLevel.DEBUG, ""); 113 setNumber(val_number); 114 setCustomer(val_customer); 115 setBalance(val_balance); 116 return (null); 117 } 118 119 125 public AccountPK ejbCreate(int flag) throws CreateException , AppException { 126 logger.log(BasicLevel.DEBUG, ""); 127 setNumber(1951); 128 setCustomer("Myself"); 129 setBalance(10000); 130 if (flag == 0) { 131 entityContext.setRollbackOnly(); 132 throw new AppException("AppException in ejbCreate(boolean)"); 133 } else { 134 int zero = 0; 135 float f = 10 / zero; 136 } 137 return (null); 138 } 139 140 145 public AccountPK ejbCreate(boolean flag) throws CreateException , AppException { 146 logger.log(BasicLevel.DEBUG, ""); 147 setNumber(1951); 148 setCustomer("Myself"); 149 setBalance(10000); 150 if (flag) { 151 throw new AppException("AppException in ejbCreate(boolean)"); 152 } else { 153 int zero = 0; 154 float f = 10 / zero; 155 } 156 return (null); 157 } 158 159 public void ejbPostCreate(int val_number, String val_customer, long val_balance) { 160 logger.log(BasicLevel.DEBUG, ""); 161 } 162 163 public void ejbPostCreate(int flag) { 164 logger.log(BasicLevel.DEBUG, ""); 165 } 166 167 public void ejbPostCreate(boolean flag) { 168 logger.log(BasicLevel.DEBUG, ""); 169 } 170 171 public void doFailedEjbStore_1() { 172 logger.log(BasicLevel.DEBUG, ""); 173 setBalance(1000); 174 forceToFailEjbStore = true; 175 } 176 public void doFailedEjbStore_2() { 177 logger.log(BasicLevel.DEBUG, ""); 178 setBalance(2000); 179 forceToFailEjbStore = true; 180 } 181 public void doFailedEjbStore_3() { 182 logger.log(BasicLevel.DEBUG, ""); 183 setBalance(3000); 184 forceToFailEjbStore = true; 185 } 186 187 } 188 189 | Popular Tags |