What you propose makes sense, but would not work. There is no guarantee
that the EJB server will use the same instance for finding as for
loading.

For example, it can take instance X run a finder on it, get a list of
primary keys and put it back in the pool. It can then take any other
instance and use it to load, or if the entity bean was already loaded in
another instance, reuse that instance.

arkin

Laurent Nel wrote:
>
> Hello,
>
> I am wondering whether it's possible to improve the ejbFindSomething
> mechanism.
>
> The ejbFindByPrimaryKey() method should return the primary key if the
> corresponding EJB is found in the DB. It is something like this:
>
> public MyEJBPK ejbFindByPrimaryKey (MyEJBPK pk) throws FinderException
> {
>  try {
>         Connection c = makeConnection();
>         PreparedStatement ps = c.prepareStatement("select * from table where
> id=?");
>         ps.setInt (1, pk.id);
>         ResultSet rs = ps.executeQuery();
>         boolean res = rs.next();
>         c.close();
>         if (res)
>                 return res;
>         else
>                 throw new ObjectNotFoundException ("not found");
>  } catch (Exception e) {
>         throw new EJBException ("big bug "+e.getMessage());
>  }
> }
>
> Suppose that the client code is:
>
> MyEJB x = home.findByPrimaryKey (key);
> int value = x.getBusinessValue();
>
> In this case, the ejbFindByPrimaryKey() method returns the pk and the
> container loads the EJB a second time when the getBusinessValue()
> message is sent to x. Maybe there is a kind of optimization ? Am i wrong
> ?
>
> I am wondering whether it's possible to improve the ejbFindByPrimaryKey
> like this:
>
>         ...
>         boolean res = rs.next();
>         c.close();
>         if (res) {
>                 // read DB values and stores them in EJB attributes
>                 this.attribute1 = rs.get<Type> ("attributecolumn1");
>                 this.attribute2 = rs.get<Type> ("attributecolumn2");
>                 ...
>                 this.isModified = false;
>                 return res;
>         }
>
> and
>
> public void ejbLoad()
> {
>         if ( ! isModified)
>                 return;
>         // normal load
> }
>
> Any idea or comment ?
> Thanx in advance,
>
> Laurent
>
> ===========================================================================
> 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".

--
----------------------------------------------------------------------
Assaf Arkin                                           www.exoffice.com
CTO, Exoffice Technologies, Inc.                        www.exolab.org

===========================================================================
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