81,122
社区成员




package com.lhp.dao.imp;
import java.sql.SQLException;
import java.util.List;
import org.apache.derby.tools.sysinfo;
import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.lhp.bean.Board;
import com.lhp.dao.BoardDAO;
public class BoardDAOImp extends HibernateDaoSupport implements BoardDAO {
private static final String FIND_ALL_BOARD="from Board";
private static final String FIND_BY_ID="select * from Board where id = ?";
private static final String FIND_BY_PID="from Board where parentid = ?";
private static final String FIND_BY_THEME="select * from Board where theme = ?";
private static final String FIND_ALL_COUNT="select count(*) from Board";
public Board findBoardByTheme(String theme) {
return (Board)this.getHibernateTemplate().find(FIND_BY_THEME,theme);
}
public Board findBoardByid(long id) {
return (Board)this.getHibernateTemplate().find(FIND_BY_ID,id);
}
public long findBoardCount() {
return ((Long)this.getHibernateTemplate().find(FIND_ALL_COUNT).get(0)).longValue();
}
public List<Board> findListBoard(int page) {
return null;
}
public Board saveBoard(Board board) {
this.getHibernateTemplate().save(board);
return board;
}
public List findBoardByParentId(final long parentId) {
//System.out.println((this.getHibernateTemplate().find("from Board where boardname = ?","6666")).isEmpty());
//return this.getHibernateTemplate().find("from Board where parentid = ?" ,0);
return this.getHibernateTemplate().executeFind(new HibernateCallback() {
public Object doInHibernate(Session s)
throws HibernateException, SQLException {
Criteria c =s.createCriteria(Board.class);
c.add(Restrictions.eq("parentid", new Long(parentId)));
return c.list();
}
});
}
public List allBoard() {
//System.out.println((this.getHibernateTemplate().find("from Board where parentid = ?",new Object[] {0})).isEmpty());
return this.getHibernateTemplate().find("from Board");
//return null;
}
}