1 25 26 package org.objectweb.jonas.jtests.beans.relation.pkcomp; 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 47 50 public abstract class AEC2 implements javax.ejb.EntityBean { 51 52 private BHomeLocal bhl = null; 53 54 public void m1(){ 55 } 56 public APK getId() { 57 return (APK) ejbContext.getPrimaryKey(); 58 } 59 60 public void assignB(Collection c) throws FinderException { 61 ArrayList al; 62 if (c==null) 63 al = new ArrayList (); 64 else { 65 if (c.size()==-1) 66 al = new ArrayList (); 67 else { 68 al = new ArrayList (c.size()); 69 for(Iterator it = c.iterator(); it.hasNext();) 70 al.add(bhl.findByPrimaryKey((BPK) it.next())); 71 } 72 } 73 setB(al); 74 } 75 public void assignBInNewTx(Collection c) throws FinderException { 76 assignB(c); 77 } 78 79 public Collection retrieveB() { 80 Collection bs = getB(); 81 ArrayList result ; 82 if (bs.size()==-1) 83 result = new ArrayList (); 84 else result = new ArrayList (bs.size()); 85 86 for(Iterator it = bs.iterator(); it.hasNext();) 87 result.add(((BLocal) it.next()).getPrimaryKey()); 88 return result; 89 } 90 91 public Collection retrieveBInNewTx() { 92 return retrieveB(); 93 } 94 95 public void addInB(BPK pkb) throws FinderException { 96 getB().add(bhl.findByPrimaryKey(pkb)); 97 } 98 public void addInBInNewTx(BPK pkb) throws FinderException { 99 addInB(pkb); 100 } 101 102 public void addAllInB(Collection pkbs) throws FinderException { 103 ArrayList al = new ArrayList (); 104 for (Iterator it = pkbs.iterator(); it.hasNext();) 105 al.add(bhl.findByPrimaryKey((BPK) it.next())); 106 getB().addAll(al); 107 } 108 public void addAllInBInNewTx(Collection pkbs) throws FinderException { 109 addAllInB(pkbs); 110 } 111 112 public void removeFromB(BPK pkb) throws FinderException { 113 getB().remove(bhl.findByPrimaryKey(pkb)); 114 } 115 public void removeFromBInNewTx(BPK pkb) throws FinderException { 116 removeFromB(pkb); 117 } 118 119 public void clearB() { 120 getB().clear(); 121 } 122 123 public void clearBInNewTx() { 124 clearB(); 125 } 126 127 public boolean containAllInB(Collection pkbs) throws FinderException { 128 ArrayList al = new ArrayList (pkbs.size()); 129 for(Iterator it = pkbs.iterator(); it.hasNext();) 130 al.add(bhl.findByPrimaryKey((BPK) it.next())); 131 return getB().containsAll(al); 132 } 133 134 140 public boolean containInB(BPK pkb) throws FinderException { 141 return (getB().contains(bhl.findByPrimaryKey(pkb))); 142 } 143 144 public abstract String getIda1(); 148 149 public abstract int getIda2(); 150 151 public abstract void setIda1(String id); 152 153 public abstract void setIda2(int id); 154 155 public abstract Collection getB(); 156 157 public abstract void setB(Collection bl); 158 159 163 static protected Logger logger = null; 164 EntityContext ejbContext; 165 166 172 public String ejbCreate(String ida1, int ida2) throws CreateException , DuplicateKeyException { 173 logger.log(BasicLevel.DEBUG, ""); 174 175 setIda1(ida1); 177 setIda2(ida2); 178 return null; 180 } 181 182 192 public void setEntityContext(EntityContext ctx) { 193 if (logger == null) 194 logger = Log.getLogger(Log.JONAS_TESTS_PREFIX); 195 logger.log(BasicLevel.DEBUG, ""); 196 ejbContext = ctx; 197 try { 198 Context ictx = new InitialContext (); 199 bhl = (BHomeLocal) ictx.lookup("java:comp/env/ejb/b"); 200 } catch (NamingException e) { 201 throw new EJBException ("Impossible to fetch the ", e); 202 } 203 } 204 205 216 public void unsetEntityContext() { 217 logger.log(BasicLevel.DEBUG, ""); 218 ejbContext = null; 219 } 220 221 234 public void ejbRemove() throws RemoveException { 235 logger.log(BasicLevel.DEBUG, ""); 236 } 237 238 246 public void ejbLoad() { 247 logger.log(BasicLevel.DEBUG, ""); 248 } 249 250 258 public void ejbStore() { 259 logger.log(BasicLevel.DEBUG, ""); 260 } 261 262 267 public void ejbPostCreate(String ida1, int ida2) throws CreateException { 268 logger.log(BasicLevel.DEBUG, "ida1=" + ida1 + " / ida2=" + ida2); 269 } 270 271 275 public void ejbPassivate() { 276 logger.log(BasicLevel.DEBUG, ""); 277 } 278 279 284 public void ejbActivate() { 285 logger.log(BasicLevel.DEBUG, ""); 286 } 287 288 } 289 | Popular Tags |