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

📄 friendlabelimpl.java

📁 野蔷薇论坛源码 java 自己看看吧。 学习用
💻 JAVA
字号:
/* 
 * Created on 2007-4-26
 * Last modified on 2007-9-8
 * 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.FriendLabelDAO;
import com.yeqiangwei.club.dao.hibernate.ConnectionProvider;
import com.yeqiangwei.club.dao.hibernate.support.HibernateFacade;
import com.yeqiangwei.club.dao.hibernate.support.HibernateProvider;
import com.yeqiangwei.club.dao.hibernate.support.HibernateUserFacade;
import com.yeqiangwei.club.dao.model.FriendLabel;
import com.yeqiangwei.club.exception.DAOException;
import com.yeqiangwei.club.param.FriendParameter;

public class FriendLabelImpl implements FriendLabelDAO{
	
	private static final Logger logger = Logger.getLogger(FriendLabelImpl.class);
	
	private static final String DELETE_LABELID = "delete from FriendLabel where labelId=?";
	
	private static final String DELETE_LABELIDS = "delete from FriendLabel where labelId in (:ids)";
	
	private static final String FIND_labelId = "from FriendLabel where labelId=?";
		
	private HibernateProvider<FriendLabel> getHibernateProvider(){
		if(ConnectionProvider.whichConnection==0){
			logger.info("HibernateFacade...");
			return new HibernateFacade<FriendLabel>();
		}else{
			logger.info("HibernateUserFacade...");
			return new HibernateUserFacade<FriendLabel>();
		}
	}
	
	public void create(FriendLabel item) throws DAOException {
		HibernateProvider<FriendLabel> hibernateProvider = this.getHibernateProvider();
		try{
			hibernateProvider.save(item);
		}catch(HibernateException e){
			throw new DAOException(e);
		}
	}

	public void update(FriendLabel item) throws DAOException {
		HibernateProvider<FriendLabel> hibernateProvider = this.getHibernateProvider();
		try{
			hibernateProvider.update(item);
		}catch(HibernateException e){
			throw new DAOException(e);
		}
	}

	public int delete(FriendLabel item) throws DAOException {
		HibernateProvider<FriendLabel> hibernateProvider = this.getHibernateProvider();
		hibernateProvider.createQuery(DELETE_LABELID);
		hibernateProvider.setInt(0,item.getLabelId());
		try{
			return hibernateProvider.executeUpdate();
		}catch(HibernateException e){
			throw new DAOException(e);
		}
	}

	public int delete(List<Integer> ids) throws DAOException {
		HibernateProvider<FriendLabel> hibernateProvider = this.getHibernateProvider();
		hibernateProvider.createQuery(DELETE_LABELIDS);
		hibernateProvider.setParameterList("ids", ids);
		try{
			return hibernateProvider.executeUpdate();
		}catch(HibernateException e){
			throw new DAOException(e);
		}
	}

	public FriendLabel findById(int id) {
		HibernateProvider<FriendLabel> hibernateProvider = this.getHibernateProvider();
		hibernateProvider.createQuery(FIND_labelId);
		hibernateProvider.setInt(0,id);
	    hibernateProvider.setCacheable(true); 
	    hibernateProvider.setMaxResults(1);
	    return hibernateProvider.uniqueResult();
	}

	public List<FriendLabel> findByParameter(FriendParameter param) {
		StringBuffer hql = new StringBuffer();
		hql.append("from FriendLabel where labelId>0");
		if(param.getMyUserId()!=null){
			hql.append(" and myUserId=");
			hql.append(param.getMyUserId());
		}
		HibernateProvider<FriendLabel> hibernateProvider = this.getHibernateProvider();
		hibernateProvider.createQuery(hql);
		List<FriendLabel> list = hibernateProvider.executeQuery();
		return list;
	}

	public long countByParameter(FriendParameter param) {
		StringBuffer hql = new StringBuffer();
		hql.append("select count(labelId) from FriendLabel where labelId>0");
		if(param.getMyUserId()!=null){
			hql.append(" and myUserId=");
			hql.append(param.getMyUserId());
		}
		HibernateProvider<FriendLabel> hibernateProvider = this.getHibernateProvider();
		hibernateProvider.createQuery(hql);
		hibernateProvider.setCacheable(true);
		return hibernateProvider.resultTotal();
	}

	public List<FriendLabel> findAll(FriendParameter param) {
		return null;
	}

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

}

⌨️ 快捷键说明

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