1 22 package org.jboss.test.testbean.bean; 23 24 25 import java.rmi.*; 26 import javax.ejb.*; 27 import javax.naming.Context ; 28 import javax.sql.DataSource ; 29 import javax.naming.InitialContext ; 30 import java.sql.Connection ; 31 import org.jboss.test.testbean.interfaces.StatelessSession; 32 import org.jboss.test.testbean.interfaces.StatelessSessionHome; 33 import java.util.Collection ; 34 import java.util.Collections ; 35 import java.util.Vector ; 36 import java.util.Enumeration ; 37 38 public class EntityBMPBean implements EntityBean { 39 org.jboss.logging.Logger log = org.jboss.logging.Logger.getLogger(getClass()); 40 41 private EntityContext entityContext; 42 public String name; 43 private StatelessSession statelessSession; 44 private boolean wasFind = false; 45 46 47 public String ejbCreate() throws RemoteException, CreateException { 48 49 log.debug("EntityBMP.ejbCreate() called"); 50 this.name = "noname"; 51 52 return name; 53 54 55 } 56 public String ejbCreate(String name) throws RemoteException, CreateException { 57 58 log.debug("EntityBMP.ejbCreate("+name+") called"); 59 this.name = name; 60 61 return name; 62 } 63 64 public String ejbCreateMETHOD(String name) throws RemoteException, CreateException { 65 66 log.debug("EntityBMP.ejbCreateMETHOD("+name+") called"); 67 this.name = name; 68 69 return name; 70 } 71 72 74 public String ejbFindByPrimaryKey(String name) throws RemoteException, FinderException { 75 76 log.debug("EntityBMP.ejbFindByPrimaryKey() called"); 77 78 wasFind = true; 79 80 return name; 81 } 82 83 public Collection ejbFindCollectionKeys(int num) throws RemoteException, FinderException { 84 85 log.debug("EntityBMP.ejbFindMultipleKeys() called with num "+num); 86 Collection pks = new Vector (); 87 pks.add("primary key number 1"); 88 pks.add("primary key number 2"); 89 pks.add("primary key number 3"); 90 91 return pks; 92 } 93 public Enumeration ejbFindEnumeratedKeys(int num) throws RemoteException, FinderException { 94 95 log.debug("EntityBMP.ejbFindEnumeratedKeys() called with num "+num); 96 Collection pks = new Vector (); 97 pks.add("primary key number 1"); 98 pks.add("primary key number 2"); 99 pks.add("primary key number 3"); 100 101 return Collections.enumeration(pks); 102 } 103 104 public void ejbPostCreate() throws RemoteException, CreateException { 105 106 log.debug("EntityBMP.ejbPostCreate() called"); 107 } 108 109 public void ejbPostCreate(String name) throws RemoteException, CreateException { 110 111 log.debug("EntityBMP.ejbPostCreate("+name+") called"); 112 } 113 114 public void ejbPostCreateMETHOD(String name) throws RemoteException, CreateException { 115 116 log.debug("EntityBMP.ejbPostCreateMETHOD("+name+") called"); 117 } 118 119 public void ejbActivate() throws RemoteException { 120 log.debug("EntityBMP.ejbActivate() called"); 121 } 122 123 public void ejbLoad() throws RemoteException { 124 log.debug("EntityBMP.ejbLoad() called"); 125 } 126 127 public void ejbPassivate() throws RemoteException { 128 129 log.debug("Was Find "+wasFind); 130 log.debug("EntityBMP.ejbPassivate() called"); 131 } 132 133 public void ejbRemove() throws RemoteException, RemoveException { 134 log.debug("EntityBMP.ejbRemove() called"); 135 } 136 137 public void ejbStore() throws RemoteException { 138 139 log.debug("EntityBMP.ejbStore() called"); 140 } 141 142 public String callBusinessMethodA() throws RemoteException{ 143 144 log.debug("EntityBMP.callBusinessMethodA() called"); 145 return "EntityBMP.callBusinessMethodA() called, my primaryKey is "+ 146 entityContext.getPrimaryKey().toString(); 147 } 148 149 public String callBusinessMethodB() throws RemoteException { 150 151 log.debug("EntityBMP.callBusinessMethodB() called, calling B2B"); 152 String b2bMessage = statelessSession.callBusinessMethodB(); 153 log.debug("EntityBMP called stateless Bean and it said "+b2bMessage); 154 return "EntityBMP.callBusinessMethodB() called, called other bean (B2B) and it said \""+b2bMessage+"\""; 155 156 } 157 158 public String callBusinessMethodB(String words) throws RemoteException { 159 log.debug("EntityBMP.callBusinessMethodB(String) called, calling B2B"); 160 String b2bMessage = statelessSession.callBusinessMethodB(); 161 log.debug("EntityBMP called stateless Bean and it said "+b2bMessage); 162 return "EntityBMP.callBusinessMethodB() called, called other bean (B2B) and it said \""+b2bMessage+"\""+" words "+words; 163 164 } 165 166 public void setEntityContext(EntityContext context) throws RemoteException { 167 log.debug("EntityBMP.setSessionContext() called"); 168 entityContext = context; 169 170 172 try { 173 174 Context namingContext = new InitialContext (); 175 176 Connection connection = ((DataSource ) namingContext.lookup("java:comp/env/jdbc/myDatabase")).getConnection(); 177 connection.close(); 178 179 log.debug("EntityBMP I did get the connection to the database for BMP"); 180 } 181 182 catch (Exception e) { 183 184 log.debug("failed", e); 185 186 log.debug("EntityBMP Could not find the database connection, check settings"); 187 188 throw new RemoteException("EntityBMP Could not find the database connection"); 189 } 190 191 try { 192 193 Context namingContext = new InitialContext (); 194 195 log.debug("EntityBMP Looking up Stateless Home"); 196 197 StatelessSessionHome statelessHome = ((StatelessSessionHome) namingContext.lookup("java:comp/env/ejb/myEJBRef")); 198 199 log.debug("EntityBMP Calling create on Stateless Home"); 200 201 statelessSession = statelessHome.create(); 202 203 log.debug("EntityBMP Found the EJB Reference in my java:comp/env/ environment"); 204 205 206 } 207 208 catch (Exception e) { 209 210 log.debug("failed", e); 211 212 log.debug("EntityBMP Could not find the EJB Reference called myEJBRef, check settings"); 213 214 throw new RemoteException("EntityBean Could not find EJB Reference"); 215 } 216 } 217 218 public void unsetEntityContext() throws RemoteException { 219 220 log.debug("EntityBMP.unsetSessionContext() called"); 221 entityContext = null; 222 } 223 } 224 | Popular Tags |