|
From: Lachezar D. <l.d...@gm...> - 2005-10-05 08:15:13
|
<< Appologies to all members that get this mail once more. >>
<< It seems SF drops mail from users with non-latin names :(. >>
<< I changed my name to be in latin letters only, hope it gets now. >>
I did not invest much time in Google-ing around to find an answer, but most
of my findings were concerning something called "generics medicines" and
"until spring".
I want to ask if there are any plans to support generics-enhanced beans
declarations in Spring Context.
I don't quite grasp the idea there, but I think there 'might/should' be a
way to specialize a generic enhanced bean's class in the context, something
saying what classes is the generic specialized for.
I have seen questions here as to what use would it be...
Well... Let's say we have a generic base DAO interface:
public interface BaseDao<T> {
public T load(Long ID);
public Long save(T);
public void update(T);
public void update(Collection<T>);
public void delete(T);
public void delete(Collection<T>);
public void delete(Collection<Long>);
}
So we have our services depend on BaseDAO<SpecificType>
public class MyServiceImpl implements MyService {
// We specialise the generic type here.
public void setBaseDao(BaseDao<SpecificEntity> dao) {
this.dao =3D dao;
}
}
Then let's assume we are using Hibernate and have a Generic implementation
of the BaseDao<T>: BaseHibernateDao<T>
public class BaseHibernateDao<T> extends HibernateDaoSupport
implementsBaseDao<T> {
public T load(Long ID) { ... }
public Long save(T) { ... }
public void update(T) { ... }
public void update(Collection<T>) { ... }
public void delete(T) { ... }
public void delete(Collection<T>) { ... }
public void delete(Collection<Long>) { ... }
}
1. I would very much like to do:
<bean name=3D"myEntityDao"
class=3D"com.company.BaseHibernateDao<com.company.SpecificEntityClass>" />
Actually I believe this is quite required if Spring is to be Java5-capable.
2. I would also want to have:
<bean name=3D"myService"
class=3D"com.company.MyServiceImpl"
autowire=3D"byType"/>
and of course have my baseDao set accordingly. This is not required, as
byName gives better handling, but might be considered good.
These are not all the implications Generics support in Spring might give,
but I think these give some insight on what Generics can be used for.
While Spring uses reflection and run-time-casting it would supply little or
no extras for Spring itself (I think), but enabling the use of Generics for
contained beans might provide some wishful flexibility.
Thoughts for food :)
Lachezar Dobrev
|