onlinestathibernatedao.java

来自「一套基于struts+spring开发的网上聊天系统,欢迎下在研究.」· Java 代码 · 共 113 行

JAVA
113
字号
package com.laoer.bbscs.dao.hibernate;

import org.springframework.orm.hibernate.support.*;
import com.laoer.bbscs.dao.IOnlineStatDAO;
import com.laoer.bbscs.bean.OnlineStat;
import org.springframework.dao.*;
import org.apache.commons.logging.LogFactory;
import org.apache.commons.logging.Log;
import java.util.*;
import net.sf.hibernate.Query;
import net.sf.hibernate.Session;
import net.sf.hibernate.HibernateException;
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 OnlineStatHibernateDAO
    extends HibernateDaoSupport implements IOnlineStatDAO {

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

  private static final String LOAD_BY_RECDATE =
      "from OnlineStat os where os.recDate = ?";
  private static final String LOADS_ALL = "from OnlineStat os order by os.id desc";
  private static final String LOADS_ALL_COUNT = "from OnlineStat os";

  public OnlineStatHibernateDAO() {
    super();
  }

  /**
   * saveOnlineStat
   *
   * @param os OnlineStat
   * @return OnlineStat
   * @todo Implement this com.laoer.bbscs.dao.IOnlineStatDAO method
   */
  public OnlineStat saveOnlineStat(OnlineStat os) {
    try {
      this.getHibernateTemplate().saveOrUpdate(os);
      return os;
    }
    catch (DataAccessException ex) {
      logger.error(ex);
      return null;
    }
  }

  /**
   * findOnlineStatByRecDate
   *
   * @param recDate String
   * @return OnlineStat
   * @todo Implement this com.laoer.bbscs.dao.IOnlineStatDAO method
   */
  public OnlineStat findOnlineStatByRecDate(String recDate) {
    List l = this.getHibernateTemplate().find(LOAD_BY_RECDATE, recDate);
    if (l == null || l.size() == 0 || l.isEmpty()) {
      return null;
    }
    else {
      return (OnlineStat) l.get(0);
    }
  }

  /**
   * getOnlineStatNum
   *
   * @return int
   * @todo Implement this com.laoer.bbscs.dao.IOnlineStatDAO method
   */
  public int getOnlineStatNum() {
    try {
      List l = this.getHibernateTemplate().find("select count(*) " + LOADS_ALL_COUNT);
      return ( (Integer) l.get(0)).intValue();
    }
    catch (DataAccessException ex) {
      logger.error(ex);
      return 0;
    }
  }

  /**
   * getOnlineStatList
   *
   * @param pages Pages
   * @return PageList
   * @todo Implement this com.laoer.bbscs.dao.IOnlineStatDAO method
   */
  public List getOnlineStatList(final int firstResult, final int maxResults) {
    return getHibernateTemplate().executeFind(new HibernateCallback() {
      public Object doInHibernate(Session s) throws HibernateException, SQLException {
        Query query = s.createQuery(LOADS_ALL);
        query.setFirstResult(firstResult);
        query.setMaxResults(maxResults);
        List list = query.list();
        return list;
      }
    });
  }
}

⌨️ 快捷键说明

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