1 22 package org.jboss.test.cmp2.fkmapping.ejb; 23 24 25 import javax.ejb.EntityBean ; 26 import javax.ejb.EntityContext ; 27 import javax.ejb.RemoveException ; 28 import javax.ejb.CreateException ; 29 30 31 50 public abstract class ChildCMPBean 51 implements EntityBean 52 { 53 private EntityContext ctx; 55 56 63 public abstract Long getId(); 64 public abstract void setId(Long id); 65 66 71 public abstract String getFirstName(); 72 public abstract void setFirstName(String name); 73 74 83 public abstract Long getMotherId(); 84 public abstract void setMotherId(Long id); 85 86 95 public abstract String getMotherName(); 96 public abstract void setMotherName(String name); 97 98 114 public abstract ParentLocal getMother(); 115 118 public abstract void setMother(ParentLocal parent); 119 120 124 public Long ejbCreate(Long childId, String firstName) 125 throws CreateException 126 { 127 setId(childId); 128 setFirstName(firstName); 129 return null; 130 } 131 132 public void ejbPostCreate(Long id, String firstName) {} 133 134 137 public Long ejbCreate(Long childId, String firstName, Long parentId, String parentName) 138 throws CreateException 139 { 140 setId(childId); 141 setFirstName(firstName); 142 return null; 143 } 144 145 public void ejbPostCreate(Long id, String firstName, Long parentId, String parentName) 146 throws CreateException 147 { 148 ParentLocal parent = null; 149 try 150 { 151 parent = ParentUtil.getLocalHome().findByPrimaryKey(new ParentPK(parentId, parentName)); 154 } 155 catch(Exception e) 156 { 157 throw new CreateException ("Could not create relationship: " + e.getMessage()); 158 } 159 160 setMother(parent); 161 162 if(!id.equals(ctx.getPrimaryKey())) 163 throw new IllegalStateException ("Primary key is not available in ejbPostCreate."); 164 165 if(ctx.getEJBLocalObject() == null) 166 throw new IllegalStateException ("Local object is not available in ejbPostCreate."); 167 } 168 169 172 public void setEntityContext(EntityContext ctx) 173 { 174 this.ctx = ctx; 175 } 176 177 180 public void unsetEntityContext() 181 { 182 this.ctx = null; 183 } 184 185 public void ejbActivate() {} 186 public void ejbLoad() {} 187 public void ejbPassivate() {} 188 public void ejbRemove() throws RemoveException {} 189 public void ejbStore() {} 190 } 191 | Popular Tags |