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

📄 basdictdao.java

📁 SSH框架 开发的客户管理系统 北大青鸟培训实课题 适合新学者学习
💻 JAVA
字号:
package com.accp.dao.jb_crm_team0.Imp;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.Criteria;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.hibernate.criterion.Expression;
import org.hibernate.criterion.Projection;
import org.hibernate.criterion.Projections;
import org.hibernate.impl.CriteriaImpl;

import com.accp.dao.jb_crm_team0.Inf.IBasDictDAO;
import com.accp.dao.jb_sale.Inf.IProductDAO;
import com.accp.entity.jb_crm_team0.BasDict;
import com.accp.entity.jb_crm_team0.CstCustomer;
import com.accp.util.PageResult;
import com.accp.struts.form.BasDictForm;
import com.accp.struts.form.CustomerForm;
import com.sun.org.apache.commons.collections.Predicate;

import freemarker.template.utility.StringUtil;

public class BasDictDAO extends HibernateDaoSupport implements IBasDictDAO {
	private static final Log log = LogFactory.getLog(BasDictDAO.class);

	protected void initDao() {
		// do nothing
	}

	public void save(BasDict transientInstance) {
		log.debug("saving BasDict instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public PageResult findAll(Map paramMap) {
		PageResult pgr = new PageResult();
		String start = (String) paramMap.get("start");
		String limit = (String) paramMap.get("limit");
		
		
		String dicttype=(String)paramMap.get("dict_type");
		String dictitem=(String)paramMap.get("dict_item");
		String dictvalue=(String)paramMap.get("dict_value");
		try {
		Criteria c=getSession().createCriteria(BasDict.class);
		if(StringUtils.isNotEmpty(dicttype))
		{
			c.add(Expression.like("dictType", "%"+dicttype+"%"));
		}
		if(StringUtils.isNotEmpty(dictitem)){
			c.add(Expression.like("dictItem", "%"+dictitem+"%"));
		}
		if(StringUtils.isNotEmpty(dictvalue))
		{
			c.add(Expression.like("dictValue", "%"+dictvalue+"%"));
		}
		
		// 总条数
		Projection entityProjection = ((CriteriaImpl)c).getProjection();
		c.setProjection(Projections.rowCount()).uniqueResult();
		int rowCount  = ((Number)c.uniqueResult()).intValue();
		pgr.setRowCount(rowCount);
		c.setProjection(entityProjection);
		// 分页
		if (start != null) {
			c.setFirstResult(Integer.parseInt(start));
		}
		if (limit != null) {
			c.setMaxResults(Integer.parseInt(limit));
		}
		List<BasDict> list=c.list();
		List<BasDictForm> fList=new ArrayList<BasDictForm>();
		BasDictForm dictForm=null;
		for(BasDict basdict:list){
			dictForm=new BasDictForm();
			dictForm.setDictId(basdict.getDictId());
			dictForm.setDictType(basdict.getDictType());
			dictForm.setDictItem(basdict.getDictItem());
			dictForm.setDictValue(basdict.getDictValue());
			dictForm.setDictIsEditable(basdict.getDictIsEditable());
			fList.add(dictForm);
			}
		pgr.setData(fList);

		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
		return pgr;
		
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.accp.dao.jb_crm_team0.IBasDictDAO#delete(com.accp.entity.jb_crm_team0.BasDict)
	 */
	public void delete(BasDict persistentInstance) {
		log.debug("deleting BasDict instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.accp.dao.jb_crm_team0.IBasDictDAO#findById(java.lang.Long)
	 */
	public BasDict findById(java.lang.Long id) {
		log.debug("getting BasDict instance with id: " + id);
		try {
			BasDict instance = (BasDict) getHibernateTemplate().get(
					"com.accp.entity.jb_crm_team0.BasDict", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.accp.dao.jb_crm_team0.IBasDictDAO#findByExample(com.accp.entity.jb_crm_team0.BasDict)
	 */
	public List findByExample(BasDict instance) {
		log.debug("finding BasDict instance by example");
		try {
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.accp.dao.jb_crm_team0.IBasDictDAO#findByProperty(java.lang.String,
	 *      java.lang.Object)
	 */
	public List findByProperty(String propertyName, Object value) {
		log.debug("finding BasDict instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from BasDict as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.accp.dao.jb_crm_team0.IBasDictDAO#findByDictType(java.lang.Object)
	 */
	public List findByDictType(Object dictType) {
		return findByProperty(DICT_TYPE, dictType);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.accp.dao.jb_crm_team0.IBasDictDAO#findByDictItem(java.lang.Object)
	 */
	public List findByDictItem(Object dictItem) {
		return findByProperty(DICT_ITEM, dictItem);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.accp.dao.jb_crm_team0.IBasDictDAO#findByDictValue(java.lang.Object)
	 */
	public List findByDictValue(Object dictValue) {
		return findByProperty(DICT_VALUE, dictValue);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.accp.dao.jb_crm_team0.IBasDictDAO#findByDictIsEditable(java.lang.Object)
	 */
	public List findByDictIsEditable(Object dictIsEditable) {
		return findByProperty(DICT_IS_EDITABLE, dictIsEditable);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.accp.dao.jb_crm_team0.IBasDictDAO#findAll()
	 */
	public List findAll() {
		log.debug("finding all BasDict instances");
		try {
			String queryString = "from BasDict";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.accp.dao.jb_crm_team0.IBasDictDAO#merge(com.accp.entity.jb_crm_team0.BasDict)
	 */
	public BasDict merge(BasDict detachedInstance) {
		log.debug("merging BasDict instance");
		try {
			BasDict result = (BasDict) getHibernateTemplate().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.accp.dao.jb_crm_team0.IBasDictDAO#attachDirty(com.accp.entity.jb_crm_team0.BasDict)
	 */
	public void attachDirty(BasDict instance) {
		log.debug("attaching dirty BasDict instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.accp.dao.jb_crm_team0.IBasDictDAO#attachClean(com.accp.entity.jb_crm_team0.BasDict)
	 */
	public void attachClean(BasDict instance) {
		log.debug("attaching clean BasDict instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static IBasDictDAO getFromApplicationContext(ApplicationContext ctx) {
		return (IBasDictDAO) ctx.getBean("BasDictDAO");
	}

}

⌨️ 快捷键说明

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