📄 contentimpl.java
字号:
/*
* Created on 2005-10-22
* Last modified on 2007-1-21
* Powered by YeQiangWei.com
*/
package com.yeqiangwei.club.dao.hibernate.impl;
import java.util.List;
import com.yeqiangwei.club.dao.model.Content;
import com.yeqiangwei.club.param.TopicParameter;
import com.yeqiangwei.club.dao.ContentDAO;
import com.yeqiangwei.club.dao.hibernate.support.HibernateFacade;
public class ContentImpl implements ContentDAO {
private static final String FIND_CONTENTID = "from Content where contentId=?";
private static final String FIND_TOPICID = "from Content where topicId=?";
private static final String DELETE_TOPICID = "delete from Content where topicId=?";
private static final String DELETES_TOPICID = "delete from Content where topicId in (:ids)";
private static final String DELETE_CONTENTID = "delete from Content where contentId=?";
private static final String DELETES_CONTENTID = "delete from Content where contentId in (:ids)";
public Content create(Content item) {
HibernateFacade<Content> facade = new HibernateFacade<Content>();
item = facade.save(item);
return item;
}
public Content update(Content item) {
HibernateFacade<Content> facade = new HibernateFacade<Content>();
item = facade.update(item);
return item;
}
public int delete(Content item) {
HibernateFacade<Content> facade = new HibernateFacade<Content>();
facade.createQuery(DELETE_CONTENTID);
facade.setInt(0, item.getContentId());
int c = facade.executeUpdate();
return c;
}
public int delete(List ids) {
HibernateFacade<Content> facade = new HibernateFacade<Content>();
facade.createQuery(DELETES_CONTENTID);
facade.setParameterList("ids",ids);
int c = facade.executeUpdate();
return c;
}
public int deleteByTopicId(int topicId) {
HibernateFacade<Content> facade = new HibernateFacade<Content>();
facade.createQuery(DELETE_TOPICID);
facade.setInt(0, topicId);
int c = facade.executeUpdate();
return c;
}
public int deleteByTopicId(List<Integer> ids) {
HibernateFacade<Content> facade = new HibernateFacade<Content>();
facade.createQuery(DELETES_TOPICID);
facade.setParameterList("ids",ids);
int c = facade.executeUpdate();
return c;
}
public Content findById(int id) {
Content item = null;
HibernateFacade<Content> facade = new HibernateFacade<Content>();
facade.createQuery(FIND_CONTENTID);
facade.setInt(0,id);
facade.setMaxResults(1);
item = (Content) facade.uniqueResult();
return item;
}
public Content findByTopicId(int topicId) {
Content item = null;
HibernateFacade<Content> facade = new HibernateFacade<Content>();
facade.createQuery(FIND_TOPICID);
facade.setInt(0,topicId);
facade.setMaxResults(1);
item = (Content) facade.uniqueResult();
return item;
}
public List<Content> findByParameter(TopicParameter param) {
StringBuffer hql = new StringBuffer();
hql.append("from Content where ");
if(param.getMinId()==null){
hql.append(" topicId>0 ");
}else{
hql.append(" topicId>");
hql.append(param.getMinId().intValue());
}
if(param.getIsDeleted()!=null){
hql.append(" and isDeleted=?");
}
else if(param.getOrderBy().byteValue()==4){
hql.append(" order by topicId");
}
//System.out.println(hql);
HibernateFacade<Content> facade = new HibernateFacade<Content>();
facade.createQuery(hql);
if(param.getIsDeleted()!=null){
facade.setBoolean(0, param.getIsDeleted());
}
facade.setFirstResult(param.getPagination().getStartRow());
facade.setMaxResults(param.getPagination().getEndRow());
List<Content> list = facade.executeQuery();
return list;
}
public long countByParameter(TopicParameter param) {
StringBuffer hql = new StringBuffer();
hql.append("select(contentId) from Content where ");
if(param.getMinId()==null){
hql.append(" topicId>0 ");
}else{
hql.append(" topicId>");
hql.append(param.getMinId().intValue());
}
if(param.getIsDeleted()!=null){
hql.append(" and isDeleted=?");
}
HibernateFacade<Content> facade = new HibernateFacade<Content>();
facade.createQuery(hql);
if(param.getIsDeleted()!=null){
facade.setBoolean(0, param.getIsDeleted());
}
facade.setCacheable(true);
//long c = facade.resultTotal();
return facade.resultTotalInteger();
}
public List findAll(TopicParameter param) {
return null;
}
public long countAll(TopicParameter param) {
return 0;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -