📄 forumdao.java
字号:
package mokoda.entity;
import java.util.ArrayList;
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.criterion.Example;
/**
* Data access object (DAO) for domain model class Forum.
* @see mokoda.entity.Forum
* @author MyEclipse - Hibernate Tools
*/
public class ForumDAO extends BaseHibernateDAO {
private static final Log log = LogFactory.getLog(ForumDAO.class);
//property constants
public static final String NAME = "name";
public static final String HOSTID = "hostid";
public void save(Forum transientInstance) {
log.debug("saving Forum instance");
try {
getSession().save(transientInstance);
log.debug("save successful");
} catch (RuntimeException re) {
log.error("save failed", re);
throw re;
}
}
public void delete(Forum persistentInstance) {
log.debug("deleting Forum instance");
try {
getSession().delete(persistentInstance);
log.debug("delete successful");
} catch (RuntimeException re) {
log.error("delete failed", re);
throw re;
}
}
public Forum findById( java.lang.Integer id) {
log.debug("getting Forum instance with id: " + id);
try {
Forum instance = (Forum) getSession()
.get("mokoda.entity.Forum", id);
return instance;
} catch (RuntimeException re) {
log.error("get failed", re);
throw re;
}
}
public List findByExample(Forum instance) {
log.debug("finding Forum instance by example");
try {
List results = getSession()
.createCriteria("mokoda.entity.Forum")
.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 Forum instance with property: " + propertyName
+ ", value: " + value);
try {
String queryString = "from Forum 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 findByHostid(Object hostid) {
return findByProperty(HOSTID, hostid);
}
public Forum merge(Forum detachedInstance) {
log.debug("merging Forum instance");
try {
Forum result = (Forum) getSession()
.merge(detachedInstance);
log.debug("merge successful");
return result;
} catch (RuntimeException re) {
log.error("merge failed", re);
throw re;
}
}
public void attachDirty(Forum instance) {
log.debug("attaching dirty Forum instance");
try {
getSession().saveOrUpdate(instance);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
public void attachClean(Forum instance) {
log.debug("attaching clean Forum instance");
try {
getSession().lock(instance, LockMode.NONE);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
public static List<Forum> getAllForums(){
Query query = new ForumDAO().getSession().createQuery("from Forum");
List list = query.list();
List<Forum> frms = new ArrayList<Forum>();
for(Object i: list){
frms.add((Forum)i);
}
return frms;
}
/**
* @param id
* @return
*/
public static List getAllTpcs(Integer id) {
Session session = new ForumDAO().getSession();
Query query = session.createQuery("select tf.id.tpcid from Tpc2frm tf where tf.id.frmid="+id);
List tpcids = query.list();
List<Message> tpcs = new ArrayList<Message>();
MessageDAO mdao = new MessageDAO();
for(Object tempid: tpcids){
tpcs.add(mdao.findById((Integer)tempid));
}
return tpcs;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -