📄 informationdaohibernate.java
字号:
package com.longtime.wap.module.front.dao.hibernate;
import java.sql.SQLException;
import java.util.List;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;
import com.longtime.wap.common.BaseDao;
import com.longtime.wap.common.web.Page;
import com.longtime.wap.model.Information;
import com.longtime.wap.module.front.dao.InformationDao;
/**
* InformationDao层代码实现
*
* @author bulc
* @date Nov 22, 2007
*/
public class InformationDaoHibernate extends BaseDao
implements InformationDao {
/**
* 获取信息对象
*
* @param id
* 信息编号
* @return 信息对象
*/
public Information retrieveInfoById(Long id) {
return (Information) this.getHibernateTemplate().load(
Information.class, id);
}
/**
* 获取热点信息对象
*
* @param page
* 分页参数
* @return 热点信息对象
*/
public List retrieveInfosByIsHotAndIsPub(final Page page) {
return getHibernateTemplate().executeFind(new HibernateCallback() {
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
Query query = session.createQuery("from Information info "
+ "where info.isPub=1 " + "and info.isHot=1 "
+ "and (info.pubDate+info.business.duration)"
+ ">SYSDATE order by info.pubDate desc");
return query.setFirstResult(page.getFirstResult())
.setMaxResults(page.getPageSize()).list();
}
});
}
/**
* 获取推荐信息对象
*
* @param page
* 分页参数
* @return 推荐信息对象
*/
public List retrieveInfosByIsRecommendAndIsPub(final Page page) {
return getHibernateTemplate().executeFind(new HibernateCallback() {
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
Query query = session.createQuery("from Information info "
+ "where info.isPub=1 " + "and info.isRecommend=1 "
+ "and (info.pubDate+info.business.duration)"
+ ">SYSDATE order by info.pubDate desc");
return query.setFirstResult(page.getFirstResult())
.setMaxResults(page.getPageSize()).list();
}
});
}
/**
* 获取不同业务类型的信息对象
*
* @param category
* 业务分类
* @param page
* 分页参数
* @return 不同业务分类的信息对象
*/
public List retrieveInfosByCategoryAndViewCount(final Integer category,
final Page page) {
return getHibernateTemplate().executeFind(new HibernateCallback() {
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
Query query = session.createQuery("from Information info "
+ "where info.isPub=1 "
+ "and info.business.category=? "
+ "and (info.pubDate+info.business.duration)"
+ ">SYSDATE order by info.pubDate desc");
query.setLong(0, category);
return query.setFirstResult(page.getFirstResult())
.setMaxResults(page.getPageSize()).list();
}
});
}
/**
* 根据搜索的内容来获取信息对象
*
* @param content
* 搜索内容
* @param page
* 分页参数
* @return 信息对象列表
*/
public List retrieveInfosByContent(final String content,
final Page page) {
return getHibernateTemplate().executeFind(new HibernateCallback() {
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
Query query = session.createQuery("from Information info "
+ "where info.isPub=1 and "
+ "(info.content like ? or info.title like ?) "
+ "order by info.informationId");
query.setString(0, "%" + content + "%");
query.setString(1, "%" + content + "%");
return query.setFirstResult(page.getFirstResult())
.setMaxResults(page.getPageSize()).list();
}
});
}
/**
* 更新信息内容
*
* @param info
* 信息对象
*/
public void updateInfo(Information info) {
this.getHibernateTemplate().update(info);
}
/**
* 通过业务编号列表显示信息内容
*
* @param businessId
* 业务编号
* @param page
* 分页参数
* @return 信息对象列表
*/
public List retrieveInfosByBusinessId(final Long businessId,
final Page page) {
return getHibernateTemplate().executeFind(new HibernateCallback() {
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
Query query = session.createQuery("from Information info "
+ "where info.isPub=1 and info.business.businessId=? "
+ "and (info.pubDate+info.business.duration)"
+ ">SYSDATE order by info.informationId");
query.setLong(0, businessId);
return query.setFirstResult(page.getFirstResult())
.setMaxResults(page.getPageSize()).list();
}
});
}
/**
* 通过业务编号统计信息数
*
* @param businessId
* 业务
* @return 信息数
*/
public int retrieveInfosCountByBusinessId(final Long businessId) {
return (Integer) getHibernateTemplate().execute(
new HibernateCallback() {
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
Query query = session.createQuery("select count(*) "
+ "from Information info where info.isPub=1 "
+ "and info.business.businessId=?"
+ "and (info.pubDate+info.business.duration)"
+ ">SYSDATE order by info.informationId");
query.setLong(0, businessId);
return query.uniqueResult();
}
});
}
/**
* 通过搜索内容统计信息数
*
* @param content
* 信息搜索内容
* @return 信息数
*/
public int retrieveInfosCountByContent(final String content) {
return (Integer) getHibernateTemplate().execute(
new HibernateCallback() {
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
Query query = session.createQuery("select count(*) "
+ "from Information info where info.isPub=1 "
+ "and "
+ "(info.content like ? or info.title like ?)");
query.setString(0, "%" + content + "%");
query.setString(1, "%" + content + "%");
return query.uniqueResult();
}
});
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -