DAO implementation: static?singleton?or instances? [message #390290] |
Wed, 15 July 2009 03:26  |
Eclipse User |
|
|
|
Dear all,
I have written my Entity class and my DAO class (a DAO for each entity)
that implements CRUD operation.
My sopurce code architecture has:
- A base DAO implementation (that implement an interface) with CRUD
operation.
- I use generics in order to have all DAO class that simple extend the
basic DAO, declaring the class Entity they work on
I would like to know what is the better solution between the following
cases:
- 1. implement singleton DAOs
- 2. implment static method for DAOs
- 3. implement instances DAO (instance a new DAO ojbect every time i
need to to do CRUD operation on that table/relationhip.
Currently i have implemented case 3. I think it is good but i don't like
to have a new instance of DAO every time I need to access a table.So, I
am thinking if possible to use case 1 or 2, but I would like to know
what are the advantage/disadvanges of those solution in comparison to
the current implementation.
Can anyone give me some suggestion, please?
BR,
Enrico
|
|
|
|
Re: DAO implementation: static?singleton?or instances? [message #390514 is a reply to message #390513] |
Wed, 22 July 2009 01:51  |
Eclipse User |
|
|
|
Hi Tim,
thank you for your reply.
I also implement DAO using generics. I have a BaseDAO <T> and many DAO
that extend teh BaseDAO defining the Entity class they work on.
My question is related to more on performance and/or control
(synchronization), when JPA is used also on my "public" pages (I mean to
serve http client request). Can be a static or singleton DAO a
bottleneck for many request?Is it better to create a new DAO instance
to serve any request?
BR,
Enrico
Tim Hollosy ha scritto:
> I use a single DAO for all my CRUD, then I don't have to implement the
> DAO each time.
>
> It has methods that are templated like this:
>
>
> public <T extends AbstractEntity> List<T> selectAll(Class<T> clazz) {
> return (List<T>)
> JpaHelper.getEntityManager(entityManager).createQuery(null,c lazz).getResultList()
>
> }
|
|
|
Powered by
FUDForum. Page generated in 0.03457 seconds