📄 newstdao.java
字号:
package po.news;
import hibernate.BaseHibernateDAO;
import java.util.Date;
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 org.hibernate.*;
import org.hibernate.criterion.*;
/**
* Data access object (DAO) for domain model class Newst.
* @see po.news.Newst
* @author MyEclipse - Hibernate Tools
*/
public class NewstDAO extends BaseHibernateDAO {
private static final Log log = LogFactory.getLog(NewstDAO.class);
//property constants
public static final String COLUMN_ID = "columnId";
public static final String TITLE = "title";
public static final String CONTENT = "content";
public static final String AUTHOR = "author";
/**
* @param author
* @param title
* @return
*/
public List findByHQL(String author,String title)
{
log.debug("getting Newst instances List by author:"+author+" and title:" + title);
try {
Criteria criteria=getSession().createCriteria(Newst.class);
if(!author.equals(""))
{
criteria.add(Expression.eq("author", author));
}
if(!title.equals(""))
{
criteria.add(Expression.like("title", title,MatchMode.ANYWHERE));
}
List list=criteria.list();
log.debug("getting list successful");
return list;
} catch (RuntimeException re) {
log.error("get failed", re);
throw re;
}
}
public void save(Newst transientInstance) {
log.debug("saving Newst instance");
try {
getSession().save(transientInstance);
log.debug("save successful");
} catch (RuntimeException re) {
log.error("save failed", re);
throw re;
}
}
public void delete(Newst persistentInstance) {
log.debug("deleting Newst instance");
try {
getSession().delete(persistentInstance);
log.debug("delete successful");
} catch (RuntimeException re) {
log.error("delete failed", re);
throw re;
}
}
public Newst findById( java.lang.Integer id) {
log.debug("getting Newst instance with id: " + id);
try {
Newst instance = (Newst) getSession()
.get("po.news.Newst", id);
return instance;
} catch (RuntimeException re) {
log.error("get failed", re);
throw re;
}
}
public List findByExample(Newst instance) {
log.debug("finding Newst instance by example");
try {
List results = getSession()
.createCriteria("po.news.Newst")
.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 Newst instance with property: " + propertyName
+ ", value: " + value);
try {
String queryString = "from Newst 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 findByColumnId(Object columnId) {
return findByProperty(COLUMN_ID, columnId);
}
public List findByTitle(Object title) {
return findByProperty(TITLE, title);
}
public List findByContent(Object content) {
return findByProperty(CONTENT, content);
}
public List findByAuthor(Object author) {
return findByProperty(AUTHOR, author);
}
public Newst merge(Newst detachedInstance) {
log.debug("merging Newst instance");
try {
Newst result = (Newst) getSession()
.merge(detachedInstance);
log.debug("merge successful");
return result;
} catch (RuntimeException re) {
log.error("merge failed", re);
throw re;
}
}
public void attachDirty(Newst instance) {
log.debug("attaching dirty Newst instance");
try {
getSession().saveOrUpdate(instance);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
public void attachClean(Newst instance) {
log.debug("attaching clean Newst 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 + -