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

📄 counterimpl.java

📁 野蔷薇论坛源码 java 自己看看吧。 学习用
💻 JAVA
字号:
/*
 * Created on 2006-1-22
 * Last modified on 2007-1-21
 * Powered by YeQiangWei.com
 */
package com.yeqiangwei.club.dao.hibernate.impl;

import java.util.List;

import org.hibernate.HibernateException;

import com.yeqiangwei.club.dao.CounterDAO;
import com.yeqiangwei.club.dao.hibernate.support.HibernateFacade;
import com.yeqiangwei.club.dao.hibernate.support.HibernateProvider;
import com.yeqiangwei.club.dao.model.Counter;
import com.yeqiangwei.club.exception.DAOException;
import com.yeqiangwei.club.param.CounterParameter;

public class CounterImpl implements CounterDAO{
	
	private static final String FIND_ALL = "from Counter ";
	
	private static final String COUNT_ALL = "select count(counterId) from Counter";
	
	private static final String FIND_COUNTERID = "from Counter where counterId=?";
	
	private static final String DELETE_COUNTERID = "delete from Counter where counterId=?";
	
	private static final String DELETES_COUNTERID = "delete from Counter where counterId in (:ids)";

	public void create(Counter item) throws DAOException {
		HibernateProvider<Counter> facade = new HibernateFacade<Counter>();
		try{
			facade.save(item);
		}catch(HibernateException e){
			throw new DAOException(e);
		}
	}

	public void update(Counter item) throws DAOException {
        HibernateProvider<Counter> facade = new HibernateFacade<Counter>();
		try{
			facade.update(item);
		}catch(HibernateException e){
			throw new DAOException(e);
		}
	}

	public int delete(Counter item) throws DAOException {
    	HibernateProvider<Counter> facade = new HibernateFacade<Counter>();
		facade.createQuery(DELETE_COUNTERID);
		facade.setInt(0, item.getCounterId());
		try{
			return facade.executeUpdate();
		}catch(HibernateException e){
			throw new DAOException(e);
		}
	}

	public int delete(List<Integer> ids) throws DAOException {
		HibernateProvider<Counter> facade = new HibernateFacade<Counter>();
		facade.createQuery(DELETES_COUNTERID);
		facade.setParameterList("ids", ids);
		try{
			return facade.executeUpdate();
		}catch(HibernateException e){
			throw new DAOException(e);
		}
	}

	public Counter findById(int id) {
        HibernateFacade<Counter> facade = new HibernateFacade<Counter>(FIND_COUNTERID);
        facade.setInt(0, id);
        facade.setMaxResults(1);
        return facade.uniqueResult();
	}


	public List<Counter> findByParameter(CounterParameter param) {
		return null;
	}

	public long countByParameter(CounterParameter param) {
		return 0;
	}

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

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

	public Counter findOnly() {
		HibernateProvider<Counter> facade = new HibernateFacade<Counter>();
	    facade.createQuery(FIND_ALL);
	    facade.setMaxResults(1);
		return facade.uniqueResult();
	}
}

⌨️ 快捷键说明

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