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".