package com.lgx8.management.dao.impl;
import java.util.List;
import org.springframework.transaction.annotation.Transactional;
import com.lgx8.common.PageArgument;
import com.lgx8.common.PageList;
import com.lgx8.common.dao.impl.BaseDao;
import com.lgx8.management.dao.INewsDao;
import com.lgx8.management.entities.News;
public class NewsDao extends BaseDao implements INewsDao{
public static final String TYPE = "type";
@Transactional
public void delete(News nw) {
this.getHibernateTemplate().delete(nw);
}
public PageList findUserByConditions(String hql, Object[] objs, PageArgument ar) {
int pageNum = ar.getCurPage();
int pageSize = ar.getPageSize();
return findByPage4Report(hql, objs, pageNum, pageSize);
}
public News findById(Integer id) {
String hql = "from News n where n.id =?";
List<News> list = getHibernateTemplate().find(hql,new Object[]{id});
if(list!=null&&list.size()>0) {
return list.get(0);
} else {
return null;
}
}
public List<News> findByType(Object type) {
String hql = "from News n where n.type ="+type+" order by n.time desc";
Object[] values = new Object[]{};
PageList page = findByPage4Report(hql, values, 0, 3);
return page.getDataList();
}
@Transactional
public void save(News nw) {
this.getHibernateTemplate().save(nw);
}
@Transactional
public void update(News nw) {
this.getHibernateTemplate().update(nw);
}
public List<News> findByType2(Object type) {
String hql = "from News n where n.type ="+type+" order by n.time desc";
return this.findByPage(hql, null, 0, 3);
}
public News findUpNewsByCurrId(String type,Integer id) {
String hql = " from News n where n.type = " + type + " and n.id < " + id + " order by n.id desc";
List<News> newsList = this.getHibernateTemplate().find(hql);
if(newsList.size() > 0)
{
return newsList.get(0);
}
return null;
}
public News findDownNewsByCurrId(String type,Integer id) {
String hql = " from News n where n.type = " + type + " and n.id > " + id + " order by n.id asc";
List<News> newsList = this.getHibernateTemplate().find(hql);
if(newsList.size() > 0)
{
return newsList.get(0);
}
return null;
}
public PageList findNewsByConditions(String type, String condition,
int pageNum, int pageSize) {
String hql = "from News n where n.type ="+type+" order by n.time desc";
return this.findByPage4Report(hql, new Object[]{}, pageNum, pageSize);
}
}