?? commendhibernatedao.java
字號:
package com.laoer.bbscs.dao.hibernate;
import org.springframework.orm.hibernate.support.HibernateDaoSupport;
import com.laoer.bbscs.dao.ICommendDAO;
import com.laoer.bbscs.bean.Commend;
import com.laoer.bbscs.sys.PageList;
import com.laoer.bbscs.sys.Pages;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.dao.*;
import java.util.*;
import net.sf.hibernate.*;
import net.sf.hibernate.type.*;
import org.springframework.orm.hibernate.HibernateCallback;
import com.laoer.bbscs.sys.Constant;
import com.laoer.bbscs.sys.SysUtil;
import java.sql.SQLException;
/**
* <p>Title: TianYi BBS</p>
* <p>Description: TianYi BBS System</p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: LAOER.COM/TIANYISOFT.NET</p>
* @author laoer
* @version 6.0
*/
public class CommendHibernateDAO
extends HibernateDaoSupport implements ICommendDAO {
private static final Log logger = LogFactory.getLog(CommendHibernateDAO.class);
private static final String LOAD_BY_POSTID =
"from Commend commend where commend.postID = ? and commend.isBull = ?";
private static final String LOAD_NUM =
"select count(commend.id) from Commend commend where commend.isBull = ?";
private static final String LOADS_BY_ISBULL =
"from Commend commend where commend.isBull = ? order by commend.addTime desc";
private static final String LOAD_BY_ID =
"from Commend commend where commend.id = ?";
private static final String LOAD_IN =
"from Commend commend where commend.id in (:ids)";
public CommendHibernateDAO() {
super();
}
/**
*
* @param commend Commend
* @return Commend
* @todo Implement this com.laoer.bbscs.dao.ICommendDAO method
*/
public Commend saveCommend(Commend commend) {
try {
getHibernateTemplate().saveOrUpdate(commend);
return commend;
}
catch (DataAccessException ex) {
logger.error(ex);
return null;
}
}
/**
*
* @param postID long
* @param isBull short
* @return Commend
* @todo Implement this com.laoer.bbscs.dao.ICommendDAO method
*/
public Commend findCommendByPostID(long postID, short isBull) {
Object[] o = {
new Long(postID), new Short(isBull)};
List l = this.getHibernateTemplate().find(LOAD_BY_POSTID, o);
if (l.size() == 0) {
return null;
}
else {
return (Commend) l.get(0);
}
}
/**
*
* @param isBull short
* @return int
* @todo Implement this com.laoer.bbscs.dao.ICommendDAO method
*/
public int getCommendNum(short isBull) {
try {
List l = this.getHibernateTemplate().find(LOAD_NUM, new Short(isBull));
return ( (Integer) l.get(0)).intValue();
}
catch (DataAccessException ex) {
logger.error("getCommendNum(short isBull):" + ex);
return 0;
}
}
/**
*
* @param isBull short
* @param pages Pages
* @return PageList
* @todo Implement this com.laoer.bbscs.dao.ICommendDAO method
*/
public List getCommendList(final short isBull, final int firstResult, final int maxResults) {
return getHibernateTemplate().executeFind(new HibernateCallback() {
public Object doInHibernate(Session s) throws HibernateException, SQLException {
Query query = s.createQuery(LOADS_BY_ISBULL);
query.setShort(0, isBull);
query.setFirstResult(firstResult);
query.setMaxResults(maxResults);
List list = query.list();
return list;
}
});
}
/**
*
* @param ids List
* @return List
*/
public List getCommendInList(final List ids) {
return getHibernateTemplate().executeFind(new HibernateCallback() {
public Object doInHibernate(Session s) throws HibernateException, SQLException {
Query query = s.createQuery(LOAD_IN);
query.setParameterList("ids", ids);
List list = query.list();
return list;
}
});
}
/**
*
* @param id long
* @todo Implement this com.laoer.bbscs.dao.ICommendDAO method
*/
public void removeCommend(final long id) {
getHibernateTemplate().execute(new HibernateCallback() {
public Object doInHibernate(Session s) throws HibernateException, SQLException {
s.delete(LOAD_BY_ID, new Long(id), Hibernate.LONG);
return null;
}
});
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -