📄 rfcdao.java
字号:
package org.mychange.obj;
import java.util.List;
import java.util.Set;
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.criterion.DetachedCriteria;
import org.hibernate.criterion.Expression;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Restrictions;
import org.mychange.dao.IRfcDAO;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.SessionFactoryUtils;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
/**
* Data access object (DAO) for domain model class Rfc.
*
* @see org.mychange.obj.Rfc
* @author MyEclipse Persistence Tools
*/
public class RfcDAO extends HibernateDaoSupport implements IRfcDAO {
private static final Log log = LogFactory.getLog(RfcDAO.class);
// property constants
public static final String RFCNAME = "rfcname";
public static final String DESCRIPTION = "description";
public static final String STATE = "state";
public static final String TYPES = "types";
public static final String PRIORITY = "priority";
public static final String SUBMIT_DATE = "submitDate";
public static final String EXPECT_DATE = "expectDate";
public static final String COST = "cost";
public static final String MANPOWER = "manpower";
public static final String RISK_LEVEL = "riskLevel";
public static final String INSTANCY_LEVEL = "instancyLevel";
public static final String EFFECT_LEVEL = "effectLevel";
public static final String SKILL_LEVEL = "skillLevel";
public static final String LATENCY_TIME = "latencyTime";
public static final String ATTACHMENT = "attachment";
public static final String ENVENT_ID = "enventId";
protected void initDao() {
// do nothing
}
public void save(Rfc transientInstance) {
log.debug("saving Rfc instance");
try {
getHibernateTemplate().save(transientInstance);
log.debug("save successful");
} catch (RuntimeException re) {
log.error("save failed", re);
throw re;
}
}
public void update(Rfc rfc){
getHibernateTemplate().update(rfc);
}
public void delete(Rfc persistentInstance) {
log.debug("deleting Rfc instance");
try {
getHibernateTemplate().delete(persistentInstance);
log.debug("delete successful");
} catch (RuntimeException re) {
log.error("delete failed", re);
throw re;
}
}
public Rfc findById(java.lang.Integer id) {
log.debug("getting Rfc instance with id: " + id);
try {
Rfc instance = (Rfc) getHibernateTemplate().get(
"org.mychange.obj.Rfc", id);
return instance;
} catch (RuntimeException re) {
log.error("get failed", re);
throw re;
}
}
public List findByExample(Rfc instance) {
log.debug("finding Rfc 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 Rfc instance with property: " + propertyName
+ ", value: " + value);
try {
String queryString = "from Rfc 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 findByRfcname(Object rfcname) {
return findByProperty(RFCNAME, rfcname);
}
public List findByDescription(Object description) {
return findByProperty(DESCRIPTION, description);
}
public List findByState(Object state) {
return findByProperty(STATE, state);
}
public List findByTypes(Object types) {
return findByProperty(TYPES, types);
}
public List findByPriority(Object priority) {
return findByProperty(PRIORITY, priority);
}
public List findBySubmitDate(Object submitDate) {
return findByProperty(SUBMIT_DATE, submitDate);
}
public List findByExpectDate(Object expectDate) {
return findByProperty(EXPECT_DATE, expectDate);
}
public List findByCost(Object cost) {
return findByProperty(COST, cost);
}
public List findByManpower(Object manpower) {
return findByProperty(MANPOWER, manpower);
}
public List findByRiskLevel(Object riskLevel) {
return findByProperty(RISK_LEVEL, riskLevel);
}
public List findByInstancyLevel(Object instancyLevel) {
return findByProperty(INSTANCY_LEVEL, instancyLevel);
}
public List findByEffectLevel(Object effectLevel) {
return findByProperty(EFFECT_LEVEL, effectLevel);
}
public List findBySkillLevel(Object skillLevel) {
return findByProperty(SKILL_LEVEL, skillLevel);
}
public List findByLatencyTime(Object latencyTime) {
return findByProperty(LATENCY_TIME, latencyTime);
}
public List findByAttachment(Object attachment) {
return findByProperty(ATTACHMENT, attachment);
}
public List findByEnventId(Object enventId) {
return findByProperty(ENVENT_ID, enventId);
}
public List findAll() {
log.debug("finding all Rfc instances");
try {
String queryString = "from Rfc";
return getHibernateTemplate().find(queryString);
} catch (RuntimeException re) {
log.error("find all failed", re);
throw re;
}
}
public Rfc merge(Rfc detachedInstance) {
log.debug("merging Rfc instance");
try {
Rfc result = (Rfc) getHibernateTemplate().merge(detachedInstance);
log.debug("merge successful");
return result;
} catch (RuntimeException re) {
log.error("merge failed", re);
throw re;
}
}
public void attachDirty(Rfc instance) {
log.debug("attaching dirty Rfc instance");
try {
getHibernateTemplate().saveOrUpdate(instance);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
public void attachClean(Rfc instance) {
log.debug("attaching clean Rfc instance");
try {
getHibernateTemplate().lock(instance, LockMode.NONE);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
public static RfcDAO getFromApplicationContext(ApplicationContext ctx) {
return (RfcDAO) ctx.getBean("RfcDAO");
}
/**
* 实现模糊查询
*/
public List findRfcObscurity(String type, String rfcname, String submitter) {
// TODO Auto-generated method stub
DetachedCriteria crs=DetachedCriteria.forClass(Rfc.class);
if(rfcname!=null&&!rfcname.equals("")){
crs.add(Restrictions.like("rfcname",rfcname,MatchMode.ANYWHERE));
}
if(type!=null&&!type.equals("")){
crs.add(Expression.eq("types", type));
}
if(submitter!=null&&!submitter.equals("")){
crs.createCriteria("users")
.add(Expression.like("userName",submitter,MatchMode.ANYWHERE));
}
List RFCList=getHibernateTemplate().findByCriteria(crs);
return RFCList;
}
/**
* 实现精确查询
*/
public List findRfcSpecify(String beginTime, String endTime, String type) {
// TODO Auto-generated method stub
DetachedCriteria crs=DetachedCriteria.forClass(Rfc.class)
.add(Expression.ge("submitDate",beginTime))
.add(Expression.le("submitDate",endTime));
if(type!=null&&!type.equals("")){
crs.add(Expression.eq("types", type));
}
List RFCList=getHibernateTemplate().findByCriteria(crs);
/*Iterator it=RFCList.iterator();
while(it.hasNext()){
Rfc RFC=(Rfc)it.next();
Hibernate.initialize(RFC.getUsers());
}*/
return RFCList;
}
/**
* 统计某时间段内部门的变更数目
*/
public int StateRfcTT(String beginTime,String endTime,String type){
DetachedCriteria crs=DetachedCriteria.forClass(Rfc.class)
.add(Expression.ge("submitDate",beginTime))
.add(Expression.le("submitDate",endTime))
.add(Expression.eq("types", type));
List RFCList=getHibernateTemplate().findByCriteria(crs);
return RFCList.size();
}
/**
* 统计某时间段内每天的总变更数目
*/
public int StateRfcDay(String beginTime,String endTime){
return 0;
}
/**
* 统计某时间段内每周的总变更数目
*/
public int StateRfcWeek(String beginTime,String endTime){
return 0;
}
/**
* 统计某时间段内每月的总变更数目
*/
public int StateRfcMonth(String beginTime,String endTime){
return 0;
}
/**
* 统计某时间段内每年的总变更的数目
*/
public int StateRfcYear(String beginTime,String endTime){
return 0;
}
/**
* 根据rfc的状态和所属的类型来进行查询
* 前提条件:Rfc状态和所属的类型都不为空
*/
public List findByST(String state,String type){
DetachedCriteria crs=DetachedCriteria.forClass(Rfc.class)
.add(Expression.eq("state",state))
.add(Expression.eq("types",type));
List RfcList=getHibernateTemplate().findByCriteria(crs);
return RfcList;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -