📄 guestbookhibernatedao.java
字号:
package com.laoer.bbscs.dao.hibernate;
import org.springframework.orm.hibernate.support.HibernateDaoSupport;
import com.laoer.bbscs.dao.IGuestBookDAO;
import com.laoer.bbscs.bean.GuestBook;
import com.laoer.bbscs.sys.*;
import org.springframework.dao.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.util.*;
import net.sf.hibernate.*;
import net.sf.hibernate.type.*;
import org.springframework.orm.hibernate.HibernateCallback;
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 GuestBookHibernateDAO
extends HibernateDaoSupport implements IGuestBookDAO {
private static final Log logger = LogFactory.getLog(GuestBookHibernateDAO.class);
public GuestBookHibernateDAO() {
super();
}
/**
*
* @param gb GuestBook
* @return GuestBook
* @todo Implement this com.laoer.bbscs.dao.IGuestBookDAO method
*/
public GuestBook saveGuestBook(GuestBook gb) {
try {
getHibernateTemplate().saveOrUpdate(gb);
return gb;
}
catch (DataAccessException ex) {
logger.error("saveGuestBook(GuestBook gb):" + ex);
return null;
}
}
/**
*
* @param id long
* @param userID long
* @return GuestBook
* @todo Implement this com.laoer.bbscs.dao.IGuestBookDAO method
*/
public GuestBook getGuestBook(long id, long userID) {
String q = "from GuestBook" + SysUtil.getTableID(userID, Constant.MODNUM10) +
" gb where gb.id = ? and gb.toID = ?";
Object[] o = {
new Long(id), new Long(userID)};
List l = this.getHibernateTemplate().find(q, o);
if (l.size() == 0) {
return null;
}
else {
return (GuestBook) l.get(0);
}
}
/**
*
* @param userID long
* @return int
* @todo Implement this com.laoer.bbscs.dao.IGuestBookDAO method
*/
public int getGuestBookAllNum(long userID) {
String q = "select count(gb.id) from GuestBook" + SysUtil.getTableID(userID, Constant.MODNUM10) +
" gb where gb.toID = ?";
try {
List l = this.getHibernateTemplate().find(q, new Long(userID));
return ( (Integer) l.get(0)).intValue();
}
catch (DataAccessException ex) {
logger.error("getGuestBookAllNum(long userID):" + ex);
return 0;
}
}
/**
*
* @param userID long
* @param isNew short
* @return int
* @todo Implement this com.laoer.bbscs.dao.IGuestBookDAO method
*/
public int getGuestBookNum(long userID, short isNew) {
String q = "select count(gb.id) from GuestBook" + SysUtil.getTableID(userID, Constant.MODNUM10) +
" gb where gb.toID = ? and gb.isNew = ?";
Object[] o = {
new Long(userID), new Short(isNew)};
try {
List l = this.getHibernateTemplate().find(q, o);
return ( (Integer) l.get(0)).intValue();
}
catch (DataAccessException ex) {
logger.error("getGuestBookNum(long userID, short isNew):" + ex);
return 0;
}
}
/**
*
* @param userID long
* @param pages Pages
* @return PageList
* @todo Implement this com.laoer.bbscs.dao.IGuestBookDAO method
*/
public List getGuestBookList(final long userID, final int firstResult, final int maxResults) {
return getHibernateTemplate().executeFind(new HibernateCallback() {
public Object doInHibernate(Session s) throws HibernateException, SQLException {
String q = "from GuestBook" + SysUtil.getTableID(userID, Constant.MODNUM10) +
" gb where gb.toID = ? order by gb.id desc";
Query query = s.createQuery(q);
query.setLong(0, userID);
query.setFirstResult(firstResult);
query.setMaxResults(maxResults);
List list = query.list();
return list;
}
});
}
public List getGuestBookInList(final long userID, final List values) {
return getHibernateTemplate().executeFind(new HibernateCallback() {
public Object doInHibernate(Session s) throws HibernateException, SQLException {
String q = "from GuestBook" + SysUtil.getTableID(userID, Constant.MODNUM10) +
" gb where gb.toID = :toid and gb.id in (:values)";
Query query = s.createQuery(q);
query.setLong("toid", userID);
query.setParameterList("values", values);
List list = query.list();
return list;
}
});
}
/**
*
* @param userID long
*/
public void removeAllGuestBook(final long userID) {
getHibernateTemplate().execute(new HibernateCallback() {
public Object doInHibernate(Session s) throws HibernateException, SQLException {
String q = "from GuestBook" + SysUtil.getTableID(userID, Constant.MODNUM10) +
" gb where gb.toID = ?";
s.delete(q, new Long(userID), Hibernate.LONG);
return null;
}
});
}
/**
*
* @param id long
* @param userID long
* @todo Implement this com.laoer.bbscs.dao.IGuestBookDAO method
*/
public void removeGuestBook(final long id, final long userID) {
getHibernateTemplate().executeFind(new HibernateCallback() {
public Object doInHibernate(Session s) throws HibernateException, SQLException {
String q = "from GuestBook" + SysUtil.getTableID(userID, Constant.MODNUM10) +
" gb where gb.id = ? and gb.toID = ?";
Object[] o = {new Long(id), new Long(userID)};
Type[] t = {Hibernate.LONG, Hibernate.LONG};
s.delete(q, o, t);
return null;
}
});
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -