G
Guest
A lot of people recommend using the dao pattern for data access because it
makes it easy to change persistance strategy and abstracts away the
differences between datasources.
However I am somewhat confused about some of the implications this involves
concern 1:
Suppose you have a products table which contains infomation about your
products Lets say there are 3000 of them in the database and each product
record contains a description field which contains a very large description
of the product in a clob field
now everytime you want to list all products you have to instantiate 3000
objects with this *huge* description field in it, this seems very
inefficient performance and memory wise
I know core j2ee patterns recommends using a disconnected rowset and create
a RowSetWrapperList that creates instances only when needed, this improves
performance somewhat but you'd still have to fetch all fields and all
records of the table when maybe you'd only want to page thru a list of
productname and price field in a jsp page
how do you deal with these situations?
Ignore it and just Buy heaps and heaps of memory it's cheap anyhow? , Just
use jdbc for reading the stuff?
concern 2:
how do you handle relations? An object can have many relations, say a
TeamMember - Team relationship
Having a Set of TeamMembers in Team would seem intuitive, but then the dao
would also have to load all the TeamMembers, and TeamMember might have an
associated Role object which would also have to be loaded etc..
So that doesn't seem like an option
I suppose you could have a TeamMemberDAO.getByTeamID(int ..) and fix it that
way. But suppose Team would have a business method that required access to
its members would it call TeamMemberDao.getByTeamID ?, that doesn't feel
quite right
Or should you externalize all business logic and treat objects returned by
the dao only as data transfer objects, that doesn't feel right from an OO
point of view
This dao stuff feels kind of cumbersome right now, I'd appreciate if anyone
could shed some light on this
makes it easy to change persistance strategy and abstracts away the
differences between datasources.
However I am somewhat confused about some of the implications this involves
concern 1:
Suppose you have a products table which contains infomation about your
products Lets say there are 3000 of them in the database and each product
record contains a description field which contains a very large description
of the product in a clob field
now everytime you want to list all products you have to instantiate 3000
objects with this *huge* description field in it, this seems very
inefficient performance and memory wise
I know core j2ee patterns recommends using a disconnected rowset and create
a RowSetWrapperList that creates instances only when needed, this improves
performance somewhat but you'd still have to fetch all fields and all
records of the table when maybe you'd only want to page thru a list of
productname and price field in a jsp page
how do you deal with these situations?
Ignore it and just Buy heaps and heaps of memory it's cheap anyhow? , Just
use jdbc for reading the stuff?
concern 2:
how do you handle relations? An object can have many relations, say a
TeamMember - Team relationship
Having a Set of TeamMembers in Team would seem intuitive, but then the dao
would also have to load all the TeamMembers, and TeamMember might have an
associated Role object which would also have to be loaded etc..
So that doesn't seem like an option
I suppose you could have a TeamMemberDAO.getByTeamID(int ..) and fix it that
way. But suppose Team would have a business method that required access to
its members would it call TeamMemberDao.getByTeamID ?, that doesn't feel
quite right
Or should you externalize all business logic and treat objects returned by
the dao only as data transfer objects, that doesn't feel right from an OO
point of view
This dao stuff feels kind of cumbersome right now, I'd appreciate if anyone
could shed some light on this