|
From: Achmad A. R. <a.a...@gm...> - 2005-10-12 05:02:56
|
CMIIW there is no use declaring generic in concrete DaoBean, Spring hasnt
support this yet.
On 10/11/05, Achmad Arif Rachim <a.a...@gm...> wrote:
>
>
>
> 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
> >
> > On 10/10/05, Bijl, Silvester van der <silvester.van.der.bijl@logicacmg.=
com>
> > wrote:
> > >
> > > 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
> > > private Class ourClass =3D
> > > (Class)((ParameterizedType)getClass().getGenericSuperclass()).getActu=
alTypeArguments()[0];
> > >
> > > /*
> > > * Retrieve object from db.
> > > */
> > > @SuppressWarnings("unchecked")
> > > public ObjectType get(IdType id) throws DataAccessException {
> > > 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
> > > Verzonden: di 11-10-2005 6:33
> > > Aan: spr...@li...;
> > > jug...@ya...
> > > Onderwerp: [Springframework-developer] How create Generic DAO pattern
> > > in tiger
> > >
> > >
> > > 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>{
> > > 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);
> > > }
> > > 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 ??=
?
> > >
> > > (* 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 co=
pied,
> > > 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.
> > >
> > >
> >
>
|