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

📄 blackuserhibernatedao.java

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

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

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

  private static final String LOAD_BU =
      "from BlackUser bu where bu.atSite = ? and bu.atBoard = ? and bu.atBoards = ? order by bu.id desc";
  private static final String LOAD_BU_BYUSERNAME =
      "from BlackUser bu where bu.userName = ? and bu.atSite = ? and bu.atBoard = ? and bu.atBoards = ?";

  public BlackUserHibernateDAO() {
    super();
  }

  /**
   *
   * @param bu BlackUser
   * @return BlackUser
   * @todo Implement this com.laoer.bbscs.dao.IBlackUserDAO method
   */
  public BlackUser saveBlackUser(BlackUser bu) {
    try {
      this.getHibernateTemplate().saveOrUpdate(bu);
      return bu;
    }
    catch (DataAccessException ex) {
      logger.error(ex);
      return null;
    }
  }

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

  public BlackUser findBlackUserByUserName(String userName, short atSite,
                                           long atBoard, long atBoards) {
    Object[] o = {userName, new Short(atSite), new Long(atBoard), new Long(atBoards)};
    try {
      List l = this.getHibernateTemplate().find(LOAD_BU_BYUSERNAME, o);
      if (l == null || l.isEmpty()) {
        return null;
      }
      else {
        return (BlackUser) l.get(0);
      }
    }
    catch (DataAccessException ex) {
      logger.error(ex);
      return null;
    }
  }

  /**
   *
   * @param atSite short
   * @param atBoard long
   * @param atBoards long
   * @return List
   * @todo Implement this com.laoer.bbscs.dao.IBlackUserDAO method
   */
  public List findBlackUserList(short atSite, long atBoard, long atBoards) {
    try {
      Object[] o = {new Short(atSite), new Long(atBoard), new Long(atBoards)};
      List l = this.getHibernateTemplate().find(LOAD_BU, o);
      return l;
    }
    catch (DataAccessException ex) {
      logger.error(ex);
      return new ArrayList();
    }
  }

  public int getBlackUserNum(short atSite, long atBoard, long atBoards) {
    try {
      Object[] o = {new Short(atSite), new Long(atBoard), new Long(atBoards)};
      List l = this.getHibernateTemplate().find("select count(bu.id) " + LOAD_BU, o);
      if (l != null && !l.isEmpty()) {
        return ( (Integer) l.get(0)).intValue();
      }
      else {
        return 0;
      }
    }
    catch (DataAccessException ex) {
      logger.error(ex);
      return 0;
    }
  }

  public List findBlackUserList(final short atSite, final long atBoard, final long atBoards,
                                final int firstResult, final int maxResults) {
    return getHibernateTemplate().executeFind(new HibernateCallback() {
      public Object doInHibernate(Session s) throws HibernateException, SQLException {

        Query query = s.createQuery(LOAD_BU);
        query.setShort(0, atSite);
        query.setLong(1, atBoard);
        query.setLong(2, atBoards);
        query.setFirstResult(firstResult);
        query.setMaxResults(maxResults);

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

  }

  /**
   *
   * @param bu BlackUser
   * @todo Implement this com.laoer.bbscs.dao.IBlackUserDAO method
   */
  public void removeBlackUser(BlackUser bu) {
    this.getHibernateTemplate().delete(bu);
  }

}

⌨️ 快捷键说明

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