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

📄 customerdao.java

📁 关于ssh的整合,希望对大家有帮助
💻 JAVA
字号:
package crm.dao.cst;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.Criteria;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import crm.entity.cst.CustomerEntity;

/**
 * Data access object (DAO) for domain model class CustomerEntity.
 * 
 * @see crm.entity.cst.CustomerEntity
 * @author MyEclipse Persistence Tools
 */

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

	// property constants
	public static final String CUST_NAME = "custName";

	public static final String CUST_REGION = "custRegion";

	public static final String CUST_MANAGER_ID = "custManagerId";

	public static final String CUST_MANAGER_NAME = "custManagerName";

	public static final String CUST_LEVEL = "custLevel";

	public static final String CUST_LEVEL_LABEL = "custLevelLabel";

	public static final String CUST_SATISFY = "custSatisfy";

	public static final String CUST_CREDIT = "custCredit";

	public static final String CUST_ADDR = "custAddr";

	public static final String CUST_ZIP = "custZip";

	public static final String CUST_TEL = "custTel";

	public static final String CUST_FAX = "custFax";

	public static final String CUST_WEBSITE = "custWebsite";

	public static final String CUST_LICENCE_NO = "custLicenceNo";

	public static final String CUST_CHIEFTAIN = "custChieftain";

	public static final String CUST_BANKROLL = "custBankroll";

	public static final String CUST_TURNOVER = "custTurnover";

	public static final String CUST_BANK = "custBank";

	public static final String CUST_BANK_ACCOUNT = "custBankAccount";

	public static final String CUST_LOCAL_TAX_NO = "custLocalTaxNo";

	public static final String CUST_NATIONAL_TAX_NO = "custNationalTaxNo";

	public static final String CUST_STATUS = "custStatus";

	protected void initDao() {
		// do nothing
	}

	/**
	 * 多条件查询 Criteria 查询
	 */
	public List search(CustomerEntity ce)
	{
		 
		// 得到session对象 从HibernateDaoSupport类中得到
		Session session=this.getSession();
		//创建Criteria对象c
		Criteria  c=session.createCriteria(CustomerEntity.class);
		
		//构造的查询条件是&& and 与的关系
		//判断客户编号是否为空。如果不为空。则执行下面的if语句
		if(null!=ce.getCustNo()&&!"".equals(ce.getCustNo()))
		{
			System.out.println("客户编号:"+ce.getCustNo());
			c.add(Restrictions.like("custNo", ce.getCustNo(),MatchMode.ANYWHERE));
		}
		
		//判断客户名称是否为空。如果不为空。则执行下面的if语句 
		if(null!=ce.getCustName()&&!"".equals(ce.getCustName()))
		{
			System.out.println("客户名称:"+ce.getCustName());
			c.add(Restrictions.like("custName", ce.getCustName(),MatchMode.ANYWHERE));
		}
//		
//		if(null!=ce.getCustRegion()&&!ce.getCustRegion().equals(""))
//		{
//			c.add(Restrictions.like("custRegion", ce.getCustRegion(),MatchMode.ANYWHERE));
//		}
//		
		//判断客户经理姓名是否为空。如果不为空,则执行下面的if语句
		if(null!=ce.getCustManagerName()&&!"".equals(ce.getCustManagerName()))
		{
			System.out.println("客户经理:"+ce.getCustManagerName());
			c.add(Restrictions.like("custManagerName", ce.getCustManagerName(),MatchMode.ANYWHERE));
		}
//		
//		if(null!=ce.getCustLevelLabel()&&!ce.getCustLevelLabel().equals(""))
//		{
//			c.add(Restrictions.like("custLevelLabel", ce.getCustLevelLabel(),MatchMode.ANYWHERE));
//		}
		
		c.addOrder(Order.asc("custNo"));        //按照客户的编号升序
		return c.list();

	}
	
	/**
	 * 聚合函数查询。返回表里的记录数
	 * @return
	 */
	public int getJu()
	{
		Session session=this.getSession();
		String hql="select count(cust) from CustomerEntity as cust";
		Query query=session.createQuery(hql);
		int count=(Integer)query.uniqueResult();
		System.out.println("count:"+count);
		return count; 
	}
	
	
	public void save(CustomerEntity transientInstance) {
		log.debug("saving CustomerEntity instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(CustomerEntity persistentInstance) {
		log.debug("deleting CustomerEntity instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	/**
	 * 删除方法(根据id删除)
	 */
	public void delete(String id)
	{
		this.delete(this.findById(id));
	}
	
	public CustomerEntity findById(java.lang.String id) {
		log.debug("getting CustomerEntity instance with id: " + id);
		try {
			CustomerEntity instance = (CustomerEntity) getHibernateTemplate()
					.get("crm.entity.cst.CustomerEntity", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}
	
	/**
	 * 查询客户信息 (只查询实体类里的几个属性)    客户信息管理
	 */
	public List doCustomerMessageQuery()
	{
		try {
			String queryString="select cst.custNo,cst.custName,cst.custRegion,cst.custManagerName,cst.custLevelLabel from CustomerEntity as cst";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			throw re;
		}
	}

	public List findByExample(CustomerEntity instance) {
		log.debug("finding CustomerEntity 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;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding CustomerEntity instance with property: "
				+ propertyName + ", value: " + value);
		try {
			String queryString = "from CustomerEntity as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByCustName(Object custName) {
		return findByProperty(CUST_NAME, custName);
	}

	public List findByCustRegion(Object custRegion) {
		return findByProperty(CUST_REGION, custRegion);
	}

	public List findByCustManagerId(Object custManagerId) {
		return findByProperty(CUST_MANAGER_ID, custManagerId);
	}

	public List findByCustManagerName(Object custManagerName) {
		return findByProperty(CUST_MANAGER_NAME, custManagerName);
	}

	public List findByCustLevel(Object custLevel) {
		return findByProperty(CUST_LEVEL, custLevel);
	}

	public List findByCustLevelLabel(Object custLevelLabel) {
		return findByProperty(CUST_LEVEL_LABEL, custLevelLabel);
	}

	public List findByCustSatisfy(Object custSatisfy) {
		return findByProperty(CUST_SATISFY, custSatisfy);
	}

	public List findByCustCredit(Object custCredit) {
		return findByProperty(CUST_CREDIT, custCredit);
	}

	public List findByCustAddr(Object custAddr) {
		return findByProperty(CUST_ADDR, custAddr);
	}

	public List findByCustZip(Object custZip) {
		return findByProperty(CUST_ZIP, custZip);
	}

	public List findByCustTel(Object custTel) {
		return findByProperty(CUST_TEL, custTel);
	}

	public List findByCustFax(Object custFax) {
		return findByProperty(CUST_FAX, custFax);
	}

	public List findByCustWebsite(Object custWebsite) {
		return findByProperty(CUST_WEBSITE, custWebsite);
	}

	public List findByCustLicenceNo(Object custLicenceNo) {
		return findByProperty(CUST_LICENCE_NO, custLicenceNo);
	}

	public List findByCustChieftain(Object custChieftain) {
		return findByProperty(CUST_CHIEFTAIN, custChieftain);
	}

	public List findByCustBankroll(Object custBankroll) {
		return findByProperty(CUST_BANKROLL, custBankroll);
	}

	public List findByCustTurnover(Object custTurnover) {
		return findByProperty(CUST_TURNOVER, custTurnover);
	}

	public List findByCustBank(Object custBank) {
		return findByProperty(CUST_BANK, custBank);
	}

	public List findByCustBankAccount(Object custBankAccount) {
		return findByProperty(CUST_BANK_ACCOUNT, custBankAccount);
	}

	public List findByCustLocalTaxNo(Object custLocalTaxNo) {
		return findByProperty(CUST_LOCAL_TAX_NO, custLocalTaxNo);
	}

	public List findByCustNationalTaxNo(Object custNationalTaxNo) {
		return findByProperty(CUST_NATIONAL_TAX_NO, custNationalTaxNo);
	}

	public List findByCustStatus(Object custStatus) {
		return findByProperty(CUST_STATUS, custStatus);
	}

	public List findAll() {
		log.debug("finding all CustomerEntity instances");
		try {
			String queryString = "from CustomerEntity";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public CustomerEntity merge(CustomerEntity detachedInstance) {
		log.debug("merging CustomerEntity instance");
		try {
			CustomerEntity result = (CustomerEntity) getHibernateTemplate()
					.merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(CustomerEntity instance) {
		log.debug("attaching dirty CustomerEntity instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(CustomerEntity instance) {
		log.debug("attaching clean CustomerEntity instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static CustomerDAO getFromApplicationContext(
			ApplicationContext ctx) {
		return (CustomerDAO) ctx.getBean("CustomerEntityDAO");
	}
}

⌨️ 快捷键说明

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