1 2 8 29 package org.jboss.test.deadlock.bean; 30 31 import java.util.Arrays ; 32 33 import javax.ejb.*; 34 35 import org.jboss.ejb.plugins.TxInterceptorCMT; 36 import org.jboss.test.deadlock.interfaces.BeanOrder; 37 import org.jboss.test.deadlock.interfaces.EnterpriseEntityLocalHome; 38 import org.jboss.test.deadlock.interfaces.EnterpriseEntityLocal; 39 import org.jboss.test.deadlock.interfaces.EnterpriseEntityHome; 40 import org.jboss.test.deadlock.interfaces.EnterpriseEntity; 41 42 public abstract class EnterpriseEntityBean implements EntityBean 43 { 44 org.jboss.logging.Logger log = org.jboss.logging.Logger.getLogger(getClass()); 45 46 private EntityContext entityContext; 47 public int otherField = 0; 48 49 public String ejbCreate(String name) throws CreateException { 50 setName(name); 51 return null; 52 } 53 54 public void ejbPostCreate(String name) throws CreateException { 55 56 57 EJBLocalObject ejbObject = entityContext.getEJBLocalObject(); 58 59 if (ejbObject == null) { 60 log.debug("******************************* NULL EJBOBJECT in ejbPostCreate"); 61 } 62 else { 63 log.debug("&&&&&&&&&&&&&&&& EJBObject found in ejbPostCreate id is "+ejbObject.getPrimaryKey()); 64 } 65 66 } 67 68 public void ejbActivate() { 69 } 70 71 public void ejbLoad() { 72 } 73 74 public void ejbPassivate() { 75 76 } 77 78 public void ejbRemove() throws RemoveException { 79 } 80 81 public void ejbStore() { 82 83 } 84 85 public abstract String getName(); 86 87 public abstract void setName(String name); 88 89 public String callBusinessMethodA() { 90 91 return "EntityBean.callBusinessMethodA() called, my primaryKey is "+ 92 entityContext.getPrimaryKey().toString(); 93 } 94 95 public String callBusinessMethodB() { 96 97 98 EJBObject ejbObject = entityContext.getEJBObject(); 99 100 if (ejbObject == null) 101 return "NULL EJBOBJECT"; 102 103 else 104 return ejbObject.toString(); 105 } 106 107 108 public String callBusinessMethodB(String words) { 109 110 111 EJBObject ejbObject = entityContext.getEJBObject(); 112 113 if (ejbObject == null) 114 return "NULL EJBOBJECT"; 115 116 else 117 return ejbObject.toString()+ " words "+words; 118 119 } 120 121 public abstract void setOtherField(int value); 122 123 public abstract int getOtherField(); 124 125 public abstract void setNext(EnterpriseEntityLocal next); 126 127 public abstract EnterpriseEntityLocal getNext(); 128 129 public void callAnotherBean(BeanOrder beanOrder) 130 { 131 if (beanOrder.next == beanOrder.order.length-1) 133 return; 134 135 try 137 { 138 EnterpriseEntityLocalHome home = (EnterpriseEntityLocalHome)entityContext.getEJBLocalObject().getEJBLocalHome(); 139 beanOrder.next++; 140 EnterpriseEntityLocal nextBean = home.findByPrimaryKey(beanOrder.order[beanOrder.next]); 141 try 142 { 143 nextBean.callAnotherBean(beanOrder); 144 } 145 finally 146 { 147 beanOrder.next--; 148 } 149 } 150 catch (Exception e) 151 { 152 Exception a = TxInterceptorCMT.isADE(e); 153 if (a == null) 154 { 155 log.error("Error next=" + beanOrder.next + " order=" + Arrays.asList(beanOrder.order), e); 156 throw new EJBException("callAnotherBean failed " + e.toString()); 157 } 158 else 159 { 160 throw new EJBException ("ADE", a); 161 } 162 } 163 } 164 165 public EnterpriseEntity createEntity(String newName) { 166 167 EnterpriseEntity newBean; 168 try{ 169 EJBObject ejbObject = entityContext.getEJBObject(); 170 if (ejbObject == null) 171 log.debug("************************** NULL EJBOBJECT"); 172 else 173 log.debug("************************** OK EJBOBJECT"); 174 175 EnterpriseEntityHome home = (EnterpriseEntityHome)entityContext.getEJBObject().getEJBHome(); 176 newBean = (EnterpriseEntity)home.create(newName); 177 178 179 }catch(Exception e) 180 { 181 log.debug("failed", e); 182 throw new EJBException("create entity did not work check messages"); 183 } 184 185 return newBean; 186 } 187 188 public void setEntityContext(EntityContext context) { 189 entityContext = context; 190 } 191 192 public void unsetEntityContext() { 193 entityContext = null; 194 } 195 } 196 | Popular Tags |