简单的现实,没用到DAOFactorypublic interface DaoImpl {
public void add(Object obj) throws DaoException;
public void update(Object obj) throws DaoException;
public void remove(Class cla, String id) throws DaoException;
public Object findId(Class cla, String id) throws DaoException;
public List findList(Object obj, PageBean page) throws DaoException;
public List findList(Object obj, PageBean page, Object order) throws DaoException;
public int count(Object obj) throws DaoException;}public interface NewsTypeDao extends DaoImpl{
public void remove(String id) throws DaoException;
public NewsType findId(String id) throws DaoException;}public interface NewsDao extends DaoImpl { public void remove(String id) throws DaoException;
public News findId(String id) throws DaoException;}public class HibernateBaseDao implements DaoImpl {
//实现DaoImpl
}//实现NewsTypeDao
public class NewsTypeDaoHibernate extends HibernateBaseDao implements NewsTypeDao { public void remove(String id) throws DaoException {
remove(NewsType.class, id);
} public NewsType findId(String id) throws DaoException {
return (NewsType)findId(NewsType.class, id);
}}//实现NewsDao
public class NewsDaoHibernate extends HibernateBaseDao implements NewsDao { public void remove(String id) throws DaoException {
remove(News.class, id);
} public News findId(String id) throws DaoException {
return (News) findId(News.class, id);
}
}
public void add(Object obj) throws DaoException;
public void update(Object obj) throws DaoException;
public void remove(Class cla, String id) throws DaoException;
public Object findId(Class cla, String id) throws DaoException;
public List findList(Object obj, PageBean page) throws DaoException;
public List findList(Object obj, PageBean page, Object order) throws DaoException;
public int count(Object obj) throws DaoException;}public interface NewsTypeDao extends DaoImpl{
public void remove(String id) throws DaoException;
public NewsType findId(String id) throws DaoException;}public interface NewsDao extends DaoImpl { public void remove(String id) throws DaoException;
public News findId(String id) throws DaoException;}public class HibernateBaseDao implements DaoImpl {
//实现DaoImpl
}//实现NewsTypeDao
public class NewsTypeDaoHibernate extends HibernateBaseDao implements NewsTypeDao { public void remove(String id) throws DaoException {
remove(NewsType.class, id);
} public NewsType findId(String id) throws DaoException {
return (NewsType)findId(NewsType.class, id);
}}//实现NewsDao
public class NewsDaoHibernate extends HibernateBaseDao implements NewsDao { public void remove(String id) throws DaoException {
remove(News.class, id);
} public News findId(String id) throws DaoException {
return (News) findId(News.class, id);
}
}
private NewsType newsType;}调用如下
NewsTypeDao newstypeDao = new NewsTypeDaoHibernate();
NewsType newsType = newsTypeDao.findId("1001");
News news = new News();
news.setNewsType(newsType);
NewsDao newsDao = new NewsDaoHibernate();
List list = newsDao.findList(news, null, null); //返回newsTypeId = 1001的所有记录代码还很拙劣,有待改进
* 范例:
* ResultFilter rf = ForumResultFilter.createDefaultThreadFilter();
* rf.appendSearchCondition("forumid=" + forumId);
* forumDBSearcher.getResultList(rf);
* forumDBSearcher.getResultIterator(rf);
* forumDBSearcher.getResultCount(rf);ResultFilter 还有setClass setNumResults等等方法