PortableRemoteObject.narrow(ref, CabinRemote.class); if(cabin_1.isIdentical(cabin_2)) (Yahoo free web hosting) // this will always be
Thursday, January 10th, 2008PortableRemoteObject.narrow(ref, CabinRemote.class); if(cabin_1.isIdentical(cabin_2)) // this will always be true. At first glance, the Handle and the primary key appear to do the same thing, but in truth they are very different. Using the primary key requires you to have the correct remote EJB home if you no longer have a reference to the EJB remote home, you must look up the container using JNDI and get a new home. Only then can you call findByPrimaryKey() to locate the actual enterprise bean. The following code shows how this might work: // Obtain the primary key from an input stream. Integer primaryKey = (Integer)inStream.readObject(); // The JNDI API is used to get a root directory or initial context. javax.naming.Context ctx = new javax.naming.InitialContext(); // Using the initial context, obtain the EJBHome for the Cabin bean. Object ref = ctx.lookup(”CabinHome”); CabinHomeRemote home = (CabinHomeRemote) PortableRemoteObject.narrow(ref,CabinHomeRemote.class); // Obtain a reference to an EJB object that represents the entity instance. CabinRemote cabin_2 = CabinHome.findByPrimaryKey(primaryKey); The Handle object is easier to use because it encapsulates the details of doing a JNDI lookup on the container. With a Handle, the correct EJB object can be obtained in one method call, Handle.getEJBObject(), rather than using the three method calls required to look up the context, get the home, and find the actual bean. Furthermore, while the primary key can be used to obtain remote references to unique entity beans, it is not available for session beans; a handle can be used with either type of enterprise bean. This makes using a handle more consistent across bean types. Consis tency is, of course, good in its own right, but it isn t the whole story. Normally, we think of session beans as not having identifiable instances because they exist for only the life of the client session, but this is not exactly true. We have mentioned (but not yet shown) stateful session beans, which retain state information between method invocations. With stateful session beans, two instances are not equivalent. A handle allows you to work with a stateful session bean, deactivate the bean, and then reactivate it at a later time using the handle. A client could, for example, be using a stateful session bean to process an order when the process needs to be interrupted for some reason. Instead of losing all the work performed in the session, a handle can be obtained from the EJB object and the client application can be closed down. When the user is ready to continue the order, the handle can be used to obtain a reference to the stateful Copyright (c) 2001 O’Reilly & Associates 23
Would you like to be a member of headache free web site owner’s community. Now you can. We focus in IX Web Hosting, go go go!