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

📄 shopimpl.java

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

public class ShopImpl implements ShopDAO{
	
	private static final String FIND_SHOPID = "from Shop where shopId=?";
	
	private static final String DELETE_SHOPID = "delete from Shop where shopId=?";
	
	private static final String DELETES_SHOPID = "delete from Shop where shopId in (:ids)";

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

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

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

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

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

	public List<Shop> findByParameter(ShopParameter param) {
		StringBuffer hql = new StringBuffer();
		hql.append("from Shop where shopId>0");
		if(param.getType()!=null){
			hql.append(" and type=");
			hql.append(param.getType().byteValue());
		}
		if(param.getUserId()!=null){
			hql.append(" and userId=");
			hql.append(param.getUserId().intValue());
		}
		if(param.getUserGoodesId()!=null){
			hql.append(" and userGoodsId=");
			hql.append(param.getUserGoodesId().intValue());
		}
		hql.append(" order shopId desc");
		HibernateFacade<Shop> facade = new HibernateFacade<Shop>();
		facade.createQuery(hql);
		facade.setFirstResult(param.getPagination().getStartRow());
		facade.setMaxResults(param.getPagination().getEndRow());
		return facade.executeQuery();
	}

	public long countByParameter(ShopParameter param) {
		StringBuffer hql = new StringBuffer();
		hql.append("select count(shopId) from Shop where shopId>0");
		if(param.getType()!=null){
			hql.append(" and type=");
			hql.append(param.getType().byteValue());
		}
		if(param.getUserId()!=null){
			hql.append(" and userId=");
			hql.append(param.getUserId().intValue());
		}
		if(param.getUserGoodesId()!=null){
			hql.append(" and userGoodsId=");
			hql.append(param.getUserGoodesId().intValue());
		}
		HibernateFacade<Shop> facade = new HibernateFacade<Shop>();
		facade.createQuery(hql);
		return facade.resultTotal();
	}

	public List<Shop> findAll(ShopParameter param) {
		return null;
	}

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

⌨️ 快捷键说明

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