📄 businessimpl.java
字号:
/*
* Created on 2005-11-11
* 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.BusinessDAO;
import com.yeqiangwei.club.dao.hibernate.support.HibernateFacade;
import com.yeqiangwei.club.dao.model.Business;
import com.yeqiangwei.club.param.BusinessParameter;
public class BusinessImpl implements BusinessDAO{
private static final String FIND_BUSINESSID = "from Business where businessId=? order by businessId desc";
private static final String FIND_ALL = "from Business order by businessId desc";
private static final String COUNT_ALL = "select count(businessId) from Business order by businessId desc";
private static final String DELETE_USERID = "delete from Business where userId=?";
private static final String DELETES_BUSINESSID = "delete from Business where businessId in (:ids)";
private static final String DELETE_BUSINESSID = "delete from Business where businessId=?";
public Business create(Business item) {
HibernateFacade<Business> facade = new HibernateFacade<Business>();
item = facade.save(item);
return item;
}
public Business update(Business item) {
HibernateFacade<Business> facade = new HibernateFacade<Business>();
item = facade.update(item);
return item;
}
public int delete(Business item) {
HibernateFacade<Business> facade = new HibernateFacade<Business>();
facade.createQuery(DELETE_BUSINESSID);
facade.setInt(0,item.getBusinessId());
int c = facade.executeUpdate();
return c;
}
public int delete(List ids) {
HibernateFacade<Business> facade = new HibernateFacade<Business>();
facade.createQuery(DELETES_BUSINESSID);
facade.setParameterList("ids",ids);
int c = facade.executeUpdate();
return c;
}
public int deleteByUserId(int userId) {
HibernateFacade<Business> facade = new HibernateFacade<Business>();
facade.createQuery(DELETE_USERID);
facade.setInt(0, userId);
int c = facade.executeUpdate();
return c;
}
public Business findById(int id) {
Business item = null;
HibernateFacade<Business> facade = new HibernateFacade<Business>(FIND_BUSINESSID);
facade.setInt(0, id);
facade.setCacheable(true);
facade.setMaxResults(1);
item = (Business)facade.uniqueResult();
return item;
}
public List<Business> findByParameter(BusinessParameter param) {
List<Business> list = null;
StringBuffer hql = new StringBuffer();
hql.append("from Business ");
if(param.getUserId()!=null){
hql.append(" where userId=");
hql.append(param.getUserId().intValue());
if(param.getType()!=null){
hql.append(" and type=");
hql.append(param.getType().intValue());
}
}else{
if(param.getType()!=null){
hql.append(" where type=");
hql.append(param.getType().intValue());
}
}
hql.append(" order by businessId desc");
HibernateFacade<Business> facade = new HibernateFacade<Business>();
facade.createQuery(hql);
facade.setFirstResult(param.getPagination().getStartRow());
facade.setMaxResults(param.getPagination().getEndRow());
list = facade.executeQuery();
return list;
}
public long countByParameter(BusinessParameter param) {
StringBuffer hql = new StringBuffer();
hql.append("select count(businessId) from Business ");
if(param.getUserId()!=null){
hql.append(" where userId=");
hql.append(param.getUserId().intValue());
if(param.getType()!=null){
hql.append(" and type=");
hql.append(param.getType().intValue());
}
}else{
if(param.getType()!=null){
hql.append(" where type=");
hql.append(param.getType().intValue());
}
}
HibernateFacade facade = new HibernateFacade();
facade.createQuery(hql);
long c = facade.resultTotal();
return c;
}
public List findAll(BusinessParameter param) {
List list = null;
HibernateFacade facade = new HibernateFacade();
facade.createQuery(FIND_ALL);
facade.setFirstResult(param.getPagination().getStartRow());
facade.setMaxResults(param.getPagination().getEndRow());
list = facade.executeQuery();
return list;
}
public long countAll(BusinessParameter param) {
HibernateFacade facade = new HibernateFacade();
facade.createQuery(COUNT_ALL);
long c = facade.resultTotal();
return c;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -