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

📄 sorthibernatedao.java

📁 是一个网站的博客系统
💻 JAVA
字号:
package com.opensource.blog.dao.hibernate;

import org.springframework.orm.hibernate3.support.*;
import com.opensource.blog.dao.SortDAO;
import com.opensource.blog.model.Sort;

import java.util.List;


public class SortHibernateDAO
    extends HibernateDaoSupport implements SortDAO {

  private static final String LOAD_BY_ID_BLOGID = "from Sort where id = ? and blogid = ?";

  private static final String GET_NUM_BY_BLOGID = "select count(*) from Sort where blogid = ?";

  private static final String LOADS_BY_BLOGID = "from Sort where blogid = ? order by id desc";

  public SortHibernateDAO() {
    super();
  }

  /**
   *
   * @param sort Sort
   * @return Sort
   * @todo Implement this com.opensource.blog.dao.SortDAO method
   */
  public Sort saveSort(Sort sort) {
    this.getHibernateTemplate().saveOrUpdate(sort);
    return sort;
  }

  /**
   *
   * @param id long
   * @param blogID long
   * @return Sort
   * @todo Implement this com.opensource.blog.dao.SortDAO method
   */
  public Sort findSortByID_BlogID(long id, long blogID) {
    Object[] o = {
        new Long(id), new Long(blogID)};
    List l = this.getHibernateTemplate().find(LOAD_BY_ID_BLOGID, o);
    if (l == null || l.isEmpty()) {
      return null;
    }
    else {
      return (Sort) l.get(0);
    }
  }

  /**
   *
   * @param blogID long
   * @return int
   * @todo Implement this com.opensource.blog.dao.SortDAO method
   */
  public int getSortCountByBlogID(long blogID) {
    List l = this.getHibernateTemplate().find(GET_NUM_BY_BLOGID, new Long(blogID));
    if (l == null || l.isEmpty()) {
      return 0;
    }
    else {
      return ( (Integer) l.get(0)).intValue();
    }
  }

  /**
   *
   * @param blogID long
   * @return List
   * @todo Implement this com.opensource.blog.dao.SortDAO method
   */
  public List findSortsByBlogID(long blogID) {
    return this.getHibernateTemplate().find(LOADS_BY_BLOGID, new Long(blogID));
  }

  /**
   *
   * @param sort Sort
   */
  public void removeSort(Sort sort) {
    this.getHibernateTemplate().delete(sort);
  }

}

⌨️ 快捷键说明

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