接口设计原则:
让接口尽量在框架的基础上简单
如:
1,如果对你的系统来说:必要insert(object),delete(PK),update(ojbect),find(object)这几个功能的话.
可以把他们当成"原了接口",做成一个接口.
2,把getPartObjects(Class c,int size); 这些接口,应当归类整理,
实现一个分页接口,单猩的接口
这样,如果不需要分页只实现1,如果需要分页再实现2.
接口是一些通用方法,不可能只用一个就搞定.
当然有些是可以传换的:把getPartObjects(Class c,int size)如果没有size则传成:
把getPartObjects(Class c,20);
public interface IBaseDao <T, PK extends Serializable> extends IDao {
/**
* create
* @param t
*/
public PK create(T t);
/**
* delete by PK
* @param t
*/
public boolean delete(PK id);
/**
* delete by T
* @param t
*/
public boolean delete(T t);
/**
* update
* @param t
*/
public boolean update(T t);
/**
* read by PK
* @param id
* @return
*/
public T read(PK id);
/**
* find all
* @return
*/
public List <T> findAll();
/**
* Is Exist by PK
* @return
*/
public boolean isExist(PK id);
}
/**
* Batch 批量操作dao
* @author guishuanglin 2007-11-17
*
* @param <T>
* @param <PK>
*/
public interface IBatchDao <T, PK extends Serializable> extends IDao {
/**
* create by List <T>
* @param entitys
*/
public boolean createBatch(List <T> entitys);
/**
* delete by List <T>
* @param entitys
*/
public boolean deleteBatch(List <T> entitys);
/**
* delete by ArrayList <PK>
* @param entitys
*/
public boolean deleteBatch(ArrayList <PK> ids);
/**
* update by List <T>
* @param entitys
*/
public boolean updateBatch(List <T> entitys);
}
上面的接口你可以用
jdbc
hibernate
ibatis
ole
....用你想要的方式实现,统一数据库操作方法