📄 cfourmdao.java
字号:
package cn.hope.front.pojo.dao;
import java.util.List;
import net.sf.hibernate.HibernateException;
import net.sf.hibernate.Query;
import org.apache.log4j.Logger;
import cn.hope.front.pojo.CFourm;
import cn.hope.front.pojo.base.BaseCFourmDAO;
public class CFourmDAO extends BaseCFourmDAO {
Logger log = Logger.getLogger(CFourmDAO.class.getName());
/**
* Default constructor. Can be used in place of getInstance()
*/
public CFourmDAO () {}
//==========zhang hong tao ==============
public CFourm U01D100fourm(String TSortid) throws HibernateException {
List list = null;
CFourm cf=new CFourm();
String sqlStr = "from CFourm c where c.flag='0' and c.CFlevel2.TSortid='"+TSortid+"'";
try {
initialize();
list = this.getSession().find(sqlStr);
if(list.size()>0){
cf=(CFourm)list.get(0);
}
} catch (HibernateException e) {
log.error(e);
e.printStackTrace();
throw new HibernateException(e);
} finally {
closeCurrentThreadSessions();
}
return cf;
}
private int zht = 0;
public int getCount() {
return this.zht;
}
public List search(String TSortid, int start, int range, boolean isEq)
throws HibernateException {
List list = null;
StringBuffer sqlCnt = new StringBuffer();// 取总记录数
StringBuffer sqlStr = new StringBuffer();// 长字符串的拼合一定要用StringBuffer.append()
StringBuffer condition = new StringBuffer();// 查询条件
sqlCnt.append("select count(*) from CFourm c where c.flag='0' and c.CFlevel2.TSortid='"+TSortid+"'");
sqlStr.append("from CFourm c where c.flag='0' and c.CFlevel2.TSortid='"+TSortid+"'");
/* 通过tFile中存储的条件组装HQL语句 */
try {
initialize();
Query queryCnt = this.getSession().createQuery(
sqlCnt.toString() + condition);// 通过hibernate的Query方法查询数据库(自己看文档)
Integer zht = (Integer) queryCnt.uniqueResult();// 得到总记录数
this.zht =zht.intValue();
condition.append(" order by c.CFlevel2.TSortid desc");// 加入排序条件
Query query = this.getSession().createQuery(
sqlStr.toString() + condition);
query.setFirstResult(start);// 设置查询起始记录数
query.setMaxResults(range);// 设置查询总记录数
list = query.list();
} catch (HibernateException e) {
log.error(e);
e.printStackTrace();
throw new HibernateException(e);
} finally {
closeCurrentThreadSessions();
}
return list;
}
public Integer U01D12insert(CFourm cfourm) throws HibernateException {
int falg=0;
Integer in=new Integer(falg);
try {
initialize();// 初始化session
in=this.save(cfourm);// 调用生成好的父类方法save(),返回被插入数据的主键
} catch (HibernateException e) {
log.error(e);
e.printStackTrace();
throw new HibernateException(e);
} finally {
closeCurrentThreadSessions();// 关闭当前session
}
return in;
}
public CFourm U01D1000fourm(String TTopicid) throws HibernateException {
List list = null;
String sqlStr = "from CFourm c where c.flag='0' and c.TTopicid='"+TTopicid+"'";
CFourm cfm=new CFourm();
try {
initialize();
//查寻名字
list = this.getSession().find(sqlStr);//从数据库提取名字和密码
System.out.println(list);
if(list!=null){
if(list.size()>0){ //放到实体中去
cfm =(CFourm) list.get(0);
}else{
cfm=null;
}
}
System.out.println(cfm);
return cfm;
} catch (HibernateException e) {
log.error(e);
e.printStackTrace();
throw new HibernateException(e);
} finally {
closeCurrentThreadSessions();
}
}
private int cout = 0;
public int getaCount() {
return this.cout;
}
public List D100kansearch(String TSortid,String name,String Tname, int start, int range, boolean isEq)
throws HibernateException {
List list = null;
StringBuffer sqlCnt = new StringBuffer();// 取总记录数
StringBuffer sqlStr = new StringBuffer();// 长字符串的拼合一定要用StringBuffer.append()
StringBuffer condition = new StringBuffer();// 查询条件
sqlCnt.append("select count(*) from CFourm c where c.flag='0' and c.CFlevel2.TSortid='"+TSortid+"' and c.TTopicname like '"+Tname+"%' and c.student.SUsername like'%"+name+"%'");
sqlStr.append(" from CFourm c where c.flag='0' and c.CFlevel2.TSortid='"+TSortid+"' and c.TTopicname like '"+Tname+"%' and c.student.SUsername like '%"+name+"%'");
/* 通过tFile中存储的条件组装HQL语句 */
try {
initialize();
Query queryCnt = this.getSession().createQuery(
sqlCnt.toString() + condition);// 通过hibernate的Query方法查询数据库(自己看文档)
Integer cout = (Integer) queryCnt.uniqueResult();// 得到总记录数
this.cout =cout.intValue();
System.out.println(cout);
condition.append(" order by c.CFlevel2.TSortid desc");// 加入排序条件
Query query = this.getSession().createQuery(
sqlStr.toString() + condition);
query.setFirstResult(start);// 设置查询起始记录数
query.setMaxResults(range);// 设置查询总记录数
list = query.list();
} catch (HibernateException e) {
log.error(e);
e.printStackTrace();
throw new HibernateException(e);
} finally {
closeCurrentThreadSessions();
}
return list;
}
public void uprestore(CFourm cfourm) throws HibernateException {
try {
initialize();
this.update(cfourm);
} catch (HibernateException e) {
log.error(e);
e.printStackTrace();
throw new HibernateException(e);
} finally {
closeCurrentThreadSessions();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -