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