📄 afficheimpl.java
字号:
/*
* Created on 2005-10-31
* 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.AfficheDAO;
import com.yeqiangwei.club.dao.hibernate.support.HibernateFacade;
import com.yeqiangwei.club.dao.hibernate.support.HibernateProvider;
import com.yeqiangwei.club.dao.model.Affiche;
import com.yeqiangwei.club.exception.DAOException;
import com.yeqiangwei.club.param.AfficheParameter;
public class AfficheImpl implements AfficheDAO{
private static final String FIND_AFFICHEID = "from Affiche where afficheId=?";
private static final String FIND_ALL = "from Affiche order by afficheId desc";
private static final String COUNT_ALL = "select count(afficheId) from Affiche order by afficheId desc";
private static final String DELETE_AFFICHEID = "delete from Affiche where afficheId=?";
private static final String DELETES_AFFICHEID = "delete from Affiche where afficheId in (:ids)";
public void create(Affiche item) throws DAOException {
HibernateProvider<Affiche> facade = new HibernateFacade<Affiche>();
try{
facade.save(item);
}catch(HibernateException e){
throw new DAOException(e);
}
}
public void update(Affiche item) throws DAOException {
HibernateProvider<Affiche> facade = new HibernateFacade<Affiche>();
try{
facade.update(item);
}catch(HibernateException e){
throw new DAOException(e);
}
}
public int delete(Affiche item) throws DAOException {
HibernateProvider<Affiche> facade = new HibernateFacade<Affiche>();
facade.createQuery(DELETE_AFFICHEID);
facade.setInt(0, item.getAfficheId());
try{
return facade.executeUpdate();
}catch(HibernateException e){
throw new DAOException(e);
}
}
public int delete(List<Integer> ids) throws DAOException {
HibernateProvider<Affiche> facade = new HibernateFacade<Affiche>();
facade.createQuery(DELETES_AFFICHEID);
facade.setParameterList("ids", ids);
try{
return facade.executeUpdate();
}catch(HibernateException e){
throw new DAOException(e);
}
}
public Affiche findById(int id) {
HibernateFacade<Affiche> facade = new HibernateFacade<Affiche>(FIND_AFFICHEID);
facade.setInt(0, id);
facade.setCacheable(true);
facade.setMaxResults(1);
return facade.uniqueResult();
}
public List<Affiche> findByParameter(AfficheParameter param) {
StringBuffer hql = new StringBuffer();
hql.append("from Affiche ");
if(param.getForumId()!=null){
hql.append(" where forumId=");
hql.append(param.getForumId().intValue());
hql.append(" or forumId=-1");
}
hql.append(" order by afficheId desc");
HibernateProvider<Affiche> facade = new HibernateFacade<Affiche>();
facade.createQuery(hql);
facade.setFirstResult(param.getPagination().getStartRow());
facade.setMaxResults(param.getPagination().getEndRow());
return facade.executeQuery();
}
public long countByParameter(AfficheParameter param) {
StringBuffer hql = new StringBuffer();
hql.append("select count(afficheId) from Affiche ");
if(param.getForumId()!=null){
hql.append(" where forumId=");
hql.append(param.getForumId().intValue());
hql.append(" or forumId=-1");
}
hql.append(" order by afficheId desc");
HibernateProvider<Affiche> facade = new HibernateFacade<Affiche>();
facade.createQuery(hql);
return facade.resultTotal();
}
public List<Affiche> findAll(AfficheParameter param) {
HibernateProvider<Affiche> facade = new HibernateFacade<Affiche>();
facade.createQuery(FIND_ALL);
facade.setFirstResult(param.getPagination().getStartRow());
facade.setMaxResults(param.getPagination().getEndRow());
return facade.executeQuery();
}
public long countAll(AfficheParameter param) {
HibernateProvider<Affiche> facade = new HibernateFacade<Affiche>();
facade.createQuery(COUNT_ALL);
return facade.resultTotal();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -