Hi,

I'm wondering what's the best way to return a list of records to the client,
e.g. all customers living in a given city. Entity beans are never directly
accessed by the client, but use a session bean as a Facade. So I guess, there
are basically two ways of implementing the findByCity() method in the
CustomerSession bean:

1. ----

  public Vector findByCity(String city) {
    CustomerHome customerHome = ... (get CustomerHome)
    Collection customers = customerHome.findByCity(city);
    Vector result = new Vector();

    foreach (currentCustomer in customers) do {
      result.addElement(currentCustomer.getValue());
    }

    return result;
  }

2. ---

  public Vector findByCity(String city) {
    ResultSet resultSet = statement.executeQuery("SELECT * FROM Customer
WHERE City=" + city);

    Vector result = new Vector();

    while (resultSet.next()) {
      CustomerValue value = new CustomerValue();
      // populate value object from result set...
      result.addElement(value);
    }

    return result;
  }

So, the session bean could either generate a list of customer value objects
by calling the entity bean's findByCity() method (case 1), or perform the
JDBC query itself (case 2).

Which solution would be better? I would prefer the second one, because it
avoids the overhead of creating lots of entity bean instances (especially if
the list is long), but I'm not sure...

thx
Heiko

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