I agree with Adam.

Fetch everything you can with one database call. Perform multiple JOINs
and then decode the ResultSet according to how you wrote the SELECT.
You can use iBATIS (ibatis.apache.org) or use the JDBC templating of
the Spring Framework (www.springframework.org); the former does XML
configuration, the latter is strongly-typed Java. You should choose
which is best for you.

Also, sometimes it's impossible to fetch everything in one query if
your DAO API is large and your SQL is overwhelmingly complex. It would require 
duplication and management of very-easy-to-break SQL, and sometimes in these 
cases
you are not willing to duplicate the JOIN logic in every DAO method; you
instead limit it to a few; and accept more database invocations. 
However, you need to make this up by adding caching to your DAO, 
otherwise your performance will be miserable.

Paul


--- Adam Hardy <[EMAIL PROTECTED]> wrote:

> Hi Joel,
> 
> your English is fine. Best practices would normally dictate that you fetch 
> everything you need
> from the database in one hit. 
> 
> It does depend on what framework or coding pattern you are using for your 
> database access
> though. I assume you are coding simple JDBC API calls? 
> 
> I would strongly recommend a quick and easy lightweight object / relational 
> mapping framework
> like iBatis. 
> 
> But generally I would obtain the Message DTOs in the data services layer and 
> populate them with
> the user information from a resultset obtained joining both tables. A quick 
> and dirty technique
> would be to put the UserName attribute directly on the Message bean.
> 
> But be careful of anti-patterns!
> 
> Regards
> Adam
> 
> 
> 
> 
> Joel Alejandro Espinosa Carra on 20/05/06 00:19, wrote:
> > Hi all.
> > 
> > I think this is kind of a basic question. I have an application that 
> > haves 3 tables: users, messages and user_inbox for the relationship of 
> > first 2 ones. I have a class named MessagesManager in order to manage 
> > the messages to-and-from the database throught the business methods, one 
> > of them is the public List getMessages(String user_id) method that 
> > returns a MessageBean's list and I need to display the messages of each 
> > user in a html table, the MessageBean only contains the user_id but I 
> > want to display their names, do I need to modify my business method in 
> > order to get the usernames? or do I need to add another method to get 
> > the usernames, something like public String getName(String user_id)?, 
> > the first aproach makes one query to the database and the second aproach 
> > makes two. What is the best practice here?
> > As you can see english is not my navite language, I hope you guys can 
> > understand my issue.
> > 
> > Thanks in advance.
> > Have a nice weekend.
> > 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to