?? workinfdao.java
字號(hào):
package xing.five.beans;
import java.util.Date;
import java.util.Iterator;
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.hibernate.Transaction;
import org.hibernate.criterion.Example;
/**
* Data access object (DAO) for domain model class WorkInf.
*
* @see xing.five.beans.WorkInf
* @author MyEclipse Persistence Tools
*/
public class WorkInfDAO extends BaseHibernateDAO {
private static final Log log = LogFactory.getLog(WorkInfDAO.class);
// property constants
public static final String NAME = "name";
public static final String DEGREE = "degree";
public static final String _QID = "QId";
public static final String _PID = "PId";
public static final String STATE = "state";
public void save(WorkInf transientInstance) {
log.debug("saving WorkInf instance");
Session s=getSession();
try {
Transaction tr=s.beginTransaction();
getSession().save(transientInstance);
tr.commit();
log.debug("save successful");
} catch (RuntimeException re) {
log.error("save failed", re);
throw re;
}
}
public void update(WorkInf transientInstance) {
log.debug("saving WorkInf instance");
Session s=getSession();
try {
Transaction tr=s.beginTransaction();
getSession().update(transientInstance);
log.debug("update successful");
tr.commit();
} catch (RuntimeException re) {
log.error("update failed", re);
throw re;
}
}
public List find(String state,Integer id)
{
Session session=HibernateSessionFactory.getSession();
Transaction tx=session.beginTransaction();
String hql="from xing.five.beans.WorkInf as a where a.state=? and a.PId=?";
Query q=session.createQuery(hql);
q.setParameter(0, state);
q.setParameter(1, id);
List l=q.list();
tx.commit();
session.close();
return l;
}
public List findConf(String state,Integer id) {
log.debug("finding WorkInf instance with property: " );
try {
String queryString = "from WorkInf where state=? and PId=? order by b_date" ;
Query queryObject = getSession().createQuery(queryString);
queryObject.setParameter(0, state);
queryObject.setParameter(1, id);
return queryObject.list();
} catch (RuntimeException re) {
log.error("find by property name failed", re);
throw re;
}
}
public void delete(WorkInf persistentInstance) {
log.debug("deleting WorkInf instance");
try {
getSession().delete(persistentInstance);
log.debug("delete successful");
} catch (RuntimeException re) {
log.error("delete failed", re);
throw re;
}
}
public WorkInf findById(java.lang.Integer id) {
log.debug("getting WorkInf instance with id: " + id);
try {
WorkInf instance = (WorkInf) getSession().get(
"xing.five.beans.WorkInf", id);
return instance;
} catch (RuntimeException re) {
log.error("get failed", re);
throw re;
}
}
public Integer findbyqid(WorkInf w)
{
Integer id=new Integer(0);
Session session=HibernateSessionFactory.getSession();
Transaction tx=session.beginTransaction();
String hql="from xing.five.beans.WorkInf";
Query q=session.createQuery(hql);
tx.commit();
List l=q.list();
Iterator it= l.iterator();
while (it.hasNext()){
WorkInf wo=(WorkInf)it.next();
if(wo.getQId().equals(w.getQId()))
id=wo.getId();
}
return id;
}
public List findByExample(WorkInf instance) {
log.debug("finding WorkInf instance by example");
try {
List results = getSession().createCriteria(
"xing.five.beans.WorkInf").add(Example.create(instance))
.list();
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 WorkInf instance with property: " + propertyName
+ ", value: " + value);
try {
String queryString = "from WorkInf as model where model."
+ propertyName + "= ?";
Query queryObject = getSession().createQuery(queryString);
queryObject.setParameter(0, value);
return queryObject.list();
} catch (RuntimeException re) {
log.error("find by property name failed", re);
throw re;
}
}
public WorkInf findByqid(String propertyName, Object value) {
log.debug("finding WorkInf instance with property: " + propertyName
+ ", value: " + value);
try {
String queryString = "from WorkInf as model where model."
+ propertyName + "= ?";
Query queryObject = getSession().createQuery(queryString);
queryObject.setParameter(0, value);
return WorkInf(queryObject);
} catch (RuntimeException re) {
log.error("find by property name failed", re);
throw re;
}
}
private WorkInf WorkInf(Query queryObject) {
// TODO Auto-generated method stub
return null;
}
public List findByName(Object name) {
return findByProperty(NAME, name);
}
public List findByDegree(Object degree) {
return findByProperty(DEGREE, degree);
}
public List findByPId(Object PId) {
return findByProperty(_PID, PId);
}
public List findByState(Object state) {
return findByProperty(STATE, state);
}
public List findAll() {
log.debug("finding all WorkInf instances");
try {
String queryString = "from WorkInf";
Query queryObject = getSession().createQuery(queryString);
return queryObject.list();
} catch (RuntimeException re) {
log.error("find all failed", re);
throw re;
}
}
public WorkInf merge(WorkInf detachedInstance) {
log.debug("merging WorkInf instance");
try {
WorkInf result = (WorkInf) getSession().merge(detachedInstance);
log.debug("merge successful");
return result;
} catch (RuntimeException re) {
log.error("merge failed", re);
throw re;
}
}
public void attachDirty(WorkInf instance) {
log.debug("attaching dirty WorkInf instance");
try {
getSession().saveOrUpdate(instance);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
public void attachClean(WorkInf instance) {
log.debug("attaching clean WorkInf instance");
try {
getSession().lock(instance, LockMode.NONE);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -