depotinfodao.java
来自「一套自己原先在学校作的CRM,大家指点下」· Java 代码 · 共 181 行
JAVA
181 行
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.DepotInfo;
/**
* Data access object (DAO) for domain model class DepotInfo.
*
* @see com.crm.pojo.DepotInfo
* @author MyEclipse Persistence Tools
*/
public class DepotInfoDAO extends HibernateDaoSupport {
private static final Log log = LogFactory.getLog(DepotInfoDAO.class);
// property constants
public static final String DEPOT_ADDRESS = "depotAddress";
public static final String DEPOT_BOOTH = "depotBooth";
public static final String DEPOT_PIECE = "depotPiece";
public static final String DEPOT_REMARK = "depotRemark";
protected void initDao() {
// do nothing
}
public void save(DepotInfo transientInstance) {
log.debug("saving DepotInfo instance");
try {
getHibernateTemplate().save(transientInstance);
log.debug("save successful");
} catch (RuntimeException re) {
log.error("save failed", re);
throw re;
}
}
public void delete(DepotInfo persistentInstance) {
log.debug("deleting DepotInfo instance");
try {
getHibernateTemplate().delete(persistentInstance);
log.debug("delete successful");
} catch (RuntimeException re) {
log.error("delete failed", re);
throw re;
}
}
public DepotInfo findById(java.lang.Integer id) {
log.debug("getting DepotInfo instance with id: " + id);
try {
DepotInfo instance = (DepotInfo) getHibernateTemplate().get(
"com.crm.pojo.DepotInfo", id);
return instance;
} catch (RuntimeException re) {
log.error("get failed", re);
throw re;
}
}
public List findByExample(DepotInfo instance) {
log.debug("finding DepotInfo 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 DepotInfo instance with property: " + propertyName
+ ", value: " + value);
try {
String queryString = "from DepotInfo 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 findByDepotAddress(Object depotAddress) {
return findByProperty(DEPOT_ADDRESS, depotAddress);
}
public List findByDepotBooth(Object depotBooth) {
return findByProperty(DEPOT_BOOTH, depotBooth);
}
public List findByDepotPiece(Object depotPiece) {
return findByProperty(DEPOT_PIECE, depotPiece);
}
public List findByDepotRemark(Object depotRemark) {
return findByProperty(DEPOT_REMARK, depotRemark);
}
public List findAll() {
log.debug("finding all DepotInfo instances");
try {
String queryString = "from DepotInfo";
return getHibernateTemplate().find(queryString);
} catch (RuntimeException re) {
log.error("find all failed", re);
throw re;
}
}
public DepotInfo merge(DepotInfo detachedInstance) {
log.debug("merging DepotInfo instance");
try {
DepotInfo result = (DepotInfo) getHibernateTemplate().merge(
detachedInstance);
log.debug("merge successful");
return result;
} catch (RuntimeException re) {
log.error("merge failed", re);
throw re;
}
}
public void attachDirty(DepotInfo instance) {
log.debug("attaching dirty DepotInfo instance");
try {
getHibernateTemplate().saveOrUpdate(instance);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
public void attachClean(DepotInfo instance) {
log.debug("attaching clean DepotInfo instance");
try {
getHibernateTemplate().lock(instance, LockMode.NONE);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
public static DepotInfoDAO getFromApplicationContext(ApplicationContext ctx) {
return (DepotInfoDAO) ctx.getBean("DepotInfoDAO");
}
public List find(DepotInfo d,int pageNo,int pageSize){
String sql="from DepotInfo d where 1=1 ";
Session s=this.getSessionFactory().openSession();
if(!(d.getDepotAddress()==null || d.getDepotAddress().equals(""))){
sql+=" and d.depotAddress like '%"+d.getDepotAddress()+"%'";
}
if(!(d.getProductInfo().getProductName()==null || d.getProductInfo().getProductName().equals(""))){
sql+=" and d.productInfo.productName like '%"+d.getProductInfo().getProductName()+"%'";
}
sql+=" order by d.id 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;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?