1 25 26 package org.objectweb.jonas.jtests.beans.relation.omb; 27 28 import org.objectweb.jonas.common.Log; 29 import org.objectweb.util.monolog.api.BasicLevel; 30 import org.objectweb.util.monolog.api.Logger; 31 32 import javax.ejb.CreateException ; 33 import javax.ejb.DuplicateKeyException ; 34 import javax.ejb.EntityContext ; 35 import javax.ejb.RemoveException ; 36 import javax.ejb.FinderException ; 37 import javax.ejb.EJBException ; 38 import javax.naming.Context ; 39 import javax.naming.InitialContext ; 40 import javax.naming.NamingException ; 41 import javax.rmi.PortableRemoteObject ; 42 43 import java.util.Collection ; 44 import java.util.ArrayList ; 45 import java.util.Iterator ; 46 import java.util.List ; 47 48 51 public abstract class AEC2 implements javax.ejb.EntityBean { 52 53 private BHomeLocal bhl = null; 54 55 public void m1(){ 56 } 57 58 public void assignB(Collection c) throws FinderException { 59 logger.log(BasicLevel.DEBUG, ""); 60 ArrayList al = new ArrayList (c.size()); 61 for(Iterator it = c.iterator(); it.hasNext();) 62 al.add(bhl.findByPrimaryKey((String ) it.next())); 63 setB(al); 64 } 65 public void assignBInNewTx(Collection c) throws FinderException { 66 logger.log(BasicLevel.DEBUG, ""); 67 assignB(c); 68 } 69 70 public Collection retrieveB() { 71 logger.log(BasicLevel.DEBUG, ""); 72 Collection bs = getB(); 73 ArrayList result = new ArrayList (bs.size()); 74 for(Iterator it = bs.iterator(); it.hasNext();) 75 result.add(((BLocal) it.next()).getPrimaryKey()); 76 return result; 77 } 78 public Collection retrieveBInNewTx() { 79 logger.log(BasicLevel.DEBUG, ""); 80 return retrieveB(); 81 } 82 public Collection retrieveBisB() { 83 logger.log(BasicLevel.DEBUG, ""); 84 List bs = new ArrayList (getB()); 87 ArrayList result = new ArrayList (bs.size()); 88 for(Iterator it = bs.iterator(); it.hasNext();) 89 result.add(((BLocal) it.next()).getPrimaryKey()); 90 return result; 91 } 92 93 public void addInB(String pkb) throws FinderException { 94 logger.log(BasicLevel.DEBUG, ""); 95 getB().add(bhl.findByPrimaryKey(pkb)); 96 } 97 public void addInBInNewTx(String pkb) throws FinderException { 98 logger.log(BasicLevel.DEBUG, ""); 99 addInB(pkb); 100 } 101 102 public void addNewB(String pkb) throws CreateException , FinderException { 103 logger.log(BasicLevel.DEBUG, ""); 104 BLocal bl = bhl.create(pkb); 105 getB().add(bl); 106 bhl.findByName(pkb, getId()); 107 } 108 109 public void addAllInB(Collection pkbs) throws FinderException { 110 logger.log(BasicLevel.DEBUG, ""); 111 ArrayList al = new ArrayList (); 112 for (Iterator it = pkbs.iterator(); it.hasNext();) 113 al.add(bhl.findByPrimaryKey((String ) it.next())); 114 getB().addAll(al); 115 } 116 public void addAllInBInNewTx(Collection pkbs) throws FinderException { 117 logger.log(BasicLevel.DEBUG, ""); 118 addAllInB(pkbs); 119 } 120 121 public void removeFromB(String pkb) throws FinderException { 122 logger.log(BasicLevel.DEBUG, ""); 123 getB().remove(bhl.findByPrimaryKey(pkb)); 124 } 125 public void removeFromBInNewTx(String pkb) throws FinderException { 126 logger.log(BasicLevel.DEBUG, ""); 127 removeFromB(pkb); 128 } 129 130 public void clearB() { 131 logger.log(BasicLevel.DEBUG, ""); 132 getB().clear(); 133 } 134 135 public void clearBInNewTx() { 136 logger.log(BasicLevel.DEBUG, ""); 137 clearB(); 138 } 139 140 public boolean containAllInB(Collection pkbs) throws FinderException { 141 logger.log(BasicLevel.DEBUG, ""); 142 ArrayList al = new ArrayList (pkbs.size()); 143 for(Iterator it = pkbs.iterator(); it.hasNext();) 144 al.add(bhl.findByPrimaryKey((String ) it.next())); 145 return getB().containsAll(al); 146 } 147 148 154 public boolean containInB(String pkb) throws FinderException { 155 logger.log(BasicLevel.DEBUG, ""); 156 return (getB().contains(bhl.findByPrimaryKey(pkb))); 157 } 158 159 165 public boolean testResetPkForbidden(String pka) { 166 logger.log(BasicLevel.DEBUG, ""); 167 boolean ret = false; 168 try { 169 setId(pka); 170 } catch (IllegalStateException e) { 171 ret = true; 172 } 173 return ret; 174 } 175 176 177 public abstract String getId(); 181 public abstract void setId(String id); 182 183 public abstract Product getProduct(); 186 public abstract void setProduct(Product p); 187 188 public abstract Collection getB(); 189 public abstract void setB(Collection bl); 190 191 195 static protected Logger logger = null; 196 EntityContext ejbContext; 197 198 204 public String ejbCreate(String id) throws CreateException , DuplicateKeyException { 205 logger.log(BasicLevel.DEBUG, ""); 206 207 setId(id); 209 setProduct(new Product()); 210 211 return null; 213 } 214 215 225 public void setEntityContext(EntityContext ctx) { 226 if (logger == null) 227 logger = Log.getLogger(Log.JONAS_TESTS_PREFIX); 228 logger.log(BasicLevel.DEBUG, ""); 229 ejbContext = ctx; 230 try { 231 Context ictx = new InitialContext (); 232 bhl = (BHomeLocal) ictx.lookup("java:comp/env/ejb/b"); 233 } catch (NamingException e) { 234 throw new EJBException ("Impossible to fetch the ", e); 235 } 236 } 237 238 249 public void unsetEntityContext() { 250 logger.log(BasicLevel.DEBUG, ""); 251 ejbContext = null; 252 } 253 254 267 public void ejbRemove() throws RemoveException { 268 logger.log(BasicLevel.DEBUG, ""); 269 } 270 271 279 public void ejbLoad() { 280 logger.log(BasicLevel.DEBUG, ""); 281 } 282 283 291 public void ejbStore() { 292 logger.log(BasicLevel.DEBUG, ""); 293 } 294 295 300 public void ejbPostCreate(String id) throws CreateException { 301 logger.log(BasicLevel.DEBUG, "id=" + id); 302 } 303 304 308 public void ejbPassivate() { 309 logger.log(BasicLevel.DEBUG, ""); 310 } 311 312 317 public void ejbActivate() { 318 logger.log(BasicLevel.DEBUG, ""); 319 } 320 321 } 322 | Popular Tags |