|
From: Bijl, S. v. d. <sil...@lo...> - 2005-10-12 07:41:17
|
Hi,
=20
I currently don't have access to the code, but this is wat I recalled.
I'll take a look when I get back home.
=20
Silvester
=20
________________________________
From: spr...@li...
[mailto:spr...@li...] On Behalf
Of Achmad Arif Rachim
Sent: woensdag 12 oktober 2005 6:59
To: spr...@li...
Subject: Re: [Springframework-developer] How create Generic DAO pattern
in tiger
=20
=20
On 10/11/05, Achmad Arif Rachim <a.a...@gm...> wrote:
Hi silvester,
getActualTypeArguments are instance of TypeVariableImpl, and we cannot
cast it into Class. Am I missing something ?
thnx
=20
On 10/10/05, Bijl, Silvester van der <
sil...@lo...
<mailto:sil...@lo...> > wrote:=20
Hi,
I've been playing around with this. I came up with the following code:
public class AbstractBaseHibernateDao<ObjectType, IdType extends
Serializable> extends
HibernateDaoSupport implements BaseDao<ObjectType, IdType> {
// JDK 5.0 trickery to retrieve the object class=20
private Class ourClass =3D
(Class)((ParameterizedType)getClass().getGenericSuperclass()).getActualT
ypeArguments()[0];
/*
* Retrieve object from db.
*/
@SuppressWarnings("unchecked")
public ObjectType get(IdType id) throws DataAccessException {=20
return (ObjectType) getHibernateTemplate().load(ourClass, id);
}
}
I declared the interface similiar to your code. Hope this helps.
Silvester
________________________________
Van: spr...@li... namens Achmad
Arif Rachim=20
Verzonden: di 11-10-2005 6:33
Aan: spr...@li...;
jug...@ya...
Onderwerp: [Springframework-developer] How create Generic DAO pattern in
tiger=20
How to read Inherit Generic Type class ?
Guys I've been googling all week but couldn't find solution.
Id like to create Generic DAO pattern. So here's what i do
public interface Dao<E extends Entity, I extends Serializable>{=20
public I create(E entity);
public E read(I id);
public void update(E entity);
public E delete(I id);
}
concrete class would be like this
public class DaoBean implements Dao{
public Serializable create(Entity entity){
getHibernateTemplate.save(entity);
return entity.getId();
}
public void update(Entity entity){
getHibernateTemplate.update(entity);=20
}
public Entity read(Serializable id){
return (Entity)getHibernateTemplate.load(getClass(),id);
}
public Entity delete(Serializable id){
Entity entity =3D read(id);
getHibernateTemplate.delete(entity);
return entity;
}
public Class getEntityClass(){
// now ... how to get Dao E class ????
return E.class;
}
}
The millon dollar* question is how to get Dao Generic E type class ???=20
(* million asked question)
Thanx
This e-mail and any attachment is for authorised use by the intended
recipient(s) only. It may contain proprietary material, confidential
information and/or be subject to legal privilege. It should not be
copied, disclosed to, retained or used by, any other party. If you are
not an intended recipient then please promptly delete this e-mail and
any attachment and all copies and inform the sender. Thank you.
=20
|