Hi
I have some questions about the DAO Pattern.
Say that I have a database with one table named Persons (PersonId, name), one table named Groups (GroupId, GroupName) and one table GroupMemberships (id, GroupId, PersonId).
Persons and Groups are in the java app represented by the classes Person and Group.
Using the DAO pattern, should the data access code for these objects be in seperate DAOs, i.e. PersonDAO and GroupDAO?
If one wants to retrieve all persons in a specified group (sql something likes this: select PersonId, Name from Persons as p, GroupMemberships as m where m.GroupId = ? and p.PersonId = m.PersonId), in which DAO should that code be?
-
DAO Pattern (3 messages)
- Posted by: Johan Henricsson
- Posted on: April 05 2003 15:04 EST
Threaded Messages (3)
- DAO Pattern by Andreas Siebert on April 06 2003 10:20 EDT
- DAO Pattern by Weston Aiken on April 07 2003 07:35 EDT
- DAO Pattern by Kiran Kumar on April 08 2003 02:51 EDT
-
DAO Pattern[ Go to top ]
- Posted by: Andreas Siebert
- Posted on: April 06 2003 10:20 EDT
- in response to Johan Henricsson
I think this it is more then one way possible.
i like to code one dao for every sql-statement. other people create one dao for all statements over one table.
if you code one dao for every sql-query (forgett the class-overhead) it simplier to create a dao-cache or other helper-classes.
cause every dao have only to methods:
VO getByPrimaryKey( Serializable id);
Iterator getAll();
Iterator getByValueKey( String name, Object value);
a better way is, if you configure the dao before you get the values.
so you develope a dao like a sql-pattern with settable values.
sorry, i can't speak english. this are first steps in english ;) -
DAO Pattern[ Go to top ]
- Posted by: Weston Aiken
- Posted on: April 07 2003 07:35 EDT
- in response to Johan Henricsson
Unless you create a GroupMembershipDAO, it makes sense for it to be a method on the PersonDAO...since your returning a collection of Person Objects.
Collection people = personDAO.findByGroupdId(int group_id); -
DAO Pattern[ Go to top ]
- Posted by: Kiran Kumar
- Posted on: April 08 2003 02:51 EDT
- in response to Johan Henricsson
Instead of having a seperate DAO for each sql statement, it might be good to have related sql statements as part of that particular DAO. Sometimes these SQL statements could belong to more than one table, where all these SQL statements tries to address similar/common business needs
For ex:
All persons related queries as part of PersonsDAO and all group related queries as GroupDAO.
I think, having a seperate DAO for each SQL statement adds more complexity than the problems it tries to address.