📄 lostdao.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.Session;
import org.hibernate.SessionFactory;
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.LostEntity;
/**
* Data access object (DAO) for domain model class LostEntity.
*
* @see crm.entity.cst.LostEntity
* @author MyEclipse Persistence Tools
*/
public class LostDAO extends HibernateDaoSupport {
private static final Log log = LogFactory.getLog(LostDAO.class);
// property constants
public static final String LST_CUST_NAME = "lstCustName";
public static final String LST_CUST_MANAGER_ID = "lstCustManagerId";
public static final String LST_CUST_MANAGER_NAME = "lstCustManagerName";
public static final String LST_DELAY = "lstDelay";
public static final String LST_REASON = "lstReason";
public static final String LST_STATUS = "lstStatus";
protected void initDao() {
// do nothing
}
/**
* 查询客户和客户经理 .状态
*/
public List doQuery(LostEntity le)
{
//得到session对象
Session session=this.getSession();
//创建Criteria对象c.传输的参数的对应的实体类
Criteria c=session.createCriteria(LostEntity.class);
if(null!=le)
{ //判断客户名称是否为空。如果不为空。则执行下面的if语句
if(le.getLstCustName()!=null&&!le.getLstCustName().equals(""))
{
c.add(Restrictions.like("lstCustName", le.getLstCustName()));
}
//判断客户经理姓名是否为空。如果不为空,则执行下面的if语句
if(le.getLstCustManagerName()!=null&&!le.getLstCustManagerName().equals(""))
{
c.add(Restrictions.like("lstCustManagerName", le.getLstCustManagerName()));
}
}
c.addOrder(Order.asc("lstId"));
return c.list();
}
public void save(LostEntity transientInstance) {
log.debug("saving LostEntity instance");
try {
getHibernateTemplate().save(transientInstance);
log.debug("save successful");
} catch (RuntimeException re) {
log.error("save failed", re);
throw re;
}
}
public void delete(LostEntity persistentInstance) {
log.debug("deleting LostEntity instance");
try {
getHibernateTemplate().delete(persistentInstance);
log.debug("delete successful");
} catch (RuntimeException re) {
log.error("delete failed", re);
throw re;
}
}
/**
* 删除方法(根据id删除)
*/
public void delete(int id)
{
long lid=id; //将int型转换成long型
this.delete(this.findById(lid));
}
public LostEntity findById(java.lang.Long id) {
log.debug("getting LostEntity instance with id: " + id);
try {
LostEntity instance = (LostEntity) getHibernateTemplate().get(
"crm.entity.cst.LostEntity", id);
return instance;
} catch (RuntimeException re) {
log.error("get failed", re);
throw re;
}
}
public List findByExample(LostEntity instance) {
log.debug("finding LostEntity 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 LostEntity instance with property: " + propertyName
+ ", value: " + value);
try {
String queryString = "from LostEntity 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 findByLstCustName(Object lstCustName) {
return findByProperty(LST_CUST_NAME, lstCustName);
}
public List findByLstCustManagerId(Object lstCustManagerId) {
return findByProperty(LST_CUST_MANAGER_ID, lstCustManagerId);
}
public List findByLstCustManagerName(Object lstCustManagerName) {
return findByProperty(LST_CUST_MANAGER_NAME, lstCustManagerName);
}
public List findByLstDelay(Object lstDelay) {
return findByProperty(LST_DELAY, lstDelay);
}
public List findByLstReason(Object lstReason) {
return findByProperty(LST_REASON, lstReason);
}
public List findByLstStatus(Object lstStatus) {
return findByProperty(LST_STATUS, lstStatus);
}
public List findAll() {
log.debug("finding all LostEntity instances");
try {
String queryString = "from LostEntity";
return getHibernateTemplate().find(queryString);
} catch (RuntimeException re) {
log.error("find all failed", re);
throw re;
}
}
public LostEntity merge(LostEntity detachedInstance) {
log.debug("merging LostEntity instance");
try {
LostEntity result = (LostEntity) getHibernateTemplate().merge(
detachedInstance);
log.debug("merge successful");
return result;
} catch (RuntimeException re) {
log.error("merge failed", re);
throw re;
}
}
public void attachDirty(LostEntity instance) {
log.debug("attaching dirty LostEntity instance");
try {
getHibernateTemplate().saveOrUpdate(instance);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
public void attachClean(LostEntity instance) {
log.debug("attaching clean LostEntity instance");
try {
getHibernateTemplate().lock(instance, LockMode.NONE);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
public static LostDAO getFromApplicationContext(ApplicationContext ctx) {
return (LostDAO) ctx.getBean("LostEntityDAO");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -