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

📄 adimpl.java

📁 野蔷薇论坛源码 java 自己看看吧。 学习用
💻 JAVA
字号:
/* 
 * Created on 2006-3-4
 * Last modified on 2007-11-3
 * Powered by YeQiangWei.com
 */
package com.yeqiangwei.club.dao.hibernate.impl;

import java.util.List;

import org.hibernate.HibernateException;

import com.yeqiangwei.club.dao.AdDAO;
import com.yeqiangwei.club.dao.hibernate.support.HibernateFacade;
import com.yeqiangwei.club.dao.hibernate.support.HibernateProvider;
import com.yeqiangwei.club.dao.model.Ad;
import com.yeqiangwei.club.exception.DAOException;
import com.yeqiangwei.club.param.AdParameter;

public class AdImpl implements AdDAO {
	
	private static final String FIND_ADID = "from Ad where adId=?";
	
	private static final String DELETE_ADID = "delete from Ad where adId=?";
	
	private static final String DELETES_ADID = "delete from Ad where adId in (:ids)";
	
	private static final String FIND_ALL = "from Ad order by area";
	
	private static final String COUNT_ALL = "select count(adId) from Ad";
	
	private static final String FIND_FORUMID_AREA = "from Ad where forumId=? and area=? order by adId";
	
	public void create(Ad item) throws DAOException{
		HibernateProvider<Ad> facade = new HibernateFacade<Ad>();
		try{
			facade.save(item);
		}catch(HibernateException e){
			throw new DAOException(e);
		}
	}

	public void update(Ad item) throws DAOException {
        HibernateProvider<Ad> facade = new HibernateFacade<Ad>();
        try{
			facade.update(item);
		}catch(HibernateException e){
			throw new DAOException(e);
		}
	}
	
	
	public int delete(Ad item) throws DAOException {
		HibernateProvider<Ad> facade = new HibernateFacade<Ad>();
		facade.createQuery(DELETE_ADID);
		facade.setInt(0, item.getAdId());
		try{
			return facade.executeUpdate();
		}catch(HibernateException e){
			throw new DAOException(e);
		}
	}
	
	public int delete(List<Integer> ids) throws DAOException {
		HibernateProvider<Ad> facade = new HibernateFacade<Ad>();
		facade.createQuery(DELETES_ADID);
		facade.setParameterList("ids", ids);
		try{
			return facade.executeUpdate();
		}catch(HibernateException e){
			throw new DAOException(e);
		}
	}
	
	public Ad findById(int id) {
        HibernateFacade<Ad> facade = new HibernateFacade<Ad>(FIND_ADID);
        facade.setInt(0, id);
        facade.setCacheable(true); 
        facade.setMaxResults(1);
        return facade.uniqueResult();
	}
	
	public List<Ad> findAll(AdParameter param) {
		HibernateProvider<Ad> facade = new HibernateFacade<Ad>();
    	facade.createQuery(FIND_ALL);
    	facade.setFirstResult(param.getPagination().getStartRow());
        facade.setMaxResults(param.getPagination().getEndRow()); 
		return facade.executeQuery();  
	}

	public long countAll(AdParameter param) {
		HibernateProvider<Ad> facade = new HibernateFacade<Ad>();
    	facade.createQuery(COUNT_ALL);
		return facade.resultTotal();
	}

	public List<Ad> findByParameter(AdParameter param) {
		StringBuffer hql = new StringBuffer();
        hql.append("from Ad order by adId desc");
		HibernateProvider<Ad> facade = new HibernateFacade<Ad>();
    	facade.createQuery(hql);
    	facade.setFirstResult(param.getPagination().getStartRow());
        facade.setMaxResults(param.getPagination().getEndRow());
		return facade.executeQuery();  
	}

	public long countByParameter(AdParameter param) {
		StringBuffer hql = new StringBuffer();
        hql.append("select count(adId) from Ad");
		HibernateProvider<Ad> facade = new HibernateFacade<Ad>();
    	facade.createQuery(hql);
		return facade.resultTotal();
	}

	public Ad findByForumIdAndArea(int forumId, byte area) {
        HibernateFacade<Ad> facade = new HibernateFacade<Ad>(FIND_FORUMID_AREA);
        facade.setInt(0, forumId);
        facade.setByte(1, area);
        facade.setCacheable(true); 
        facade.setMaxResults(1);
        return facade.uniqueResult();
	}

}

⌨️ 快捷键说明

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