goodsimpl.java

来自「详细的建站源码 详细的建站源码 详细的建站源码 详细的建站源码」· Java 代码 · 共 94 行

JAVA
94
字号
/* 
 * Created on 2006-2-20
 * Last modified on 2007-1-21
 * Powered by YeQiangWei.com
 */
package com.yeqiangwei.club.dao.hibernate.impl;

import java.util.List;

import com.yeqiangwei.club.dao.GoodsDAO;
import com.yeqiangwei.club.dao.hibernate.support.HibernateFacade;
import com.yeqiangwei.club.dao.model.Goods;
import com.yeqiangwei.club.param.GoodsParameter;

public class GoodsImpl implements GoodsDAO{
	
	private static final String FIND_TYPE = "from Goods where type=?";
	
	private static final String FIND_GOODSID = "from Goods where goodsId=?";
	
	private static final String FIND_ALL = "from Goods order by type asc, goodsId desc";
	
	private static final String DELETE_GOODSID = "delete Goods where goodsId=?";
	
	private static final String DELETES_GOODSID = "delete Goods where goodsId in (:ids)";

	public Goods create(Goods item) {
		HibernateFacade<Goods> facade = new HibernateFacade<Goods>();
		item = facade.save(item);		
		return item;
	}

	public Goods update(Goods item) {
		HibernateFacade<Goods> facade = new HibernateFacade<Goods>();
		facade.update(item);
		return item;
	}

	public int delete(Goods item) {
		HibernateFacade<Goods> facade = new HibernateFacade<Goods>();
		facade.createQuery(DELETE_GOODSID);
		facade.setInt(0, item.getGoodsId());
		int c = facade.executeUpdate();
		return c;
	}

	public int delete(List ids) {
		HibernateFacade<Goods> facade = new HibernateFacade<Goods>();
		facade.createQuery(DELETES_GOODSID);
		facade.setParameterList("ids", ids);
		int c = facade.executeUpdate();
		return c;
	}

	public Goods findById(int id) {
		Goods item = null;
        HibernateFacade<Goods> facade = new HibernateFacade<Goods>(FIND_GOODSID);
        facade.setInt(0, id);
        facade.setCacheable(true); 
        facade.setMaxResults(1);
        item = facade.uniqueResult();
        return item;
	}

	public List<Goods> findByParameter(GoodsParameter param) {
		return null;
	}

	public long countByParameter(GoodsParameter param) {
		return 0;
	}

	public List findAll(GoodsParameter param) {
		List list = null;
		HibernateFacade facade = new HibernateFacade();
    	facade.createQuery(FIND_ALL);
        list = facade.executeQuery();  
		return list;
	}

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

	public Goods findByType(byte type) {
		HibernateFacade facade = new HibernateFacade();
    	facade.createQuery(FIND_TYPE);
        facade.setMaxResults(1);
        Goods item = (Goods) facade.uniqueResult();
		return item;
	}
	
}

⌨️ 快捷键说明

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