dictdao.java
来自「一套自己原先在学校作的CRM,大家指点下」· Java 代码 · 共 219 行
JAVA
219 行
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.Dict;
/**
* Data access object (DAO) for domain model class Dict.
*
* @see .Dict
* @author MyEclipse Persistence Tools
*/
public class DictDAO extends HibernateDaoSupport {
private static final Log log = LogFactory.getLog(DictDAO.class);
// property constants
public static final String NAMES = "names";
public static final String IS_EDITOR = "isEditor";
public static final String VAL = "val";
public static final String TYPES = "types";
protected void initDao() {
// do nothing
}
public void save(Dict transientInstance) {
log.debug("saving Dict instance");
try {
getHibernateTemplate().save(transientInstance);
log.debug("save successful");
} catch (RuntimeException re) {
log.error("save failed", re);
throw re;
}
}
public void delete(Dict persistentInstance) {
log.debug("deleting Dict instance");
try {
getHibernateTemplate().delete(persistentInstance);
log.debug("delete successful");
} catch (RuntimeException re) {
log.error("delete failed", re);
throw re;
}
}
public Dict findById(java.lang.Integer id) {
log.debug("getting Dict instance with id: " + id);
try {
Dict instance = (Dict) getHibernateTemplate().get("com.crm.pojo.Dict", id);
return instance;
} catch (RuntimeException re) {
log.error("get failed", re);
throw re;
}
}
public List findByExample(Dict instance) {
log.debug("finding Dict 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 Dict instance with property: " + propertyName
+ ", value: " + value);
try {
String queryString = "from Dict 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 findByNames(Object names) {
return findByProperty(NAMES, names);
}
public List findByIsEditor(Object isEditor) {
return findByProperty(IS_EDITOR, isEditor);
}
public List findByVal(Object val) {
return findByProperty(VAL, val);
}
public List findByTypes(Object types) {
return findByProperty(TYPES, types);
}
public List findAll() {
log.debug("finding all Dict instances");
try {
String queryString = "from Dict";
return getHibernateTemplate().find(queryString);
} catch (RuntimeException re) {
log.error("find all failed", re);
throw re;
}
}
public Dict merge(Dict detachedInstance) {
log.debug("merging Dict instance");
try {
Dict result = (Dict) getHibernateTemplate().merge(detachedInstance);
log.debug("merge successful");
return result;
} catch (RuntimeException re) {
log.error("merge failed", re);
throw re;
}
}
public void attachDirty(Dict instance) {
log.debug("attaching dirty Dict instance");
try {
getHibernateTemplate().saveOrUpdate(instance);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
public void attachClean(Dict instance) {
log.debug("attaching clean Dict instance");
try {
getHibernateTemplate().lock(instance, LockMode.NONE);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
public List find(Dict dict,int pageNo,int pageSize){
String sql="from Dict d where 1=1 ";
Session s=this.getSessionFactory().openSession();
if(!(dict.getNames()==null || dict.getNames().equals(""))){
sql+=" and d.names like '%"+dict.getNames()+"%'";
}
if(!(dict.getTypes()==null || dict.getTypes().equals(""))){
sql+=" and d.types like '%"+dict.getTypes()+"%'";
}
if(!(dict.getVal()==null || dict.getVal().equals(""))){
sql+=" and d.val like '%"+dict.getVal()+"%'";
}
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;
}
public List findAll(Dict dict){
String sql="from Dict d where 1=1 ";
Session s=this.getSessionFactory().openSession();
if(!(dict.getNames()==null || dict.getNames().equals(""))){
sql+=" and d.names like '%"+dict.getNames()+"%'";
}
if(!(dict.getTypes()==null || dict.getTypes().equals(""))){
sql+=" and d.types like '%"+dict.getTypes()+"%'";
}
if(!(dict.getVal()==null || dict.getVal().equals(""))){
sql+=" and d.val like '%"+dict.getVal()+"%'";
}
sql+=" order by d.id asc";
Query query=s.createQuery(sql);
List list=query.list();
s.close();
return list;
}
public List findByName() {
String sql ="select d.names from Dict as d where d.types='服务类型' ";
Session s = this.getSessionFactory().openSession();
Query query = s.createQuery(sql);
List list = query.list();
s.close();
return list;
}
public List findByType(String name) {
String sql ="select d.names from Dict as d where d.types='"+name+"' ";
Session s = this.getSessionFactory().openSession();
Query query = s.createQuery(sql);
List list = query.list();
s.close();
return list;
}
public static DictDAO getFromApplicationContext(ApplicationContext ctx) {
return (DictDAO) ctx.getBean("DictDAO");
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?