⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 countersimpl.java

📁 这是一款最新的野蔷薇论坛源码,有需要的朋友可以尽情下载
💻 JAVA
字号:
/* 
 * Created on 2007-1-21
 * 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.CountersDAO;
import com.yeqiangwei.club.dao.hibernate.support.HibernateFacade;
import com.yeqiangwei.club.dao.model.Counters;
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 Counters create(Counters item) {
		HibernateFacade<Counters> facade = new HibernateFacade<Counters>();
		item = facade.save(item);		
		return item;
	}

	public Counters update(Counters item) {
        HibernateFacade<Counters> facade = new HibernateFacade<Counters>();
        item = facade.update(item);
        return item; 
	}

	public int delete(Counters item) {
    	HibernateFacade<Counters> facade = new HibernateFacade<Counters>();
		facade.createQuery(DELETE_COUNTERSID);
		facade.setInt(0, item.getCountersId());
		int c = facade.executeUpdate();
		return c;
	}

	public int delete(List ids) {
		HibernateFacade<Counters> facade = new HibernateFacade<Counters>();
		facade.createQuery(DELETES_COUNTERSID);
		facade.setParameterList("ids", ids);
		int c = facade.executeUpdate();
		return c;
	}

	public Counters findById(int id) {
		Counters item = null;
        HibernateFacade<Counters> facade = new HibernateFacade<Counters>(FIND_COUNTERSID);
        facade.setInt(0, id);
        facade.setCacheable(true); 
        facade.setMaxResults(1);
        item = facade.uniqueResult();
        return item;
	}

	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());
			}
		}
		HibernateFacade<Counters> facade = new HibernateFacade<Counters>();
	    facade.createQuery(hql);
	    facade.setFirstResult(param.getPagination().getStartRow());
	    facade.setMaxResults(param.getPagination().getEndRow());
	    List<Counters> list = facade.executeQuery();  
		return list;   
	}

	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");
		HibernateFacade facade = new HibernateFacade();
	    facade.createQuery(hql);
		long c = facade.resultTotal();
		return c;
	}


	public List findAll(CounterParameter param) {
		HibernateFacade facade = new HibernateFacade();
	    facade.createQuery(FIND_ALL);
	    facade.setFirstResult(param.getPagination().getStartRow());
	    facade.setMaxResults(param.getPagination().getEndRow());
	    List list = facade.executeQuery();  
		return list;   
	}

	public long countAll(CounterParameter param) {
		HibernateFacade facade = new HibernateFacade();
    	facade.createQuery(COUNT_ALL);
    	long c = facade.resultTotal();
		return c;
	}

	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());
			}
		}
		
		HibernateFacade facade = new HibernateFacade();
	    facade.createQuery(hql);
	    facade.setMaxResults(1);
	    Counters item = (Counters) facade.uniqueResult();
		return item;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -