clientstateinfodao.java
来自「一套自己原先在学校作的CRM,大家指点下」· Java 代码 · 共 211 行
JAVA
211 行
package com.crm.dao;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.crm.pojo.ClientStateInfo;
/**
* Data access object (DAO) for domain model class ClientStateInfo.
*
* @see com.crm.pojo.ClientStateInfo
* @author MyEclipse Persistence Tools
*/
public class ClientStateInfoDAO extends HibernateDaoSupport {
private static final Log log = LogFactory.getLog(ClientStateInfoDAO.class);
// property constants
public static final String CSI_TIME = "csiTime";
public static final String CSI_STEP = "csiStep";
public static final String CSI_CAUSE = "csiCause";
protected void initDao() {
// do nothing
}
public void save(ClientStateInfo transientInstance) {
log.debug("saving ClientStateInfo instance");
try {
getHibernateTemplate().save(transientInstance);
log.debug("save successful");
} catch (RuntimeException re) {
log.error("save failed", re);
throw re;
}
}
public void delete(ClientStateInfo persistentInstance) {
log.debug("deleting ClientStateInfo instance");
try {
getHibernateTemplate().delete(persistentInstance);
log.debug("delete successful");
} catch (RuntimeException re) {
log.error("delete failed", re);
throw re;
}
}
public ClientStateInfo findById(java.lang.Integer id) {
log.debug("getting ClientStateInfo instance with id: " + id);
try {
ClientStateInfo instance = (ClientStateInfo) getHibernateTemplate()
.get("com.crm.pojo.ClientStateInfo", id);
return instance;
} catch (RuntimeException re) {
log.error("get failed", re);
throw re;
}
}
public List findByExample(ClientStateInfo instance) {
log.debug("finding ClientStateInfo 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 ClientStateInfo instance with property: "
+ propertyName + ", value: " + value);
try {
String queryString = "from ClientStateInfo 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 findByCsiTime(Object csiTime) {
return findByProperty(CSI_TIME, csiTime);
}
public List findByCsiStep(Object csiStep) {
return findByProperty(CSI_STEP, csiStep);
}
public List findByCsiCause(Object csiCause) {
return findByProperty(CSI_CAUSE, csiCause);
}
public List findAll() {
log.debug("finding all ClientStateInfo instances");
try {
String queryString = "from ClientStateInfo";
return getHibernateTemplate().find(queryString);
} catch (RuntimeException re) {
log.error("find all failed", re);
throw re;
}
}
public ClientStateInfo merge(ClientStateInfo detachedInstance) {
log.debug("merging ClientStateInfo instance");
try {
ClientStateInfo result = (ClientStateInfo) getHibernateTemplate()
.merge(detachedInstance);
log.debug("merge successful");
return result;
} catch (RuntimeException re) {
log.error("merge failed", re);
throw re;
}
}
public void attachDirty(ClientStateInfo instance) {
log.debug("attaching dirty ClientStateInfo instance");
try {
getHibernateTemplate().saveOrUpdate(instance);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
public void attachClean(ClientStateInfo instance) {
log.debug("attaching clean ClientStateInfo instance");
try {
getHibernateTemplate().lock(instance, LockMode.NONE);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
public List find(ClientStateInfo sci, int pageNo, int pageSize) {
String sql = "from ClientStateInfo d where 1=1 ";
Session s = this.getSessionFactory().openSession();
if (!(sci.getClient().getClientEmployeeName() == null || sci
.getClient().getClientEmployeeName().equals(""))) {
sql += " and d.client.clientEmployeeName like '%"
+ sci.getClient().getClientEmployeeName() + "%'";
}
if (!(sci.getClient().getClientName() == null || sci.getClient()
.getClientName().equals(""))) {
sql += " and d.client.clientName like '%"
+ sci.getClient().getClientName() + "%'";
}
if (!(sci.getClient().getClientState().getClientStateId() == null || sci
.getClient().getClientState().getClientStateId().equals("") ||
sci.getClient().getClientState().getClientStateId()==0 )) {
sql += " and d.client.clientState.clientStateId ="+sci.getClient().getClientState().getClientStateId();
}
sql += " order by d.csiId asc";
Query query = s.createQuery(sql);
int fri = pageSize * (pageNo - 1);
query.setFirstResult(fri);
query.setMaxResults(pageSize);
List list = query.list();
s.close();
return list;
}
public List findAll(ClientStateInfo sci) {
String sql = "from ClientStateInfo d where 1=1 ";
Session s = this.getSessionFactory().openSession();
if (!(sci.getClient().getClientEmployeeName() == null || sci
.getClient().getClientEmployeeName().equals(""))) {
sql += " and d.client.clientEmployeeName like '%"
+ sci.getClient().getClientEmployeeName() + "%'";
}
if (!(sci.getClient().getClientName() == null || sci.getClient()
.getClientName().equals(""))) {
sql += " and d.client.clientName like '%"
+ sci.getClient().getClientName() + "%'";
}
if (!(sci.getClient().getClientState().getClientStateId() == null || sci
.getClient().getClientState().getClientStateId().equals("") ||
sci.getClient().getClientState().getClientStateId()==0 )) {
sql += " and d.client.clientState.clientStateId ="+sci.getClient().getClientState().getClientStateId();
}
sql += " order by d.csiId asc";
Query query = s.createQuery(sql);
List list = query.list();
s.close();
return list;
}
public static ClientStateInfoDAO getFromApplicationContext(
ApplicationContext ctx) {
return (ClientStateInfoDAO) ctx.getBean("ClientStateInfoDAO");
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?