📄 forumhibernatedao.java
字号:
package com.laoer.bbscs.dao.hibernate;
import org.springframework.orm.hibernate.support.HibernateDaoSupport;
import com.laoer.bbscs.dao.IForumDAO;
import com.laoer.bbscs.bean.Forum;
import com.laoer.bbscs.sys.*;
import java.util.*;
import org.springframework.dao.*;
import net.sf.hibernate.*;
import net.sf.hibernate.type.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
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 ForumHibernateDAO
extends HibernateDaoSupport implements IForumDAO {
private static final Log logger = LogFactory.getLog(ForumHibernateDAO.class);
public ForumHibernateDAO() {
super();
}
/**
* saveForum
*
* @param forum Forum
* @return Forum
* @todo Implement this com.laoer.bbscs.dao.IForumDAO method
*/
public Forum saveForum(Forum forum) {
try {
this.getHibernateTemplate().saveOrUpdate(forum);
return forum;
}
catch (DataAccessException ex) {
logger.error("saveForum(Forum forum):" + ex);
return null;
}
}
/**
* getForum
*
* @param id long
* @param bid long
* @return Forum
* @todo Implement this com.laoer.bbscs.dao.IForumDAO method
*/
public Forum getForum(final long id, final long bid) {
return (Forum) getHibernateTemplate().execute(new HibernateCallback() {
public Object doInHibernate(Session s) throws HibernateException, SQLException {
String className = SysUtil.getForumClassName(bid);
try {
return s.get(Class.forName(className), new Long(id));
}
catch (ClassNotFoundException ex) {
logger.error(ex);
return null;
}
catch (HibernateException ex) {
logger.error(ex);
return null;
}
}
});
}
/**
* getForumMainNum
*
* @param bid long
* @return int
* @todo Implement this com.laoer.bbscs.dao.IForumDAO method
*/
public int getForumMainNum(long bid) {
String q = "select count(forum.id) from Forum" + SysUtil.getForumTableID(bid) +
" forum where forum.boardID = ? and forum.isNew = 1 and forum.delSign = 0 and forum.auditing = 0";
try {
List l = getHibernateTemplate().find(q, new Long(bid));
if (l != null && !l.isEmpty()) {
return ( (Integer) l.get(0)).intValue();
}
else {
return 0;
}
}
catch (DataAccessException ex) {
logger.error(ex);
return 0;
}
}
/**
* getForumAllNum
*
* @param bid long
* @param delSign short
* @return int
* @todo Implement this com.laoer.bbscs.dao.IForumDAO method
*/
public int getForumAllNum(long bid, short delSign, short auditing) {
String q = "select count(forum.id) from Forum" + SysUtil.getForumTableID(bid) +
" forum where forum.boardID = ? and forum.delSign = ? and forum.auditing = ?";
Object[] o = {
new Long(bid), new Short(delSign), new Short(auditing)};
try {
List l = this.getHibernateTemplate().find(q, o);
if (l != null && !l.isEmpty()) {
return ( (Integer) l.get(0)).intValue();
}
else {
return 0;
}
}
catch (DataAccessException ex) {
logger.error(ex);
return 0;
}
}
/**
* getForumTopicNum
*
* @param bid long
* @param ID2 long
* @return int
* @todo Implement this com.laoer.bbscs.dao.IForumDAO method
*/
public int getForumTopicNum(long bid, long ID2) {
String q = "select count(forum.id) from Forum" + SysUtil.getForumTableID(bid) +
" forum where forum.id2 = ? and forum.boardID = ? and forum.delSign = 0 and forum.auditing = 0";
Object[] o = {
new Long(ID2), new Long(bid)};
try {
List l = this.getHibernateTemplate().find(q, o);
if (l != null && !l.isEmpty()) {
return ( (Integer) l.get(0)).intValue();
}
else {
return 0;
}
}
catch (DataAccessException ex) {
logger.error(ex);
return 0;
}
}
public int getForumDelAllNum(long bid) {
String q = "select count(forum.id) from Forum" + SysUtil.getForumTableID(bid) +
" forum where forum.boardID = ? and forum.delSign = 1";
try {
List l = this.getHibernateTemplate().find(q, new Long(bid));
if (l != null && !l.isEmpty()) {
return ( (Integer) l.get(0)).intValue();
}
else {
return 0;
}
}
catch (DataAccessException ex) {
logger.error(ex);
return 0;
}
}
/**
* getForumMainList
*
* @param bid long
* @return PageList
* @todo Implement this com.laoer.bbscs.dao.IForumDAO method
*/
public List getForumMainList(final long bid, final int firstResult, final int maxResults) {
return getHibernateTemplate().executeFind(new HibernateCallback() {
public Object doInHibernate(Session s) throws HibernateException, SQLException {
String q = "from Forum" + SysUtil.getForumTableID(bid) +
" forum where forum.boardID = ? and forum.isNew = 1 and forum.delSign = 0 and forum.auditing = 0 order by forum.isTop desc,forum.lastTime desc";
Query query = s.createQuery(q);
query.setLong(0, bid);
query.setFirstResult(firstResult);
query.setMaxResults(maxResults);
List list = query.list();
return list;
}
});
}
/**
* getForumAllList
*
* @param bid long
* @param delSign short
* @return PageList
* @todo Implement this com.laoer.bbscs.dao.IForumDAO method
*/
public List getForumAllList(final long bid, final short delSign, final short auditing,
final int firstResult, final int maxResults) {
return getHibernateTemplate().executeFind(new HibernateCallback() {
public Object doInHibernate(Session s) throws HibernateException, SQLException {
String q = "from Forum" + SysUtil.getForumTableID(bid) +
" forum where forum.boardID = ? and forum.delSign = ? and forum.auditing = ? order by forum.id desc";
Query query = s.createQuery(q);
query.setLong(0, bid);
query.setShort(1, delSign);
query.setShort(2, auditing);
query.setFirstResult(firstResult);
query.setMaxResults(maxResults);
List list = query.list();
return list;
}
});
}
/**
* getForumTopicList
*
* @param bid long
* @param ID2 long
* @return PageList
* @todo Implement this com.laoer.bbscs.dao.IForumDAO method
*/
public List getForumTopicList(final long bid, final long ID2, final int firstResult,
final int maxResults) {
return getHibernateTemplate().executeFind(new HibernateCallback() {
public Object doInHibernate(Session s) throws HibernateException, SQLException {
String q = "from Forum" + SysUtil.getForumTableID(bid) +
" forum where forum.id2 = ? and forum.boardID = ? and forum.delSign = 0 and forum.auditing = 0 order by forum.id";
Query query = s.createQuery(q);
query.setLong(0, ID2);
query.setLong(1, bid);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -