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

📄 favoriteimpl.java

📁 野蔷薇论坛源码 java 自己看看吧。 学习用
💻 JAVA
字号:
/* 
 * Created on 2005-11-30
 * 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.FavoriteDAO;
import com.yeqiangwei.club.dao.hibernate.support.HibernateFacade;
import com.yeqiangwei.club.dao.hibernate.support.HibernateProvider;
import com.yeqiangwei.club.dao.model.Favorite;
import com.yeqiangwei.club.exception.DAOException;
import com.yeqiangwei.club.param.FavoriteParameter;

public class FavoriteImpl implements FavoriteDAO{
	
	private static final String FIND_FAVORITEID = "from Favorite where favoriteId=?";

	private static final String DELETE_FAVORITEID = "delete from Favorite where favoriteId=?";
	
	private static final String DELETES_FAVORITEID = "delete from Favorite where favoriteId in (:ids)";
	
	public void create(Favorite item) throws DAOException {
		HibernateProvider<Favorite> facade = new HibernateFacade<Favorite>();
		try{
			facade.save(item);
		}catch(HibernateException e){
			throw new DAOException(e);
		}
	}

	public void update(Favorite item) throws DAOException {
		HibernateProvider<Favorite> facade = new HibernateFacade<Favorite>();
		try{
			facade.update(item);
		}catch(HibernateException e){
			throw new DAOException(e);
		}
	}

	public int delete(Favorite item) throws DAOException {
    	HibernateProvider<Favorite> facade = new HibernateFacade<Favorite>();
		facade.createQuery(DELETE_FAVORITEID);
		facade.setInt(0, item.getFavoriteId());
		try{
			return facade.executeUpdate();
		}catch(HibernateException e){
			throw new DAOException(e);
		}
	}

	public int delete(List<Integer> ids) throws DAOException {
    	HibernateProvider<Favorite> facade = new HibernateFacade<Favorite>();
		facade.createQuery(DELETES_FAVORITEID);
		facade.setParameterList("ids",ids);
		try{
			return facade.executeUpdate();
		}catch(HibernateException e){
			throw new DAOException(e);
		}
	}

	public Favorite findById(int id) {
		HibernateFacade<Favorite> facade = new HibernateFacade<Favorite>();
		facade.createQuery(FIND_FAVORITEID);
		facade.setInt(0,id);
		return facade.uniqueResult();
	}

	public List<Favorite> findByParameter(FavoriteParameter param) {
		StringBuffer hql = new StringBuffer();
		hql.append("from Favorite where favoriteId>0");
		if(param.getForumId()!=null){
			hql.append(" and forumId=");
			hql.append(param.getForumId().intValue());
		}
		if(param.getMyUserId()!=null){
			hql.append(" and myUserId=");
			hql.append(param.getMyUserId().intValue());
		}
		if(param.getTopicId()!=null){
			hql.append(" and topicId=");
			hql.append(param.getTopicId().intValue());
		}
		if(param.getUserId()!=null){
			hql.append(" and userId=");
			hql.append(param.getUserId().intValue());
		}
		hql.append(" order favoriteId desc");
		HibernateFacade<Favorite> facade = new HibernateFacade<Favorite>();
		facade.createQuery(hql);
		facade.setFirstResult(param.getPagination().getStartRow());
		facade.setMaxResults(param.getPagination().getEndRow());
		return facade.executeQuery();
	}

	public long countByParameter(FavoriteParameter param) {
		StringBuffer hql = new StringBuffer();
		hql.append("select count(favoriteId) from Favorite where favoriteId>0");
		if(param.getForumId()!=null){
			hql.append(" and forumId=");
			hql.append(param.getForumId().intValue());
		}
		if(param.getMyUserId()!=null){
			hql.append(" and myUserId=");
			hql.append(param.getMyUserId().intValue());
		}
		if(param.getTopicId()!=null){
			hql.append(" and topicId=");
			hql.append(param.getTopicId().intValue());
		}
		if(param.getUserId()!=null){
			hql.append(" and userId=");
			hql.append(param.getUserId().intValue());
		}
		HibernateFacade<Favorite> facade = new HibernateFacade<Favorite>();
		facade.createQuery(hql);
		return facade.resultTotal();
	}

	public List<Favorite> findAll(FavoriteParameter param) {
		return null;
	}

	public long countAll(FavoriteParameter param) {
		return 0;
	}
	




}

⌨️ 快捷键说明

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