package cn.com.sp.common.model;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
/**
* Data access object (DAO) for domain model class Mtrecords.
* @see cn.com.sp.common.model.Mtrecords
* @author MyEclipse - Hibernate Tools
*/
public class MtrecordsDAO extends HibernateDaoSupport {
private static final Log log = LogFactory.getLog(MtrecordsDAO.class);
//property constants
public static final String MTSMGID = "mtsmgid";
public static final String MTPHONE_NUMBER = "mtphoneNumber";
public static final String MTSPNUMBER = "mtspnumber";
public static final String MTRESULT = "mtresult";
public static final String MTCONTENT = "mtcontent";
public static final String MTRECEIVE_TIME = "mtreceiveTime";
protected void initDao() {
//do nothing
}
// 查询所有的mt总行数
public Integer getCountAllMt(){
String hql="select count(*) from Mtrecords";
return (Integer)this.getSession().createQuery(hql).uniqueResult();
}
//分页查询全部mt
public List getByPage(int rowStart){
String hql="from Mtrecords order by mtid desc";
return this.getSession().createQuery(hql).setFirstResult(rowStart).setMaxResults(5).list();
}
//根据手机号模糊查询总行数
public Integer findCountByPhone(String phoneNumber){
String hql="select count(*) from Mtrecords mt where mt.mtphoneNumber like '"+phoneNumber+"%'";
return (Integer)this.getSession().createQuery(hql).uniqueResult();
}
//根据状态查询总行数
public Integer findCountByState(int state){
//如果小写的mtresult写成MtResult会报错!!!!!
String hql="select count(*) from cn.com.sp.common.model.Mtrecords mt where mt.mtresult="+state;
return (Integer)this.getSession().createQuery(hql).uniqueResult();
}
//根据日期段查询Mt总行数
public Integer findCountByTime(String startTime,String endTime){
String hql="select count(*) from Mtrecords mt where mt.mtreceiveTime between '"+startTime+"' and '"+endTime+"'";
return (Integer)this.getSession().createQuery(hql).uniqueResult();
}
//根据手机号和状态查询Mt总行数
public Integer findCountByPhoneNumberAndState(String phoneNumber,int state){
String hql="select count(*) from Mtrecords mt where mt.mtphoneNumber like '"+phoneNumber+"%' and mtresult="+state;
return (Integer)this.getSession().createQuery(hql).uniqueResult();
}
//根据日期和状态查询总行数
public Integer findCountByTimeAndState(String startTime,String endTime,int state){
String hql="select count(*) from Mtrecords mt where mt.mtreceiveTime between '"+startTime+"' and '"+endTime+"' and mtresult="+state;
return (Integer)this.getSession().createQuery(hql).uniqueResult();
}
//根据日期和手机号查询总行数
public Integer findCountTimeAndPhoneNumber(String startTime,String endTime,String phoneNumber){
String hql="select count(*) from Mtrecords mt where mt.mtreceiveTime between '"+startTime+"' and '"+endTime+"' and mtphoneNumber like '"+phoneNumber+"%'";
return (Integer)this.getSession().createQuery(hql).uniqueResult();
}
//根据日期,手机号和状态查询总行数
public Integer findCountByTimeAndPhoneNumberAndState(String startTime,String endTime,String phoneNumber,int state){
String hql="select count(*) from Mtrecords mt where mt.mtreceiveTime between '"+startTime+"' and '"+endTime+"' and mtphoneNumber like '"+phoneNumber+"%'and mtresult="+state;
return (Integer)this.getSession().createQuery(hql).uniqueResult();
}
// 根据手机号模糊分页查询
public List findFByPhone(String phoneNumber,int rowStart){
String hql="from Mtrecords mt where mt.mtphoneNumber like '"+phoneNumber+"%' order by mtid desc";
List list=this.getSession().createQuery(hql).setFirstResult(rowStart).setMaxResults(5).list();
return list;
}
//根据状态分页查询
public List findFMtByState(int state,int rowStart){
String hql="from cn.com.sp.common.model.Mtrecords mt where mt.mtresult="+state+" order by mtid desc";
List list=this.getSession().createQuery(hql).setFirstResult(rowStart).setMaxResults(5).list();
return list;
}
//根据日期段分页查询Mt
public List findFMtByTime(String startTime,String endTime,int rowStart){
String hql="from Mtrecords mt where mt.mtreceiveTime between '"+startTime+"' and '"+endTime+"' order by mt.mtid desc";
return this.getSession().createQuery(hql).setFirstResult(rowStart).setMaxResults(5).list();
}
//根据手机号和状态分页查询Mt
public List findFMtByPhoneNumberAndState(String phoneNumber,int state,int rowStart){
String hql="from Mtrecords mt where mt.mtphoneNumber like '"+phoneNumber+"%' and mtresult="+state+" order by mt.mtid desc";
return this.getSession().createQuery(hql).setFirstResult(rowStart).setMaxResults(5).list();
}
//根据日期和状态分页查询
public List findFMtByTimeAndState(String startTime,String endTime,int state,int rowStart){
String hql="from Mtrecords mt where mt.mtreceiveTime between '"+startTime+"' and '"+endTime+"' and mtresult="+state+" order by mt.mtid desc";
return this.getSession().createQuery(hql).setFirstResult(rowStart).setMaxResults(5).list();
}
//根据日期和手机号分页查询
public List findFMtByTimeAndPhoneNumber(String startTime,String endTime,String phoneNumber,int rowStart){
String hql="from Mtrecords mt where mt.mtreceiveTime between '"+startTime+"' and '"+endTime+"' and mtphoneNumber like '"+phoneNumber+"%' order by mt.mtid desc";
return this.getSession().createQuery(hql).setFirstResult(rowStart).setMaxResults(5).list();
}
//根据日期,手机号和状态分页查询
public List findFMtByTimeAndPhoneNumberAndState(String startTime,String endTime,String phoneNumber,int state,int rowStart){
String hql="from Mtrecords mt where mt.mtreceiveTime between '"+startTime+"' and '"+endTime+"' and mtphoneNumber like '"+phoneNumber+"%'and mtresult="+state+" order by mt.mtid desc";
return this.getSession().createQuery(hql).setFirstResult(rowStart).setMaxResults(5).list();
}
public void save(Mtrecords transientInstance) {
log.debug("saving Mtrecords instance");
try {
getHibernateTemplate().save(transientInstance);
log.debug("save successful");
} catch (RuntimeException re) {
log.error("save failed", re);
throw re;
}
}
public void delete(Mtrecords persistentInstance) {
log.debug("deleting Mtrecords instance");
try {
getHibernateTemplate().delete(persistentInstance);
log.debug("delete successful");
} catch (RuntimeException re) {
log.error("delete failed", re);
throw re;
}
}
public Mtrecords findById( java.lang.Integer id) {
log.debug("getting Mtrecords instance with id: " + id);
try {
Mtrecords instance = (Mtrecords) getHibernateTemplate()
.get("cn.com.sp.common.model.Mtrecords", id);
return instance;
} catch (RuntimeException re) {
log.error("get failed", re);
throw re;
}
}
public List findByExample(Mtrecords instance) {
log.debug("finding Mtrecords instance by example");
try {
List results = getHibernateTemplate().findByExample(instance);
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 Mtrecords instance with property: " + propertyName