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

📄 choicehibernatedao.java

📁 一个jsp写的bbs
💻 JAVA
字号:
package com.laoer.bbscs.dao.hibernate;

import org.springframework.orm.hibernate3.support.*;
import com.laoer.bbscs.dao.ChoiceDAO;
import com.laoer.bbscs.bean.Choice;
import java.util.List;
import org.hibernate.Session;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.springframework.orm.hibernate3.HibernateCallback;
import java.sql.SQLException;

/**
 * <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 ChoiceHibernateDAO
    extends HibernateDaoSupport implements ChoiceDAO {

  private static final String GET_NUM_BY_CID = "selete count(id) from Choice where categoryID = ?";

  private static final String LOADS_BY_CID = "from Choice where categoryID = ? order by createTime desc";

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

  private static final String DELETE_BY_ID = "delete from Choice where id = ?";

  private static final String DELETE_BY_CID = "delete from Choice where categoryID = ?";

  private static final String LOAD_BY_CID_PID = "from Choice where categoryID = ? and postID = ?";

  private static final String DELS_IN_IDS = "delete from Choice where id in (:ids)";

  public ChoiceHibernateDAO() {
    super();
  }

  /**
   *
   * @param choice Choice
   * @return Choice
   * @todo Implement this com.laoer.bbscs.dao.ChoiceDAO method
   */
  public Choice saveChoice(Choice choice) {
    this.getHibernateTemplate().saveOrUpdate(choice);
    return choice;
  }

  /**
   *
   * @param id String
   * @return Choice
   * @todo Implement this com.laoer.bbscs.dao.ChoiceDAO method
   */
  public Choice findChoiceById(String id) {
    return (Choice)this.getHibernateTemplate().get(Choice.class, id);
  }

  public Choice findChoiceByCategoryIDPostID(String categoryID, String postID) {
    Object[] o = {categoryID, postID};
    List l = this.getHibernateTemplate().find(LOAD_BY_CID_PID, o);
    if (l == null || l.isEmpty()) {
      return null;
    }
    else {
      return (Choice) l.get(0);
    }
  }

  public int getChoicesNumByCategoryID(String categoryID) {
    List l = this.getHibernateTemplate().find(GET_NUM_BY_CID, categoryID);
    if (l == null || l.isEmpty()) {
      return 0;
    }
    else {
      return ( (Integer) l.get(0)).intValue();
    }
  }

  /**
   *
   * @param categoryID String
   * @param firstResult int
   * @param maxResults int
   * @return List
   * @todo Implement this com.laoer.bbscs.dao.ChoiceDAO method
   */
  public List findChoicesByCategoryID(final String categoryID, final int firstResult, final int maxResults) {
    return getHibernateTemplate().executeFind(new HibernateCallback() {
      public Object doInHibernate(Session s) throws HibernateException, SQLException {
        Query query = s.createQuery(LOADS_BY_CID);
        query.setString(0, categoryID);
        query.setFirstResult(firstResult);
        query.setMaxResults(maxResults);
        List list = query.list();
        return list;
      }
    });
  }

  /**
   *
   * @param categoryID String
   * @return List
   */
  public List findChoicesByCategoryID(String categoryID) {
    return this.getHibernateTemplate().find(LOADS_BY_CID, categoryID);
  }

  /**
   *
   * @param ids List
   * @return List
   * @todo Implement this com.laoer.bbscs.dao.ChoiceDAO method
   */
  public List findChoicesInIds(final List ids) {
    return getHibernateTemplate().executeFind(new HibernateCallback() {
      public Object doInHibernate(Session s) throws HibernateException, SQLException {
        Query query = s.createQuery(LOADS_IN_IDS);
        query.setParameterList("ids", ids);
        List list = query.list();
        return list;
      }
    });
  }

  /**
   *
   * @param choice Choice
   * @todo Implement this com.laoer.bbscs.dao.ChoiceDAO method
   */
  public void removeChoice(Choice choice) {
    this.getHibernateTemplate().delete(choice);
  }

  /**
   *
   * @param id String
   * @todo Implement this com.laoer.bbscs.dao.ChoiceDAO method
   */
  public void removeChoiceById(final String id) {
    getHibernateTemplate().execute(new HibernateCallback() {
      public Object doInHibernate(Session s) throws HibernateException, SQLException {
        Query query = s.createQuery(DELETE_BY_ID);
        query.setString(0, id);
        query.executeUpdate();
        return null;
      }
    });
  }

  public void removeChoiceByCategoryID(final String categoryID) {
    getHibernateTemplate().execute(new HibernateCallback() {
      public Object doInHibernate(Session s) throws HibernateException, SQLException {
        Query query = s.createQuery(DELETE_BY_CID);
        query.setString(0, categoryID);
        query.executeUpdate();
        return null;
      }
    });
  }

  public void removeChoice(final List ids) {
    getHibernateTemplate().execute(new HibernateCallback() {
      public Object doInHibernate(Session s) throws HibernateException, SQLException {
        Query query = s.createQuery(DELS_IN_IDS);
        query.setParameterList("ids", ids);
        query.executeUpdate();
        return null;
      }
    });
  }
}

⌨️ 快捷键说明

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