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

📄 subscibehibernatedao.java

📁 天乙社区6.0是一套基于JAVA技术的网络虚拟社区
💻 JAVA
字号:
package com.laoer.bbscs.dao.hibernate;

import org.springframework.orm.hibernate.support.HibernateDaoSupport;
import com.laoer.bbscs.dao.ISubscibeDAO;
import com.laoer.bbscs.bean.Subscibe;
import java.util.*;
import com.laoer.bbscs.sys.PageList;
import org.springframework.dao.*;
import com.laoer.bbscs.sys.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
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 SubscibeHibernateDAO
    extends HibernateDaoSupport implements ISubscibeDAO {

  private static final Log logger = LogFactory.getLog(SubscibeHibernateDAO.class);

  public SubscibeHibernateDAO() {
    super();
  }

  /**
   * saveSubscibe
   *
   * @param subs Subscibe
   * @return Subscibe
   * @todo Implement this com.laoer.bbscs.dao.ISubscibeDAO method
   */
  public Subscibe saveSubscibe(Subscibe subs) {
    try {
      this.getHibernateTemplate().saveOrUpdate(subs);
      return subs;
    }
    catch (DataAccessException ex) {
      logger.error(ex);
      return null;
    }
  }

  /**
   * getSubscibe
   *
   * @param id long
   * @param userID long
   * @param bid long
   * @return Subscibe
   * @todo Implement this com.laoer.bbscs.dao.ISubscibeDAO method
   */
  public Subscibe getSubscibe(long id, long userID, long bid) {
    String q = "from Subscibe" + SysUtil.getTableID(bid, Constant.MODNUM10) +
        " subs where subs.id = ? and subs.userID = ?";
    Object[] o = {
        new Long(id), new Long(userID)};
    List l = this.getHibernateTemplate().find(q, o);
    if (l.size() == 0) {
      return null;
    }
    else {
      return (Subscibe) l.get(0);
    }
  }

  /**
   * getPostSubscibe
   *
   * @param postID long
   * @param userID long
   * @param bid long
   * @return Subscibe
   * @todo Implement this com.laoer.bbscs.dao.ISubscibeDAO method
   */
  public Subscibe getPostSubscibe(long postID, long userID, long bid) {
    String q = "from Subscibe" + SysUtil.getTableID(bid, Constant.MODNUM10) +
        " subs where subs.postID = ? and subs.userID = ?";
    Object[] o = {
        new Long(postID), new Long(userID)};
    List l = this.getHibernateTemplate().find(q, o);
    if (l.size() == 0) {
      return null;
    }
    else {
      return (Subscibe) l.get(0);
    }
  }

  /**
   * getSubscibeNum
   *
   * @param userID long
   * @param bid long
   * @return int
   * @todo Implement this com.laoer.bbscs.dao.ISubscibeDAO method
   */
  public int getSubscibeNum(long userID, long bid) {
    String q = "select count(subs.id) from Subscibe" + SysUtil.getTableID(bid, Constant.MODNUM10) +
        " subs where subs.userID = ?";
    try {
      List l = this.getHibernateTemplate().find(q, new Long(userID));
      return ( (Integer) l.get(0)).intValue();
    }
    catch (DataAccessException ex) {
      logger.error("getSubscibeNum(long userID, long bid):" + ex);
      return 0;
    }
  }

  /**
   * getSubscibeSendList
   *
   * @param postID long
   * @return List
   * @todo Implement this com.laoer.bbscs.dao.ISubscibeDAO method
   */
  public List getSubscibeSendList(long postID, long bid) {
    String q = "from Subscibe" + SysUtil.getTableID(bid, Constant.MODNUM10) +
        " subs where subs.postID = ?";
    try {
      List l = this.getHibernateTemplate().find(q, new Long(postID));
      return l;
    }
    catch (DataAccessException ex) {
      logger.error(ex);
      return new ArrayList();
    }
  }

  /**
   * getMySubscibeList
   *
   * @param userID long
   * @param bid long
   * @return PageList
   * @todo Implement this com.laoer.bbscs.dao.ISubscibeDAO method
   */
  public List getMySubscibeList(final long userID, 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 Subscibe" + SysUtil.getTableID(bid, Constant.MODNUM10) +
            " subs where subs.userID = ?";
        Query query = s.createQuery(q);
        query.setLong(0, userID);
        query.setFirstResult(firstResult);
        query.setMaxResults(maxResults);

        List list = query.list();
        return list;
      }
    });
  }

  /**
   * removeSubscibe
   *
   * @param id long
   * @param userID long
   * @param bid long
   * @todo Implement this com.laoer.bbscs.dao.ISubscibeDAO method
   */
  public void removeSubscibe(final long id, final long userID, final long bid) {
    getHibernateTemplate().execute(new HibernateCallback() {
      public Object doInHibernate(Session s) throws HibernateException, SQLException {
        String q = "from Subscibe" + SysUtil.getTableID(bid, Constant.MODNUM10) +
            " subs where subs.id = ? and subs.userID = ?";
        Object[] o = {
            new Long(id), new Long(userID)};
        Type[] t = {
            Hibernate.LONG, Hibernate.LONG};
        s.delete(q, o, t);
        return null;
      }
    });
  }

  public void removeSubscibe(Subscibe subs) {
    try {
      this.getHibernateTemplate().delete(subs);
    }
    catch (DataAccessException ex) {
      logger.error(ex);
    }
  }

}

⌨️ 快捷键说明

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