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

📄 contentimpl.java

📁 野蔷薇论坛源码 java 自己看看吧。 学习用
💻 JAVA
字号:
/*
 * Created on 2005-10-22
 * 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.model.Content;
import com.yeqiangwei.club.param.TopicParameter;
import com.yeqiangwei.club.dao.ContentDAO;
import com.yeqiangwei.club.dao.hibernate.support.HibernateFacade;
import com.yeqiangwei.club.dao.hibernate.support.HibernateProvider;
import com.yeqiangwei.club.exception.DAOException;

public class ContentImpl implements ContentDAO {
   
	private static final String FIND_CONTENTID = "from Content where contentId=?";
	
	private static final String FIND_TOPICID = "from Content where topicId=?";
	
	private static final String DELETE_TOPICID = "delete from Content where topicId=?";
	
	private static final String DELETES_TOPICID = "delete from Content where topicId in (:ids)";
	
	private static final String DELETE_CONTENTID = "delete from Content where contentId=?";
	
	private static final String DELETES_CONTENTID = "delete from Content where contentId in (:ids)";
	
    public void create(Content item) throws DAOException {
		HibernateProvider<Content> facade = new HibernateFacade<Content>();
		try{
			facade.save(item);
		}catch(HibernateException e){
			throw new DAOException(e);
		}
	}

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

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


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


	public int deleteByTopicId(int topicId) throws DAOException {
        HibernateProvider<Content> facade = new HibernateFacade<Content>();
        facade.createQuery(DELETE_TOPICID);
        facade.setInt(0, topicId);
		try{
			return facade.executeUpdate();
		}catch(HibernateException e){
			throw new DAOException(e);
		}
	}
	
	public int deleteByTopicId(List<Integer> ids) throws DAOException {
        HibernateProvider<Content> facade = new HibernateFacade<Content>();
        facade.createQuery(DELETES_TOPICID);
        facade.setParameterList("ids",ids);
		try{
			return facade.executeUpdate();
		}catch(HibernateException e){
			throw new DAOException(e);
		}
	}

	public Content findById(int id) {
		HibernateProvider<Content> facade = new HibernateFacade<Content>();
        facade.createQuery(FIND_CONTENTID);
        facade.setInt(0,id);
        facade.setMaxResults(1);
		return facade.uniqueResult();
	}
	
	public Content findByTopicId(int topicId) {
		HibernateProvider<Content> facade = new HibernateFacade<Content>();
        facade.createQuery(FIND_TOPICID);
        facade.setInt(0,topicId);
        facade.setMaxResults(1);
		return facade.uniqueResult();
	}

	public List<Content> findByParameter(TopicParameter param) {
		StringBuffer hql = new StringBuffer();
		hql.append("from Content where ");
		if(param.getMinId()==null){
			hql.append(" topicId>0 ");
		}else{
			hql.append(" topicId>");
			hql.append(param.getMinId().intValue());
		}
		if(param.getIsDeleted()!=null){
			hql.append(" and isDeleted=?");
		}
		else if(param.getOrderBy().byteValue()==4){
			hql.append(" order by topicId");
		}
		//System.out.println(hql);
		HibernateProvider<Content> facade = new HibernateFacade<Content>();
		facade.createQuery(hql);
		if(param.getIsDeleted()!=null){
			facade.setBoolean(0, param.getIsDeleted());
		}
		facade.setFirstResult(param.getPagination().getStartRow());
		facade.setMaxResults(param.getPagination().getEndRow());
		return facade.executeQuery();
	}

	public long countByParameter(TopicParameter param) {
		StringBuffer hql = new StringBuffer();
		hql.append("select(contentId) from Content where ");
		if(param.getMinId()==null){
			hql.append(" topicId>0 ");
		}else{
			hql.append(" topicId>");
			hql.append(param.getMinId().intValue());
		}
		if(param.getIsDeleted()!=null){
			hql.append(" and isDeleted=?");
		}
		HibernateProvider<Content> facade = new HibernateFacade<Content>();
		facade.createQuery(hql);
		if(param.getIsDeleted()!=null){
			facade.setBoolean(0, param.getIsDeleted());
		}
		facade.setCacheable(true);
		//long c = facade.resultTotal();
		return facade.resultTotalInteger();
	}

	public List<Content> findAll(TopicParameter param) {
		return null;
	}

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

⌨️ 快捷键说明

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