📄 moduledao.java
字号:
package com.tarena.oos.DAO;
// default package
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;
import com.tarena.oos.model.Module;
/**
* Data access object (DAO) for domain model class Module.
* @see .Module
* @author MyEclipse Persistence Tools
*/
public class ModuleDAO extends BaseDAO {
private static final Log log = LogFactory.getLog(ModuleDAO.class);
//property constants
public static final String NAME = "name";
public static final String USER_FLAG = "userFlag";
public void save(Module transientInstance) {
log.debug("saving Module instance");
try {
getSession().saveOrUpdate(transientInstance);
getSession().beginTransaction().commit();
log.debug("save successful");
} catch (RuntimeException re) {
log.error("save failed", re);
throw re;
}
}
public void delete(Module persistentInstance) {
log.debug("deleting Module instance");
try {
getSession().delete(persistentInstance);
getSession().beginTransaction().commit();
log.debug("delete successful");
} catch (RuntimeException re) {
log.error("delete failed", re);
throw re;
}
}
public Module findById( java.lang.Integer id) {
log.debug("getting Module instance with id: " + id);
try {
Module instance = (Module) getSession()
.get(Module.class, id);
return instance;
} catch (RuntimeException re) {
log.error("get failed", re);
throw re;
}
}
public List findByExample(Module instance) {
log.debug("finding Module instance by example");
try {
List results = getSession()
.createCriteria("Module")
.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 Module instance with property: " + propertyName
+ ", value: " + value);
try {
String queryString = "from Module 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 findByName(Object name) {
return findByProperty(NAME, name);
}
public List findByUserFlag(Object userFlag) {
return findByProperty(USER_FLAG, userFlag);
}
public List findAll() {
log.debug("finding all Module instances");
try {
String queryString = "from Module";
Query queryObject = getSession().createQuery(queryString);
return queryObject.list();
} catch (RuntimeException re) {
log.error("find all failed", re);
throw re;
}
}
public Module merge(Module detachedInstance) {
log.debug("merging Module instance");
try {
Module result = (Module) getSession()
.merge(detachedInstance);
log.debug("merge successful");
return result;
} catch (RuntimeException re) {
log.error("merge failed", re);
throw re;
}
}
public void attachDirty(Module instance) {
log.debug("attaching dirty Module instance");
try {
getSession().saveOrUpdate(instance);
getSession().beginTransaction().commit();
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
public void attachClean(Module instance) {
log.debug("attaching clean Module 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 + -