Hi Heiko,

I suppose that it depends on your context. If you are accessing the list in
read only, than the second method is usually the best one from the
performance point of view.
Now what you can lose with this method is that the responsability of knowing
the database is distributed between a lot of objects..

Amine

> -----Message d'origine-----
> De : Heiko Gottschling [mailto:[EMAIL PROTECTED]]
> Envoyé : vendredi 19 janvier 2001 19:23
> À : [EMAIL PROTECTED]
> Objet : Best way of retrurning a list of records - please discuss
>
>
> 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".
>

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