📄 classroomdao.java
字号:
package com.dcs.hibernate;
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.criterion.Example;
/**
* Data access object (DAO) for domain model class Classroom.
* @see com.dcs.hibernate.Classroom
* @author MyEclipse - Hibernate Tools
*/
public class ClassroomDAO extends BaseHibernateDAO {
private static final Log log = LogFactory.getLog(ClassroomDAO.class);
//property constants
public static final String LOCATION = "location";
public static final String CAPABILITY = "capability";
public static final String TYPE = "type";
public void save(Classroom transientInstance) {
log.debug("saving Classroom instance");
try {
getSession().save(transientInstance);
log.debug("save successful");
} catch (RuntimeException re) {
log.error("save failed", re);
throw re;
}
}
public void delete(Classroom persistentInstance) {
log.debug("deleting Classroom instance");
try {
getSession().delete(persistentInstance);
log.debug("delete successful");
} catch (RuntimeException re) {
log.error("delete failed", re);
throw re;
}
}
public Classroom findById( java.lang.String id) {
log.debug("getting Classroom instance with id: " + id);
try {
Classroom instance = (Classroom) getSession()
.get("com.dcs.hibernate.Classroom", id);
return instance;
} catch (RuntimeException re) {
log.error("get failed", re);
throw re;
}
}
public List findByExample(Classroom instance) {
log.debug("finding Classroom instance by example");
try {
List results = getSession()
.createCriteria("com.dcs.hibernate.Classroom")
.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 Classroom instance with property: " + propertyName
+ ", value: " + value);
try {
String queryString = "from Classroom 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 List findByLocation(Object location) {
return findByProperty(LOCATION, location);
}
public List findByCapability(Object capability) {
return findByProperty(CAPABILITY, capability);
}
public List findByType(Object type) {
return findByProperty(TYPE, type);
}
public Classroom merge(Classroom detachedInstance) {
log.debug("merging Classroom instance");
try {
Classroom result = (Classroom) getSession()
.merge(detachedInstance);
log.debug("merge successful");
return result;
} catch (RuntimeException re) {
log.error("merge failed", re);
throw re;
}
}
public void attachDirty(Classroom instance) {
log.debug("attaching dirty Classroom instance");
try {
getSession().saveOrUpdate(instance);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
public void attachClean(Classroom instance) {
log.debug("attaching clean Classroom instance");
try {
getSession().lock(instance, LockMode.NONE);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -