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

📄 bulletinhibernatedao.java

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

import org.springframework.orm.hibernate.support.HibernateDaoSupport;
import com.laoer.bbscs.dao.IBulletinDAO;
import com.laoer.bbscs.bean.Bulletin;
import org.springframework.dao.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.util.*;
import net.sf.hibernate.*;
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 BulletinHibernateDAO
    extends HibernateDaoSupport implements IBulletinDAO {

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

  private static final String LOAD_ALL =
      "from Bulletin bull order by bull.id desc";
  private static final String LOAD_COUNT =
      "select count(bull.id) from Bulletin bull";
  private static final String LOAD_BY_ID =
      "from Bulletin bull where bull.id = ?";

  public BulletinHibernateDAO() {
    super();
  }

  /**
   *
   * @param bulletin Bulletin
   * @return Bulletin
   * @todo Implement this com.laoer.bbscs.dao.IBulletinDAO method
   */
  public Bulletin saveBulletin(Bulletin bulletin) {
    try {
      getHibernateTemplate().saveOrUpdate(bulletin);
      return bulletin;
    }
    catch (DataAccessException ex) {
      logger.error(ex);
      return null;
    }
  }

  /**
   *
   * @param id long
   * @return Bulletin
   * @todo Implement this com.laoer.bbscs.dao.IBulletinDAO method
   */
  public Bulletin getBulletin(long id) {
    return (Bulletin) getHibernateTemplate().get(Bulletin.class, new Long(id));
  }

  /**
   *
   * @return int
   * @todo Implement this com.laoer.bbscs.dao.IBulletinDAO method
   */
  public int getBulletinNum() {
    try {
      List l = this.getHibernateTemplate().find(LOAD_COUNT);
      return ( (Integer) l.get(0)).intValue();
    }
    catch (DataAccessException ex) {
      logger.error(ex);
      return 0;
    }
  }

  /**
   *
   * @param pages Pages
   * @return PageList
   * @todo Implement this com.laoer.bbscs.dao.IBulletinDAO method
   */
  public List getBulletinList(final int firstResult, final int maxResults) {

    return getHibernateTemplate().executeFind(new HibernateCallback() {
      public Object doInHibernate(Session s) throws HibernateException, SQLException {

        Query query = s.createQuery(LOAD_ALL);
        query.setFirstResult(firstResult);
        query.setMaxResults(maxResults);

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

  }

  /**
   *
   * @param id long
   * @todo Implement this com.laoer.bbscs.dao.IBulletinDAO method
   */
  public void removeBulletin(final long id) {
    getHibernateTemplate().execute(new HibernateCallback() {
      public Object doInHibernate(Session s) throws HibernateException, SQLException {
        s.delete(LOAD_BY_ID, new Long(id), Hibernate.LONG);
        return null;
      }
    });

  }

}

⌨️ 快捷键说明

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