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

📄 ruleimpl.java

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

import java.util.List;

import org.apache.log4j.Logger;
import org.hibernate.HibernateException;

import com.yeqiangwei.club.dao.RuleDAO;
import com.yeqiangwei.club.dao.hibernate.support.HibernateFacade;
import com.yeqiangwei.club.dao.hibernate.support.HibernateProvider;
import com.yeqiangwei.club.dao.model.Rule;
import com.yeqiangwei.club.exception.DAOException;
import com.yeqiangwei.club.param.RuleParameter;

public class RuleImpl  implements RuleDAO{
	
	private Logger logger = Logger.getLogger(RuleImpl.class);
	
	private static final String FIND_RULEID = "from com.yeqiangwei.club.dao.model.Rule where ruleId=?";
	
	private static final String FIND_FORUMID = "from com.yeqiangwei.club.dao.model.Rule where forumId=?";
	
	private static final String DELETE_RULEID = "delete from com.yeqiangwei.club.dao.model.Rule where ruleId=?";
	
	private static final String DELETES_RULEID = "delete from com.yeqiangwei.club.dao.model.Rule where ruleId in (:ids)";
	
	/*
	public static void main(String args[]){
		com.yeqiangwei.club.dao.hibernate.ConnectionManager.init();
		RuleImpl r = new RuleImpl();
		RuleParameter p = new RuleParameter();
		r.findByParameter(p);
	}
	*/
	
	public void create(Rule item) throws DAOException {
		HibernateProvider<Rule> facade = new HibernateFacade<Rule>();
		try{
			facade.save(item);
		}catch(HibernateException e){
			throw new DAOException(e);
		}
	}

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

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

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

	public Rule findById(int id) {
		HibernateFacade<Rule> facade = new HibernateFacade<Rule>();
		facade.createQuery(FIND_RULEID);
		facade.setInt(0,id);
		facade.setMaxResults(1);
		Rule item = (Rule) facade.uniqueResult();
		return item;
	}
	
	public Rule findByForumId(int forumId) {
		HibernateFacade<Rule> facade = new HibernateFacade<Rule>();
		facade.createQuery(FIND_FORUMID);
		facade.setInt(0,forumId);
		facade.setMaxResults(1);
		Rule item = (Rule) facade.uniqueResult();
		return item;
	}

	public List<Rule> findByParameter(RuleParameter param) {
		StringBuffer hql = new StringBuffer();
		hql.append("from com.yeqiangwei.club.dao.model.Rule ");
		if(param.getForumId()!=null){
			hql.append(" where forumId=");
			hql.append(param.getForumId().intValue());
		}
		HibernateFacade<Rule> facade = new HibernateFacade<Rule>();
		facade.createQuery(hql);
		List<Rule> list = facade.executeQuery();
		return list;
	}

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

	public List<Rule> findAll(RuleParameter param) {
		return null;
	}

	public long countAll(RuleParameter param) {
		return 0;
	}

	public Rule findOnly(RuleParameter param) {
		StringBuffer hql = new StringBuffer();
		hql.append("from com.yeqiangwei.club.dao.model.Rule ");
		if(param.getForumId()!=null){
			hql.append(" where forumId=");
			hql.append(param.getForumId().intValue());
		}
		logger.debug(hql);
		HibernateFacade<Rule> facade = new HibernateFacade<Rule>();
		facade.createQuery(hql);
		facade.setMaxResults(1);
		Rule item = (Rule) facade.uniqueResult();
		return item;
	}


}

⌨️ 快捷键说明

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