📄 favoriteforumimpl.java
字号:
/*
* Created on 2007-5-10
* 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.FavoriteForumDAO;
import com.yeqiangwei.club.dao.hibernate.support.HibernateFacade;
import com.yeqiangwei.club.dao.hibernate.support.HibernateProvider;
import com.yeqiangwei.club.dao.model.FavoriteForum;
import com.yeqiangwei.club.exception.DAOException;
import com.yeqiangwei.club.param.FavoriteParameter;
public class FavoriteForumImpl implements FavoriteForumDAO{
//private static final String DELETE_FAVORITEFORUMID = "delete from FavoriteForum where favoriteForumId=?";
private static final String DELETES_FAVORITEFORUMID = "delete from FavoriteForum where favoriteForumId in (:ids)";
private static final String FIND_FAVORITEFORUMID = "from FavoriteForum where favoriteForumId=?";
private static final String FIND_USERID_FORUMID = "from FavoriteForum where userId=? and forumId=?";
public void create(FavoriteForum item) throws DAOException {
HibernateProvider<FavoriteForum> facade = new HibernateFacade<FavoriteForum>();
try{
facade.save(item);
}catch(HibernateException e){
throw new DAOException(e);
}
}
public void update(FavoriteForum item) throws DAOException {
HibernateProvider<FavoriteForum> facade = new HibernateFacade<FavoriteForum>();
try{
facade.save(item);
}catch(HibernateException e){
throw new DAOException(e);
}
}
public int delete(FavoriteForum item) throws DAOException {
StringBuffer hql = new StringBuffer();
hql.append("delete from FavoriteForum");
if(item.getFavoriteForumId()>0){
hql.append(" where favoriteForumId=");
hql.append(item.getFavoriteForumId());
}
else if(item.getUserId()>0){
hql.append(" where userId=");
hql.append(item.getUserId());
if(item.getForumId()>0){
hql.append(" and forumId=");
hql.append(item.getForumId());
}
}
else if(item.getForumId()>0){
hql.append(" where forumId=");
hql.append(item.getForumId());
}
HibernateProvider<FavoriteForum> facade = new HibernateFacade<FavoriteForum>();
facade.createQuery(hql);
try{
return facade.executeUpdate();
}catch(HibernateException e){
throw new DAOException(e);
}
}
public int delete(List<Integer> ids) throws DAOException {
HibernateProvider<FavoriteForum> facade = new HibernateFacade<FavoriteForum>();
facade.createQuery(DELETES_FAVORITEFORUMID);
facade.setParameterList("ids",ids);
try{
return facade.executeUpdate();
}catch(HibernateException e){
throw new DAOException(e);
}
}
public FavoriteForum findById(int id) {
HibernateProvider<FavoriteForum> facade = new HibernateFacade<FavoriteForum>();
facade.createQuery(FIND_FAVORITEFORUMID);
facade.setInt(0,id);
return facade.uniqueResult();
}
public List<FavoriteForum> findByParameter(FavoriteParameter param) {
StringBuffer hql = new StringBuffer();
hql.append("from FavoriteForum where favoriteForumId>0 ");
if(param.getUserId()!=null){
hql.append(" and userId=");
hql.append(param.getUserId().intValue());
}
if(param.getForumId()!=null){
hql.append(" and forumId=");
hql.append(param.getForumId().intValue());
}
hql.append(" order by favoriteForumId desc ");
HibernateProvider<FavoriteForum> facade = new HibernateFacade<FavoriteForum>();
facade.createQuery(hql);
facade.setFirstResult(param.getPagination().getStartRow());
facade.setMaxResults(param.getPagination().getEndRow());
return facade.executeQuery();
}
public long countByParameter(FavoriteParameter param) {
StringBuffer hql = new StringBuffer();
hql.append("select count(favoriteForumId) from FavoriteForum where favoriteForumId>0 ");
if(param.getUserId()!=null){
hql.append(" and userId=");
hql.append(param.getUserId().intValue());
}
if(param.getForumId()!=null){
hql.append(" and forumId=");
hql.append(param.getForumId().intValue());
}
HibernateProvider<FavoriteForum> facade = new HibernateFacade<FavoriteForum>();
facade.createQuery(hql);
facade.setCacheable(true);
return facade.resultTotal();
}
public FavoriteForum findOnly(int userId, int forumId) {
HibernateProvider<FavoriteForum> facade = new HibernateFacade<FavoriteForum>();
facade.createQuery(FIND_USERID_FORUMID);
facade.setInt(0,userId);
facade.setInt(1, forumId);
facade.setMaxResults(1);
return facade.uniqueResult();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -