Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » DAO implementation: static?singleton?or instances?
DAO implementation: static?singleton?or instances? [message #390290] Wed, 15 July 2009 07:26 Go to next message
Enrico is currently offline Enrico
Messages: 82
Registered: July 2009
Member
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 #390513 is a reply to message #390290] Tue, 21 July 2009 18:09 Go to previous messageGo to next message
Tim Hollosy is currently offline Tim Hollosy
Messages: 5
Registered: July 2009
Junior Member
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()
}
Re: DAO implementation: static?singleton?or instances? [message #390514 is a reply to message #390513] Wed, 22 July 2009 05:51 Go to previous message
Enrico is currently offline Enrico
Messages: 82
Registered: July 2009
Member
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()
>
> }
Previous Topic:problem with DB2 database - DB2 urgent
Next Topic:createquery
Goto Forum:
  


Current Time: Sat Oct 25 12:40:37 GMT 2014

Powered by FUDForum. Page generated in 0.13223 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software