1 25 26 package org.objectweb.jonas.jtests.beans.relation.mnb; 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 57 public void assignB(Collection c) throws FinderException { 58 ArrayList al; 59 if (c==null) 60 al = new ArrayList (); 61 else { 62 if (c.size()==-1) 63 al = new ArrayList (); 64 else { 65 al = new ArrayList (c.size()); 66 for(Iterator it = c.iterator(); it.hasNext();) 67 al.add(bhl.findByPrimaryKey((String ) it.next())); 68 } 69 } 70 setB(al); 71 } 72 public void assignBInNewTx(Collection c) throws FinderException { 73 assignB(c); 74 } 75 76 public Collection retrieveB() { 77 Collection bs = getB(); 78 ArrayList result ; 79 if (bs.size()==-1) 80 result = new ArrayList (); 81 else result = new ArrayList (bs.size()); 82 83 for(Iterator it = bs.iterator(); it.hasNext();) 84 result.add(((BLocal) it.next()).getPrimaryKey()); 85 return result; 86 } 87 88 public Collection retrieveBInNewTx() { 89 return retrieveB(); 90 } 91 92 public void addInB(String pkb) throws FinderException { 93 getB().add(bhl.findByPrimaryKey(pkb)); 94 } 95 public void addInBInNewTx(String pkb) throws FinderException { 96 addInB(pkb); 97 } 98 99 public void addAllInB(Collection pkbs) throws FinderException { 100 ArrayList al = new ArrayList (); 101 for (Iterator it = pkbs.iterator(); it.hasNext();) 102 al.add(bhl.findByPrimaryKey((String ) it.next())); 103 getB().addAll(al); 104 } 105 public void addAllInBInNewTx(Collection pkbs) throws FinderException { 106 addAllInB(pkbs); 107 } 108 109 public void removeFromB(String pkb) throws FinderException { 110 getB().remove(bhl.findByPrimaryKey(pkb)); 111 } 112 public void removeFromBInNewTx(String pkb) throws FinderException { 113 removeFromB(pkb); 114 } 115 116 public void clearB() { 117 getB().clear(); 118 } 119 120 public void clearBInNewTx() { 121 clearB(); 122 } 123 124 public boolean containAllInB(Collection pkbs) throws FinderException { 125 ArrayList al = new ArrayList (pkbs.size()); 126 for(Iterator it = pkbs.iterator(); it.hasNext();) 127 al.add(bhl.findByPrimaryKey((String ) it.next())); 128 return getB().containsAll(al); 129 } 130 131 137 public boolean containInB(String pkb) throws FinderException { 138 return (getB().contains(bhl.findByPrimaryKey(pkb))); 139 } 140 141 public abstract String getId(); 145 146 public abstract void setId(String id); 147 148 public abstract Collection getB(); 149 150 public abstract void setB(Collection bl); 151 152 156 static protected Logger logger = null; 157 EntityContext ejbContext; 158 159 165 public String ejbCreate(String id) throws CreateException , DuplicateKeyException { 166 logger.log(BasicLevel.DEBUG, ""); 167 168 setId(id); 170 171 return null; 173 } 174 175 185 public void setEntityContext(EntityContext ctx) { 186 if (logger == null) 187 logger = Log.getLogger(Log.JONAS_TESTS_PREFIX); 188 logger.log(BasicLevel.DEBUG, ""); 189 ejbContext = ctx; 190 try { 191 Context ictx = new InitialContext (); 192 bhl = (BHomeLocal) ictx.lookup("java:comp/env/ejb/b"); 193 } catch (NamingException e) { 194 throw new EJBException ("Impossible to fetch the ", e); 195 } 196 } 197 198 209 public void unsetEntityContext() { 210 logger.log(BasicLevel.DEBUG, ""); 211 ejbContext = null; 212 } 213 214 227 public void ejbRemove() throws RemoveException { 228 logger.log(BasicLevel.DEBUG, ""); 229 } 230 231 239 public void ejbLoad() { 240 logger.log(BasicLevel.DEBUG, ""); 241 } 242 243 251 public void ejbStore() { 252 logger.log(BasicLevel.DEBUG, ""); 253 } 254 255 260 public void ejbPostCreate(String id) throws CreateException { 261 logger.log(BasicLevel.DEBUG, "id=" + id); 262 } 263 264 268 public void ejbPassivate() { 269 logger.log(BasicLevel.DEBUG, ""); 270 } 271 272 277 public void ejbActivate() { 278 logger.log(BasicLevel.DEBUG, ""); 279 } 280 281 } 282 | Popular Tags |