📄 shopimpl.java
字号:
/*
* Created on 2006-2-20
* Last modified on 2007-1-22
* Powered by YeQiangWei.com
*/
package com.yeqiangwei.club.dao.hibernate.impl;
import java.util.List;
import com.yeqiangwei.club.dao.ShopDAO;
import com.yeqiangwei.club.dao.hibernate.support.HibernateFacade;
import com.yeqiangwei.club.dao.model.Shop;
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 Shop create(Shop item) {
HibernateFacade<Shop> facade = new HibernateFacade<Shop>();
facade.save(item);
return item;
}
public Shop update(Shop item) {
HibernateFacade<Shop> facade = new HibernateFacade<Shop>();
facade.update(item);
return item;
}
public int delete(Shop item) {
HibernateFacade<Shop> facade = new HibernateFacade<Shop>();
facade.createQuery(DELETE_SHOPID);
facade.setInt(0,item.getShopId());
int c = facade.executeUpdate();
return c;
}
public int delete(List ids) {
HibernateFacade<Shop> facade = new HibernateFacade<Shop>();
facade.createQuery(DELETES_SHOPID);
facade.setParameterList("ids",ids);
int c = facade.executeUpdate();
return c;
}
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());
List<Shop> list = facade.executeQuery();
return list;
}
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);
long c = facade.resultTotal();
return c;
}
public List findAll(ShopParameter param) {
return null;
}
public long countAll(ShopParameter param) {
return 0;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -