Hi Bill:

The Fat Key Pattern written by Gene Chuang seems to achieve what you are
trying to do:

http://theserverside.com/patterns/thread.jsp?thread_id=4540

BTW, if you use CMP, some app servers do this optimization for you. For
example, WebLogic Server 6.0 has a setting that loads the data on the
findBy<whatever>, thus eliminating the need for a subsequent ejbLoad().
WebSphere Application Server 4.0 is an example of an app server that doesn't
have this capability.

Laurel

-----Original Message-----
From: Bill Leonard [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, July 25, 2001 11:12 AM
To: [EMAIL PROTECTED]
Subject: Finding BMP entity beans: 2 db calls?


When developing BMP entity beans, it seems like unless the Connection pool
is written very smartly, that 2 database calls are made when a find() is
done:  one when the bean instance's ejbFind<whatever>() method is called to
get the primary key and another when the bean instance's ejbLoad() method is
called.  I see that the Connection object from the Connection Pool will have
a cache of prepared statements; I'm wondering if when the
ejbFind<whatever>() gets the data from the db using its prepared database
statement, that the whole record is retrieved and cached -- and this data is
accessed when the ejbLoad()'s prepared statement is used??  I looked at some
sample code and this doesn't seem right ... instead, it looks like 2
database calls will be made....

I've provided some lifecycle details for explanation; it's long so ....

=== cut here: details follow =====

For BMP entity beans, here's my understanding of the lifecycle with respect
to find (assume that entity bean instances have already been created and are
in the instance Pool):

1. Client uses remote reference to EJBHome object to send findWhatever()
method to EJBHome server object
2. The container/home object creates an EJBObject
3. The home/container selects a bean instance (that is not bound to an
EJBObject) from the instance pool.
4. The home/container calls the corresponding ejbFindWhatever() method on
the bean instance.
5. I implement the bean's ejbFindWhatever() method by getting a Connection
from the Connection pool and using that to prepare a db statement that
selects the primary key from the db.  The method returns the primary key to
the home/container.  Note that in this method,  I do NOT get the rest of the
record's data and store it in this bean instance's data members.  Note also
that this bean instance is NOT associated with the EJBObject.
6. The home/container associates the primary key with the EJBObject.
7. A remote reference to the EJBObject is returned to the Client.

At this point, the EJBObject on the server has a primary key assigned to it.
It does not have a bean instance assigned to it (this is why any bean
instance that isn't attached to an EJBObject can be used to service find
requests).  The Client now invokes a business method to get one of the
fields of the database record (e.g. getLastName() ):

1. Client invokes business method, getLastName(), on remote reference to
EJBObject.
2. Remote reference to EJBObject sends message to EJBObject on server.
3. The container sees that the EJBObject does not have a bean instance
associated with it.  It then gets a bean instance from the instance Pool and
assigns the bean instance to the EJBObject.
4. The container calls ejbActivate() on the bean instance. I would implement
this method to acquire any resources needed for this specific bean instance.
5. The container calls ejbLoad() on the bean instance.  Now, here is the
main issue:  the ejbLoad() method will be implemented as follows: it will
ask the EntityContext for the primary key that is associated with the
EJBObject, create a db statement using that db key, use a Connection object
to prepare the statement and then use the prepared statement to select data
from the db.  This is a second database lookup ....

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to