几天前拜读了rainlife大哥哥的文章:
于是乎自行改造了项目中的原有抽象结构:
范型DAO将所有DAO的CRUD方法使用范型抽象到此层面。
IGenericDAO.java 代码
- public interface IGenericDAO<t></t> {
- public List<t></t> find(String sql) throws NullSqlStringException,
- UnformatSelectStringException,AccessDataException;
- public T save(T t) throws NullPointerException,AccessDataException;
- public int deleteById(String id) throws AccessDataException;
- public T update(T t) throws NullPointerException,AccessDataException;
- public T getById(String id) throws AccessDataException;
- }
此DAO层接口主要处理针对某一PO的特殊操作的方法。
ISysUserDao.java 代码
- public interface ISysUserDao<sysuser></sysuser> extends IGenericDAO<sysuser></sysuser> {
- public void initializeRoles(SysUser user) throws NullPointerException;
- public void initializeOrganization(SysUser user) throws NullPointerException;
- public void initializeHeadShip(SysUser user) throws NullPointerException;
- public void initializePosition(SysUser user) throws NullPointerException;
- public void initializeTitle(SysUser user) throws NullPointerException;
- public void initializeWorkGroups(SysUser user) throws NullPointerException;
- }
其实,范型的真实类型已经在这一层上体现了,我们使用范型主要还是为了减少在此层接口中大量出现的相同的CRUD的方法的定义。