📄 postdao.java
字号:
package tarena.dao;
import java.sql.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 tarena.entity.Post;
/**
* Data access object (DAO) for domain model class Post.
*
* @see tarena.entity.Post
* @author MyEclipse Persistence Tools
*/
@SuppressWarnings("unchecked")
public class PostDAO extends BaseHibernateDAO {
private static final Log log = LogFactory.getLog(PostDAO.class);
// property constants
public static final String TITLE = "title";
public static final String TRANSACTIONPOINT = "transactionpoint";
public static final String READACCESS = "readaccess";
public static final String ICON = "icon";
public static final String CONTENT = "content";
public static final String FORBIDEURL = "forbideurl";
public static final String FORBIDESMILE = "forbidesmile";
public static final String FORBIDEGERWEB = "forbidegerweb";
public static final String USESIGN = "usesign";
public static final String FLOOR = "floor";
public void save(Post transientInstance) {
try {
getSession().beginTransaction();
getSession().save(transientInstance);
getSession().getTransaction().commit();
} catch (RuntimeException re) {
throw re;
}
}
public void delete(Post persistentInstance) {
try {
getSession().beginTransaction();
getSession().delete(persistentInstance);
getSession().getTransaction().commit();
} catch (RuntimeException re) {
throw re;
}
}
public Post findById(java.lang.Integer id) {
try {
Post instance = (Post) getSession().get("tarena.entity.Post", id);
return instance;
} catch (RuntimeException re) {
throw re;
}
}
public List<Post> findByPropertyBetween(String propertyName,Date start,Date end){
String hql = "from Post p where p."+propertyName+" between ? and ?";
return getSession()
.createQuery(hql)
.setParameter(0, start)
.setParameter(1, end)
.list();
}
public List<Post> findBySendTimeBetween(Date start,Date end){
return findByPropertyBetween("sendtime", start, end);
}
public List findByExample(Post instance) {
log.debug("finding Post instance by example");
try {
List results = getSession().createCriteria("tarena.entity.Post")
.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 Post instance with property: " + propertyName
+ ", value: " + value);
try {
String queryString = "from Post 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 findByTitle(Object title) {
return findByProperty(TITLE, title);
}
public List findByTransactionpoint(Object transactionpoint) {
return findByProperty(TRANSACTIONPOINT, transactionpoint);
}
public List findByReadaccess(Object readaccess) {
return findByProperty(READACCESS, readaccess);
}
public List findByIcon(Object icon) {
return findByProperty(ICON, icon);
}
public List findByContent(Object content) {
return findByProperty(CONTENT, content);
}
public List findByForbideurl(Object forbideurl) {
return findByProperty(FORBIDEURL, forbideurl);
}
public List findByForbidesmile(Object forbidesmile) {
return findByProperty(FORBIDESMILE, forbidesmile);
}
public List findByForbidegerweb(Object forbidegerweb) {
return findByProperty(FORBIDEGERWEB, forbidegerweb);
}
public List findByUsesign(Object usesign) {
return findByProperty(USESIGN, usesign);
}
public List findByFloor(Object floor) {
return findByProperty(FLOOR, floor);
}
public List findAll() {
log.debug("finding all Post instances");
try {
String queryString = "from Post";
Query queryObject = getSession().createQuery(queryString);
return queryObject.list();
} catch (RuntimeException re) {
log.error("find all failed", re);
throw re;
}
}
public Post merge(Post detachedInstance) {
log.debug("merging Post instance");
try {
Post result = (Post) getSession().merge(detachedInstance);
log.debug("merge successful");
return result;
} catch (RuntimeException re) {
log.error("merge failed", re);
throw re;
}
}
public void attachDirty(Post instance) {
log.debug("attaching dirty Post instance");
try {
getSession().saveOrUpdate(instance);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
public void attachClean(Post instance) {
log.debug("attaching clean Post 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 + -