1 22 package org.jboss.test.jca.ejb; 23 24 import java.rmi.RemoteException ; 25 import java.sql.Connection ; 26 27 import javax.ejb.CreateException ; 28 import javax.ejb.EJBException ; 29 import javax.ejb.EntityBean ; 30 import javax.ejb.EntityContext ; 31 import javax.naming.InitialContext ; 32 import javax.sql.DataSource ; 33 34 import org.jboss.test.jca.interfaces.Reentrant; 35 36 53 54 public class ReentrantBean implements EntityBean 55 { 56 57 private static final long serialVersionUID = 1L; 58 59 private Integer id; 60 61 private EntityContext ctx; 62 63 public ReentrantBean() 64 { 65 66 } 67 68 78 public Integer ejbCreate(Integer id, Reentrant other) throws CreateException , RemoteException 79 { 80 this.id = id; 81 return id; 82 } 83 84 92 public void ejbPostCreate(Integer id, Reentrant other) throws CreateException , RemoteException 93 { 94 this.id = id; 95 Reentrant me = (Reentrant) ctx.getEJBObject(); 96 Connection c = null; 97 try 98 { 99 try 100 { 101 DataSource ds = (DataSource ) new InitialContext ().lookup("java:/DefaultDS"); 102 c = ds.getConnection(); 103 if (other != null) 104 { 105 other.doSomething(me); 106 } 107 } 108 finally 109 { 110 c.close(); 111 } 112 } 113 catch (Exception e) 114 { 115 throw new CreateException ("could not get DataSource or Connection" + e.getMessage()); 116 } 117 } 118 119 127 public void doSomething(Reentrant first) throws RemoteException 128 { 129 if (first != null) 130 { 131 first.doSomething(null); 132 } 133 } 134 135 public Integer ejbFindByPrimaryKey(Integer id) 136 { 137 return id; 138 } 139 140 142 public void ejbActivate() 143 { 144 } 145 146 public void ejbLoad() 147 { 148 this.id = (Integer ) ctx.getPrimaryKey(); 149 } 150 151 public void ejbPassivate() 152 { 153 } 154 155 public void ejbRemove() throws EJBException 156 { 157 } 158 159 public void ejbStore() throws EJBException 160 { 161 } 162 163 public void setEntityContext(EntityContext ctx) 164 { 165 this.ctx = ctx; 166 } 167 168 public void unsetEntityContext() 169 { 170 ctx = null; 171 } 172 173 public String toString() 174 { 175 if (id == null) 176 return null; 177 else 178 return id.toString(); 179 } 180 } 181 | Popular Tags |