⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 forumhistoryhibernatedao.java

📁 一个jsp写的bbs
💻 JAVA
字号:
package com.laoer.bbscs.dao.hibernate;

import org.springframework.orm.hibernate3.support.*;
import com.laoer.bbscs.dao.ForumHistoryDAO;
import com.laoer.bbscs.bean.ForumHistory;
import java.util.List;
import com.laoer.bbscs.comm.OrderObj;
import org.hibernate.criterion.Restrictions;
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Projections;
import org.hibernate.HibernateException;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.hibernate.criterion.Order;
import org.apache.commons.lang.StringUtils;
import com.laoer.bbscs.comm.Constant;
import org.hibernate.Query;
import java.sql.SQLException;

/**
 * <p>Title: TianyiBBS</p>
 *
 * <p>Description: BBSCS</p>
 *
 * <p>Copyright: Copyright (c) 2006</p>
 *
 * <p>Company: Laoer.com</p>
 *
 * @author Laoer
 * @version 7.0
 */
public class ForumHistoryHibernateDAO
    extends HibernateDaoSupport implements ForumHistoryDAO {

  private static final String LOAD_BY_ID_BID = "from ForumHistory where id = ? and boardID = ?";

  private static final String UPDATE_TAG = "update ForumHistory set tagID = ?, tagName = ? where tagID = ?";

  public ForumHistoryHibernateDAO() {
    super();
  }

  /**
   *
   * @param fh ForumHistory
   * @return ForumHistory
   * @todo Implement this com.laoer.bbscs.dao.ForumHistoryDAO method
   */
  public ForumHistory saveForumHistory(ForumHistory fh) {
    this.getHibernateTemplate().save(fh);
    return fh;
  }

  /**
   *
   * @param fh ForumHistory
   * @return ForumHistory
   * @todo Implement this com.laoer.bbscs.dao.ForumHistoryDAO method
   */
  public ForumHistory updateForumHistory(ForumHistory fh) {
    this.getHibernateTemplate().update(fh);
    return fh;
  }

  /**
   *
   * @param id String
   * @param bid long
   * @return ForumHistory
   * @todo Implement this com.laoer.bbscs.dao.ForumHistoryDAO method
   */
  public ForumHistory findForumHistoryByID(String id, long bid) {
    Object[] o = {id, new Long(bid)};
    List l = this.getHibernateTemplate().find(LOAD_BY_ID_BID, o);
    if (l == null || l.isEmpty()) {
      return null;
    }
    else {
      return (ForumHistory) l.get(0);
    }
  }

  /**
   *
   * @param bid long
   * @param isNew int
   * @param delSign int
   * @param auditing int
   * @return int
   * @todo Implement this com.laoer.bbscs.dao.ForumHistoryDAO method
   */
  public int getForumHistoryNum(final long bid, final int isNew, final int delSign, final int auditing) {
    List l = getHibernateTemplate().executeFind(new HibernateCallback() {
      public Object doInHibernate(Session s) throws HibernateException {
        Criteria c = s.createCriteria(ForumHistory.class);
        c.setProjection(Projections.count("id"));
        if (bid != -1) {
          c.add(Restrictions.eq("boardID", new Long(bid)));
        }
        if (isNew != -1) {
          c.add(Restrictions.eq("isNew", new Integer(isNew)));
        }
        if (delSign != -1) {
          c.add(Restrictions.eq("delSign", new Integer(delSign)));
        }
        if (auditing != -1) {
          c.add(Restrictions.eq("auditing", new Integer(auditing)));
        }
        return c.list();
      }
    });
    if (l == null || l.isEmpty()) {
      return 0;
    }
    else {
      return ( (Integer) l.get(0)).intValue();
    }
  }

  /**
   *
   * @param bid long
   * @param mainID String
   * @param delSign int
   * @param auditing int
   * @return int
   * @todo Implement this com.laoer.bbscs.dao.ForumHistoryDAO method
   */
  public int getForumHistoryTopicNum(final long bid, final String mainID, final int delSign,
                                     final int auditing) {
    List l = getHibernateTemplate().executeFind(new HibernateCallback() {
      public Object doInHibernate(Session s) throws HibernateException {
        Criteria c = s.createCriteria(ForumHistory.class);
        c.setProjection(Projections.count("id"));
        c.add(Restrictions.eq("boardID", new Long(bid)));
        c.add(Restrictions.eq("mainID", mainID));
        if (delSign != -1) {
          c.add(Restrictions.eq("delSign", new Integer(delSign)));
        }
        if (auditing != -1) {
          c.add(Restrictions.eq("auditing", new Integer(auditing)));
        }
        return c.list();
      }
    });
    if (l == null || l.isEmpty()) {
      return 0;
    }
    else {
      return ( (Integer) l.get(0)).intValue();
    }
  }

  /**
   *
   * @param bid long
   * @param isNew int
   * @param delSign int
   * @param auditing int
   * @param oo OrderObj[]
   * @param firstResult int
   * @param maxResults int
   * @return List
   * @todo Implement this com.laoer.bbscs.dao.ForumHistoryDAO method
   */
  public List findForumHistorys(final long bid, final int isNew, final int delSign, final int auditing,
                                final OrderObj[] oo, final int firstResult, final int maxResults) {
    return getHibernateTemplate().executeFind(new HibernateCallback() {
      public Object doInHibernate(Session s) throws HibernateException {
        Criteria c = s.createCriteria(ForumHistory.class);
        c.add(Restrictions.eq("boardID", new Long(bid)));
        if (isNew != -1) {
          c.add(Restrictions.eq("isNew", new Integer(isNew)));
        }
        if (delSign != -1) {
          c.add(Restrictions.eq("delSign", new Integer(delSign)));
        }
        if (auditing != -1) {
          c.add(Restrictions.eq("auditing", new Integer(auditing)));
        }
        if (oo != null && oo.length > 0) {
          for (int i = 0; i < oo.length; i++) {
            if (StringUtils.isNotBlank(oo[i].getOrderBy())) {
              if (oo[i].getAscOrDesc() == Constant.ORDER_ASC) {
                c.addOrder(Order.asc(oo[i].getOrderBy()));
              }
              if (oo[i].getAscOrDesc() == Constant.ORDER_DESC) {
                c.addOrder(Order.desc(oo[i].getOrderBy()));
              }
            }
          }
        }
        c.setFirstResult(firstResult);
        c.setMaxResults(maxResults);
        return c.list();
      }
    });

  }

  /**
   *
   * @param bid long
   * @param mainID String
   * @param delSign int
   * @param auditing int
   * @param oo OrderObj[]
   * @param firstResult int
   * @param maxResults int
   * @return List
   * @todo Implement this com.laoer.bbscs.dao.ForumHistoryDAO method
   */
  public List findForumHistorysTopic(final long bid, final String mainID, final int delSign,
                                     final int auditing, final OrderObj[] oo, final int firstResult,
                                     final int maxResults) {
    return getHibernateTemplate().executeFind(new HibernateCallback() {
      public Object doInHibernate(Session s) throws HibernateException {
        Criteria c = s.createCriteria(ForumHistory.class);
        c.add(Restrictions.eq("mainID", mainID));
        c.add(Restrictions.eq("boardID", new Long(bid)));
        if (delSign != -1) {
          c.add(Restrictions.eq("delSign", new Integer(delSign)));
        }
        if (auditing != -1) {
          c.add(Restrictions.eq("auditing", new Integer(auditing)));
        }
        if (oo != null && oo.length > 0) {
          for (int i = 0; i < oo.length; i++) {
            if (StringUtils.isNotBlank(oo[i].getOrderBy())) {
              if (oo[i].getAscOrDesc() == Constant.ORDER_ASC) {
                c.addOrder(Order.asc(oo[i].getOrderBy()));
              }
              if (oo[i].getAscOrDesc() == Constant.ORDER_DESC) {
                c.addOrder(Order.desc(oo[i].getOrderBy()));
              }
            }
          }
        }
        c.setFirstResult(firstResult);
        c.setMaxResults(maxResults);
        return c.list();
      }
    });
  }

  /**
   *
   * @param bids List
   * @param isNew int
   * @param delSign int
   * @param auditing int
   * @return int
   * @todo Implement this com.laoer.bbscs.dao.ForumHistoryDAO method
   */
  public int getForumHistoryNumInBids(final List bids, final int isNew, final int delSign, final int auditing) {
    List l = getHibernateTemplate().executeFind(new HibernateCallback() {
      public Object doInHibernate(Session s) throws HibernateException {
        Criteria c = s.createCriteria(ForumHistory.class);
        c.setProjection(Projections.count("id"));
        if (bids != null && !bids.isEmpty()) {
          c.add(Restrictions.in("boardID", bids));
        }
        if (isNew != -1) {
          c.add(Restrictions.eq("isNew", new Integer(isNew)));
        }
        if (delSign != -1) {
          c.add(Restrictions.eq("delSign", new Integer(delSign)));
        }
        if (auditing != -1) {
          c.add(Restrictions.eq("auditing", new Integer(auditing)));
        }
        return c.list();
      }
    });
    if (l == null || l.isEmpty()) {
      return 0;
    }
    else {
      return ( (Integer) l.get(0)).intValue();
    }
  }

  /**
   *
   * @param bids List
   * @param isNew int
   * @param delSign int
   * @param auditing int
   * @param oo OrderObj[]
   * @param firstResult int
   * @param maxResults int
   * @return List
   * @todo Implement this com.laoer.bbscs.dao.ForumHistoryDAO method
   */
  public List findForumHistorysInBids(final List bids, final int isNew, final int delSign, final int auditing,
                                      final OrderObj[] oo, final int firstResult, final int maxResults) {
    return getHibernateTemplate().executeFind(new HibernateCallback() {
      public Object doInHibernate(Session s) throws HibernateException {
        Criteria c = s.createCriteria(ForumHistory.class);
        if (bids != null && !bids.isEmpty()) {
          c.add(Restrictions.in("boardID", bids));
        }
        if (isNew != -1) {
          c.add(Restrictions.eq("isNew", new Integer(isNew)));
        }
        if (delSign != -1) {
          c.add(Restrictions.eq("delSign", new Integer(delSign)));
        }
        if (auditing != -1) {
          c.add(Restrictions.eq("auditing", new Integer(auditing)));
        }
        if (oo != null && oo.length > 0) {
          for (int i = 0; i < oo.length; i++) {
            if (StringUtils.isNotBlank(oo[i].getOrderBy())) {
              if (oo[i].getAscOrDesc() == Constant.ORDER_ASC) {
                c.addOrder(Order.asc(oo[i].getOrderBy()));
              }
              if (oo[i].getAscOrDesc() == Constant.ORDER_DESC) {
                c.addOrder(Order.desc(oo[i].getOrderBy()));
              }
            }
          }
        }
        c.setFirstResult(firstResult);
        c.setMaxResults(maxResults);
        return c.list();
      }
    });
  }

  public int getForumNumInMainIDByUserID(final long bid, final String mainID, final String userID,
                                         final int isnew,
                                         final int delSign, final int auditing) {
    List l = getHibernateTemplate().executeFind(new HibernateCallback() {
      public Object doInHibernate(Session s) throws HibernateException {
        Criteria c = s.createCriteria(ForumHistory.class);
        c.setProjection(Projections.count("id"));
        c.add(Restrictions.eq("boardID", new Long(bid)));

        c.add(Restrictions.eq("mainID", mainID));
        c.add(Restrictions.eq("userID", userID));
        if (isnew != -1) {
          c.add(Restrictions.eq("isNew", new Integer(isnew)));
        }
        if (delSign != -1) {
          c.add(Restrictions.eq("delSign", new Integer(delSign)));
        }
        if (auditing != -1) {
          c.add(Restrictions.eq("auditing", new Integer(auditing)));
        }

        return c.list();
      }
    });
    if (l == null || l.isEmpty()) {
      return 0;
    }
    else {
      return ( (Integer) l.get(0)).intValue();
    }
  }

  public void updateForumsTag(final String oldTagId, final String newTagID, final String newTagName) {
    getHibernateTemplate().execute(new HibernateCallback() {
      public Object doInHibernate(Session s) throws HibernateException, SQLException {
        Query query = s.createQuery(UPDATE_TAG);
        query.setString(1, newTagID);
        query.setString(2, newTagName);
        query.setString(3, oldTagId);
        query.executeUpdate();
        return null;
      }
    });

  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -