1 45 package org.openejb.client; 46 47 import java.lang.reflect.Method ; 48 import java.rmi.RemoteException ; 49 50 import javax.ejb.EJBObject ; 51 import javax.ejb.Handle ; 52 53 58 public class EntityEJBHomeHandler extends EJBHomeHandler { 59 60 public EntityEJBHomeHandler(){ 61 } 62 63 public EntityEJBHomeHandler(EJBMetaDataImpl ejb, ServerMetaData server, ClientMetaData client){ 64 super(ejb, server, client); 65 } 66 67 120 protected Object findX(Method method, Object [] args, Object proxy) throws Throwable { 121 EJBRequest req = new EJBRequest( EJB_HOME_FIND ); 122 123 req.setMethodParameters( args ); 124 req.setMethodInstance( method ); 125 req.setClientIdentity( client.getClientIdentity() ); 126 req.setDeploymentCode( ejb.deploymentCode ); 127 req.setDeploymentId( ejb.deploymentID ); 128 req.setPrimaryKey( primaryKey ); 129 130 EJBResponse res = request( req ); 131 132 Object primKey = null; 133 EJBObjectHandler handler = null; 134 Object [] primaryKeys = null; 135 136 switch (res.getResponseCode()) { 137 case EJB_ERROR: 138 throw (Throwable )res.getResult(); 139 case EJB_SYS_EXCEPTION: 140 throw (Throwable )res.getResult(); 141 case EJB_APP_EXCEPTION: 142 throw (Throwable )res.getResult(); 143 144 case EJB_OK_FOUND: 145 primKey = res.getResult(); 146 handler = EJBObjectHandler.createEJBObjectHandler(ejb,server,client,primKey); 147 handler.setEJBHomeProxy((EJBHomeProxy)proxy); 148 registerHandler(ejb.deploymentID+":"+primKey, handler); 149 return handler.createEJBObjectProxy(); 150 151 case EJB_OK_FOUND_COLLECTION: 152 primaryKeys = (Object [])res.getResult(); 157 158 for (int i=0; i < primaryKeys.length; i++){ 159 primKey = primaryKeys[i]; 160 handler = EJBObjectHandler.createEJBObjectHandler(ejb,server,client,primKey); 161 handler.setEJBHomeProxy((EJBHomeProxy)proxy); 162 registerHandler(ejb.deploymentID+":"+primKey, handler); 163 primaryKeys[i] = handler.createEJBObjectProxy(); 164 } 165 return java.util.Arrays.asList( primaryKeys ); 166 case EJB_OK_FOUND_ENUMERATION: 167 primaryKeys = (Object [])res.getResult(); 169 170 for (int i=0; i < primaryKeys.length; i++){ 171 primKey = primaryKeys[i]; 172 handler = EJBObjectHandler.createEJBObjectHandler(ejb,server,client,primKey); 173 handler.setEJBHomeProxy((EJBHomeProxy)proxy); 174 registerHandler(ejb.deploymentID+":"+primKey, handler); 175 primaryKeys[i] = handler.createEJBObjectProxy(); 176 } 177 return new org.openejb.util.ArrayEnumeration( java.util.Arrays.asList( primaryKeys ) ); 178 default: 179 throw new RemoteException ("Received invalid response code from server: "+res.getResponseCode()); 180 } 181 } 182 208 protected Object removeByPrimaryKey(Method method, Object [] args, Object proxy) throws Throwable { 209 210 Object primKey = args[0]; 211 212 if ( primKey == null ) throw new NullPointerException ("The primary key is null."); 213 215 219 invalidateAllHandlers(ejb.deploymentID+":"+primKey); 220 return null; 221 } 222 248 protected Object removeWithHandle(Method method, Object [] args, Object proxy) throws Throwable { 249 250 if ( args[0] == null ) throw new RemoteException ("Handler is null"); 251 252 Handle handle = (Handle )args[0]; 255 EJBObject ejbObject = handle.getEJBObject(); 256 ejbObject.remove(); 257 return null; 258 } 259 260 } 261 | Popular Tags |