First page Back Continue Last page Graphics

...Continuation of Notes


Notes:

And finally, part of the CustomerBean class. It must pass a reference to this Customer to the create( ) method that creates the new Order. It uses an EJBObject reference rather than this:
public abstract class CustomerBean extends EntityBeanBase {
private OrderHome _orderhome;

public Order createOrder() {
Customer custThis = (EJBObject) _ctxt.getEJBObject();
Order order = _orderhome.create(custThis);
return order;
}

//...

public void setEntityContext(EntityContext ctxt) {
super.setEntityContext(ctxt);

// Perform additional initialization here...
_orderhome = ...; // Look up Order Home object.
}
Comparing Two EJB Objects
This example illustrates how to compare two EJBObjects. Here the Bank interface has a method to move money between two accounts. The bean class method first tests if the two accounts are identical:

public interface Bank extends EJBObject {
public void transferFunds(Account source, Account target,
float amount) throws ...
// Rest of interface...
}

public class BankBean extends SessionBeanBase {
public void transferFunds(Account source, Account target,
float amount) {

// Test if source and target are same account:
if( source.isIdentical(target) )
// Throw some appropriate exception...

// Continue processing the transfer...
}
// Rest of class...
}