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

📄 forumhibernatedao.java

📁 一个jsp写的bbs
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
package com.laoer.bbscs.dao.hibernate;

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

/**
 * <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 ForumHibernateDAO
    extends HibernateDaoSupport implements ForumDAO {

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

  private static final String LOADS_ELITE =
      "from Forum where boardID = ? and elite = ? and eliteID = ?";

  private static final String GET_OWN_NUM = "select count(id) from Forum where userID = ?";

  private static final String LOADS_OWN = "from Forum where userID = ? order by postTime desc";

  private static final String DEL_BY_ID_BID = "delete from Forum where id = ? and boardID = ?";

  private static final String DEL_BY_ID = "delete from Forum where id = ?";

  //private static final String LOADS_TO_HISTORY = "from Forum where mainID in (select id from Forum where isNew = 1 and lastTime <= ?)";

  private static final String LOADS_TO_HISTORY = "from Forum where isNew = 1 and elite = 0 and lastTime <= ?";

  private static final String GET_NUM_HOT = "select count(id) from Forum where boardID = ? and isNew = ? and delSign = ? and auditing = ? and (reNum >= ? or click >= ?)";

  private static final String LOADS_HOT = "from Forum where boardID = ? and isNew = ? and delSign = ? and auditing = ? and (reNum >= ? or click >= ?) order by postTime desc";

  private static final String GET_NUM_HOT_IN_BIDS = "select count(id) from Forum where boardID in (:bids) and isNew = :isNew and delSign = :delSign and auditing = :auditing and (reNum >= :reNum or click >= :click)";

  private static final String LOADS_HOT_IN_BIDS = "from Forum where boardID in (:bids) and isNew = :isNew and delSign = :delSign and auditing = :auditing and (reNum >= :reNum or click >= :click) order by postTime desc";

  private static final String LOADS_IN_IDS_BID = "from Forum where id in (:ids) and boardID = :bid";

  private static final String LOADS_IN_IDS = "from Forum where id in (:ids)";

  private static final String LOADS_DEL_REAL_ALL =
      "from Forum where boardID = ? and delSign = 1 and delTime < ?";

  private static final String LOADS_BY_INDEX_STATUS = "from Forum where indexStatus = ?";

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

  public ForumHibernateDAO() {
    super();
  }

  /**
   * 保存或更新Forum对象
   *
   * @param forum Forum
   * @return Forum
   * @todo Implement this com.laoer.bbscs.dao.ForumDAO method
   */
  public Forum saveForum(Forum forum) {
    this.getHibernateTemplate().saveOrUpdate(forum);
    return forum;
  }

  /**
   *
   * @param id String
   * @return Forum
   */
  public Forum findForumByID(String id) {
    return (Forum)this.getHibernateTemplate().get(Forum.class, id);
  }

  /**
   * 根据ID,版区ID取得Forum对象
   *
   * @param id String
   * @param bid long
   * @return Forum
   * @todo Implement this com.laoer.bbscs.dao.ForumDAO method
   */
  public Forum findForumByID(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 (Forum) l.get(0);
    }
  }

  /**
   *
   * @param bid long
   * @param isNew int
   * @param delSign int
   * @param auditing int
   * @return int
   * @todo Implement this com.laoer.bbscs.dao.ForumDAO method
   */
  public int getForumNum(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(Forum.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)));
        }
        /*
                 if (groups != null && !groups.isEmpty()) {
          c.add(Restrictions.in("userGroupID", groups));
                 }*/
        return c.list();
      }
    });
    if (l == null || l.isEmpty()) {
      return 0;
    }
    else {
      return ( (Integer) l.get(0)).intValue();
    }
  }

  public int getForumNum(final long bid, final int isNew, final int delSign, final int auditing,
                         final int auditingAttachFile) {
    List l = getHibernateTemplate().executeFind(new HibernateCallback() {
      public Object doInHibernate(Session s) throws HibernateException {
        Criteria c = s.createCriteria(Forum.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)));
        }
        if (auditingAttachFile != -1) {
          c.add(Restrictions.eq("auditingAttachFile", new Integer(auditingAttachFile)));
        }

        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.ForumDAO method
   */
  public int getForumTopicNum(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(Forum.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 orderby String
   * @param ascOrDesc int
   * @return List
   * @todo Implement this com.laoer.bbscs.dao.ForumDAO method
   */
  public List findForums(final long bid, final int isNew, final int delSign, final int auditing,
                         final String orderby, final int ascOrDesc) {
    return getHibernateTemplate().executeFind(new HibernateCallback() {
      public Object doInHibernate(Session s) throws HibernateException {
        Criteria c = s.createCriteria(Forum.class);
        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)));
        }
        if (StringUtils.isNotBlank(orderby)) {
          if (ascOrDesc == Constant.ORDER_ASC) {
            c.addOrder(Order.asc(orderby));
          }
          if (ascOrDesc == Constant.ORDER_DESC) {
            c.addOrder(Order.desc(orderby));
          }
        }
        return c.list();
      }
    });
  }

  public List findForums(final long bid, final int isNew, final int delSign, final int auditing,
                         final OrderObj[] oo) {
    return getHibernateTemplate().executeFind(new HibernateCallback() {
      public Object doInHibernate(Session s) throws HibernateException {
        Criteria c = s.createCriteria(Forum.class);
        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)));
        }
        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()));
              }
            }
          }
        }
        return c.list();
      }
    });

  }

  /**
   *
   * @param bid long
   * @param isNew int
   * @param delSign int
   * @param auditing int
   * @param orderby String
   * @param ascOrDesc int
   * @param firstResult int
   * @param maxResults int
   * @return List
   * @todo Implement this com.laoer.bbscs.dao.ForumDAO method
   */
  public List findForums(final long bid, final int isNew, final int delSign, final int auditing,
                         final String orderby, final int ascOrDesc, final int firstResult,
                         final int maxResults) {
    return getHibernateTemplate().executeFind(new HibernateCallback() {
      public Object doInHibernate(Session s) throws HibernateException {
        Criteria c = s.createCriteria(Forum.class);
        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)));
        }
        if (StringUtils.isNotBlank(orderby)) {
          if (ascOrDesc == Constant.ORDER_ASC) {
            c.addOrder(Order.asc(orderby));
          }
          if (ascOrDesc == Constant.ORDER_DESC) {
            c.addOrder(Order.desc(orderby));
          }
        }
        c.setFirstResult(firstResult);
        c.setMaxResults(maxResults);
        return c.list();
      }
    });
  }

  public List findForums(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(Forum.class);
        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)));
        }
        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()));
              }
            }
          }

⌨️ 快捷键说明

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