1 25 26 package org.objectweb.jonas.jtests.beans.relation.s1pkcomp; 27 28 import org.objectweb.util.monolog.api.Logger; 29 import org.objectweb.util.monolog.api.BasicLevel; 30 import org.objectweb.jonas.common.Log; 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 49 public abstract class BEC2 implements javax.ejb.EntityBean { 50 51 private AHomeLocal ahl = null; 52 53 public void m1(){ 54 } 55 56 public PK getId() { 57 return (PK) ejbContext.getPrimaryKey(); 58 } 59 60 public void assignA(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(ahl.findByPrimaryKey((PK) it.next())); 71 } 72 } 73 } 74 setA(al); 75 } 76 77 public void assignAInNewTx(Collection c) throws FinderException { 78 assignA(c); 79 } 80 81 public Collection retrieveA() { 82 Collection bs = getA(); 83 ArrayList result ; 84 if (bs.size()==-1) 85 result = new ArrayList (); 86 else result = new ArrayList (bs.size()); 87 88 for(Iterator it = bs.iterator(); it.hasNext();) 89 result.add(((ALocal) it.next()).getPrimaryKey()); 90 return result; 91 } 92 93 public Collection retrieveAInNewTx() { 94 return retrieveA(); 95 } 96 97 public void addInA(PK pkb) throws FinderException { 98 getA().add(ahl.findByPrimaryKey(pkb)); 99 } 100 public void addInAInNewTx(PK pkb) throws FinderException { 101 addInA(pkb); 102 } 103 104 public void addAllInA(Collection pkbs) throws FinderException { 105 ArrayList al = new ArrayList (); 106 for (Iterator it = pkbs.iterator(); it.hasNext();) 107 al.add(ahl.findByPrimaryKey((PK) it.next())); 108 getA().addAll(al); 109 } 110 public void addAllInAInNewTx(Collection pkbs) throws FinderException { 111 addAllInA(pkbs); 112 } 113 114 public void removeFromA(PK pkb) throws FinderException { 115 getA().remove(ahl.findByPrimaryKey(pkb)); 116 } 117 public void removeFromAInNewTx(PK pkb) throws FinderException { 118 removeFromA(pkb); 119 } 120 121 public void clearA() { 122 getA().clear(); 123 } 124 125 public void clearAInNewTx() { 126 clearA(); 127 } 128 129 public boolean containAllInA(Collection pkbs) throws FinderException { 130 ArrayList al = new ArrayList (pkbs.size()); 131 for(Iterator it = pkbs.iterator(); it.hasNext();) 132 al.add(ahl.findByPrimaryKey((PK) it.next())); 133 return getA().containsAll(al); 134 } 135 136 142 public boolean containInA(PK pkb) throws FinderException { 143 return (getA().contains(ahl.findByPrimaryKey(pkb))); 144 } 145 146 public abstract String getId1(); 150 151 public abstract int getId2(); 152 153 public abstract void setId1(String id); 154 155 public abstract void setId2(int id); 156 157 public abstract Collection getA(); 158 159 public abstract void setA(Collection bl); 160 161 165 static protected Logger logger = null; 166 EntityContext ejbContext; 167 168 174 public String ejbCreate(String idb1, int idb2) throws CreateException , DuplicateKeyException { 175 logger.log(BasicLevel.DEBUG, ""); 176 177 setId1(idb1); 179 setId2(idb2); 180 return null; 182 } 183 184 194 public void setEntityContext(EntityContext ctx) { 195 if (logger == null) 196 logger = Log.getLogger(Log.JONAS_TESTS_PREFIX); 197 logger.log(BasicLevel.DEBUG, ""); 198 ejbContext = ctx; 199 try { 200 Context ictx = new InitialContext (); 201 ahl = (AHomeLocal) ictx.lookup("java:comp/env/ejb/a"); 202 } catch (NamingException e) { 203 throw new EJBException ("Impossible to fetch the ", e); 204 } 205 } 206 207 218 public void unsetEntityContext() { 219 logger.log(BasicLevel.DEBUG, ""); 220 ejbContext = null; 221 } 222 223 236 public void ejbRemove() throws RemoveException { 237 logger.log(BasicLevel.DEBUG, ""); 238 } 239 240 248 public void ejbLoad() { 249 logger.log(BasicLevel.DEBUG, ""); 250 } 251 252 260 public void ejbStore() { 261 logger.log(BasicLevel.DEBUG, ""); 262 } 263 264 269 public void ejbPostCreate(String idb1, int idb2) throws CreateException { 270 logger.log(BasicLevel.DEBUG, "idb1=" + idb1 + " / idb2=" + idb2); 271 } 272 273 277 public void ejbPassivate() { 278 logger.log(BasicLevel.DEBUG, ""); 279 } 280 281 286 public void ejbActivate() { 287 logger.log(BasicLevel.DEBUG, ""); 288 } 289 290 } 291 292 | Popular Tags |