📄 guestbookdaoimpl.java
字号:
package com.cucu.tapestry.dao.impl;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.dao.DataAccessException;
import org.springframework.orm.hibernate.support.HibernateDaoSupport;
import com.cucu.tapestry.dao.GuestbookDAO;
import com.cucu.tapestry.entity.Guestbook;
/**
* Guestbook DAO实现类,实现guestbook所有与分页无关的DAO
* @author 绝情酷哥
* @version 1.0
*/
public class GuestbookDAOImpl
extends HibernateDaoSupport
implements GuestbookDAO {
private static final Log log = LogFactory.getLog(GuestbookDAOImpl.class);
/**
*
* @return 返回留言列表
*/
public List getList() throws DataAccessException {
List list =
this.getHibernateTemplate().find(
"select pojo from Guestbook pojo where pojo.parentId=-1 order by pojo.isTop desc,pojo.bookDate desc");
return list;
}
/**
* 根据ID返回guestbook
* @param id
* @return guestbook
* @throws DataAccessException
*/
public Guestbook getGuestbook(Integer id) throws DataAccessException {
String hql = "select pojo from Guestbook pojo where pojo.bookId=?";
List list = this.getHibernateTemplate().find(hql, new Object[] { id });
Guestbook gb = (Guestbook) list.get(0);
return gb;
}
/**
* @return 回复总数
*/
public Integer getReplyCount(Integer parentId) throws DataAccessException {
String hql =
"select count(pojo.bookId) from Guestbook pojo where pojo.parentId=?";
List list =
this.getHibernateTemplate().find(hql, new Object[] { parentId });
return (Integer) list.get(0);
}
/**
* @return 总数
*/
public Integer getCount() throws DataAccessException {
String hql =
"select count(pojo.bookId) from Guestbook pojo where pojo.parentId=-1";
List list = this.getHibernateTemplate().find(hql);
return (Integer) list.get(0);
}
/**
* @param parentId
* @return 回复总数
*/
public Integer getCommentCount(Integer parentId)
throws DataAccessException {
String hql =
"select count(pojo.bookId) from Guestbook pojo where pojo.parentId=?";
List list = this.getHibernateTemplate().find(hql, parentId);
return (Integer) list.get(0);
}
/**
*
* @return 计算总共花费时间
*/
public Integer getSumTime() throws DataAccessException {
String hql =
"select sum(pojo.finishedTime) from Guestbook pojo where pojo.parentId=-1";
List list = this.getHibernateTemplate().find(hql);
return (Integer) list.get(0);
}
/**
* 设置置顶操作
* @param id
* @throws DataAccessException
*/
public void doSetTop(Integer id) throws DataAccessException {
Guestbook gb =
(Guestbook) this.getHibernateTemplate().load(Guestbook.class, id);
gb.setIsTop(
gb.getIsTop().equals(new Integer(1))
? new Integer(0)
: new Integer(1));
this.getHibernateTemplate().save(gb);
}
/**
* 根据ID删除一个对象
* @param id
* @throws DataAccessException
*/
public void doDeleteTopic(Integer id) throws DataAccessException {
Guestbook gb = new Guestbook();
gb.setBookId(id);
this.getHibernateTemplate().delete(gb);
}
/**
* 新建或者修改一个guestbook
* @param gb
* @throws DataAccessException
*/
public void doUpdateTopic(Guestbook gb) throws DataAccessException {
this.getHibernateTemplate().saveOrUpdate(gb);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -