📄 logdaoimpl.java
字号:
package yyxtong.hibernate.dao.baseimpl;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import yyxtong.comment.util.ConvertUtil;
import yyxtong.hibernate.dao.base.ILogDAO;
import yyxtong.hibernate.pojo.Emp;
import yyxtong.hibernate.pojo.Log;
import yyxtong.struts.log.form.FindlogForm;
/**
* A data access object (DAO) providing persistence and search support for Log
* entities. Transaction control of the save(), update() and delete() operations
* can directly support Spring container-managed transactions or they can be
* augmented to handle user-managed Spring transactions. Each of these methods
* provides additional information for how to configure it for the desired type
* of transaction control.
*
* @see yyxtong.hibernate.pojo.Log
* @author MyEclipse Persistence Tools
*/
public class LogDAOImpl extends HibernateDaoSupport implements ILogDAO {
private static final org.apache.commons.logging.Log log = LogFactory
.getLog(LogDAOImpl.class);
// property constants
public static final String PART_NAME = "partName";
public static final String CONTRL = "contrl";
protected void initDao() {
// do nothing
}
/* (non-Javadoc)
* @see yyxtong.hibernate.dao.baseimpl.ILogDAO#save(yyxtong.hibernate.pojo.Log)
*/
public void save(Log transientInstance) {
log.debug("saving Log instance");
try {
getHibernateTemplate().save(transientInstance);
log.debug("save successful");
} catch (RuntimeException re) {
log.error("save failed", re);
throw re;
}
}
/* (non-Javadoc)
* @see yyxtong.hibernate.dao.baseimpl.ILogDAO#delete(yyxtong.hibernate.pojo.Log)
*/
public void delete(Log persistentInstance) {
log.debug("deleting Log instance");
try {
getHibernateTemplate().delete(persistentInstance);
log.debug("delete successful");
} catch (RuntimeException re) {
log.error("delete failed", re);
throw re;
}
}
/* (non-Javadoc)
* @see yyxtong.hibernate.dao.baseimpl.ILogDAO#findById(java.lang.Integer)
*/
public Log findById(java.lang.Integer id) {
log.debug("getting Log instance with id: " + id);
try {
Log instance = (Log) getHibernateTemplate().get(
"yyxtong.hibernate.pojo.Log", id);
return instance;
} catch (RuntimeException re) {
log.error("get failed", re);
throw re;
}
}
/* (non-Javadoc)
* @see yyxtong.hibernate.dao.baseimpl.ILogDAO#findByExample(yyxtong.hibernate.pojo.Log)
*/
public List findByExample(Log instance) {
log.debug("finding Log 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;
}
}
/* (non-Javadoc)
* @see yyxtong.hibernate.dao.baseimpl.ILogDAO#findByProperty(java.lang.String, java.lang.Object)
*/
public List findByProperty(String propertyName, Object value) {
log.debug("finding Log instance with property: " + propertyName
+ ", value: " + value);
try {
String queryString = "from Log as model where model."
+ propertyName + "= ?";
return getHibernateTemplate().find(queryString, value);
} catch (RuntimeException re) {
log.error("find by property name failed", re);
throw re;
}
}
/* (non-Javadoc)
* @see yyxtong.hibernate.dao.baseimpl.ILogDAO#findByPartName(java.lang.Object)
*/
public List findByPartName(Object partName) {
return findByProperty(PART_NAME, partName);
}
/* (non-Javadoc)
* @see yyxtong.hibernate.dao.baseimpl.ILogDAO#findByContrl(java.lang.Object)
*/
public List findByContrl(Object contrl) {
return findByProperty(CONTRL, contrl);
}
/* (non-Javadoc)
* @see yyxtong.hibernate.dao.baseimpl.ILogDAO#findAll()
*/
public List findAll() {
log.debug("finding all Log instances");
try {
String queryString = "from Log";
return getHibernateTemplate().find(queryString);
} catch (RuntimeException re) {
log.error("find all failed", re);
throw re;
}
}
/* (non-Javadoc)
* @see yyxtong.hibernate.dao.baseimpl.ILogDAO#merge(yyxtong.hibernate.pojo.Log)
*/
public Log merge(Log detachedInstance) {
log.debug("merging Log instance");
try {
Log result = (Log) getHibernateTemplate().merge(detachedInstance);
log.debug("merge successful");
return result;
} catch (RuntimeException re) {
log.error("merge failed", re);
throw re;
}
}
/* (non-Javadoc)
* @see yyxtong.hibernate.dao.baseimpl.ILogDAO#attachDirty(yyxtong.hibernate.pojo.Log)
*/
public void attachDirty(Log instance) {
log.debug("attaching dirty Log instance");
try {
getHibernateTemplate().saveOrUpdate(instance);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
/* (non-Javadoc)
* @see yyxtong.hibernate.dao.baseimpl.ILogDAO#attachClean(yyxtong.hibernate.pojo.Log)
*/
public void attachClean(Log instance) {
log.debug("attaching clean Log instance");
try {
getHibernateTemplate().lock(instance, LockMode.NONE);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
public static ILogDAO getFromApplicationContext(ApplicationContext ctx) {
return (ILogDAO) ctx.getBean("LogDAOImpl");
}
public List findlog(FindlogForm ff){
int logid=ff.getLogid();
String empname=ff.getEmpname();
String part_nameid=ff.getPart_nameid();
String begintime=ff.getBegin_time();
String endtime=ff.getEnd_time();
//转化日期
ConvertUtil cu=new ConvertUtil();
Date bd=cu.convertStringToDate(begintime);
Date ed=cu.convertStringToDate(endtime);
System.out.println(bd+"日期");
//得到session
Session session=getHibernateTemplate().getSessionFactory().openSession();
String hql2="select e.id from Emp e where e.name=?";
Query ql=session.createQuery(hql2);
ql.setString(0, empname);
List listemp=ql.list();
Iterator it=listemp.iterator();
Integer empid=0;
while(it.hasNext()){
empid=(Integer) it.next();
System.out.println(empid+"-----daoaaaa--------");
}
System.out.println(logid+"/"+empname+"----号码-----");
StringBuffer sb = new StringBuffer();
sb.append("SELECT ");
sb.append(" log.id,");
sb.append("log.role.id,");
sb.append("log.partName,");
sb.append("log.contrl,");
sb.append("log.time ");
sb.append(" FROM ");
sb.append("Log log ");
sb.append("WHERE ");
if(logid!= 0){
sb.append("log.id=? AND ");
}
if(empname!= null && !"".equals(empname)){
sb.append("log.role.id=? AND ");
}
sb.append(" log.partName LIKE ? AND ");
sb.append("log.time BETWEEN ? AND ? ");
String hql=sb.toString();
System.out.println(hql);
Query q=session.createQuery(hql);
//logid和empid全填
if(logid!=0 && empname!= null && !"".equals(empname)){
q.setInteger(0, logid);
q.setInteger(1, empid);
if(part_nameid != null && !"".equals(part_nameid)){
String t2 = "%"+part_nameid+"%";
q.setString(2, t2);
System.out.println(t2+"/ceshi");
}else{
String t2 ="%";
q.setString(2, t2);
System.out.println(t2+"/ceshi");
}
if(begintime != null && !"".equals(begintime)){
q.setDate(3, bd);
System.out.println(bd+"/ceshi");
}else{
Date t3=ConvertUtil.convertStringToDate("1900-1-1");
q.setDate(3, t3);
System.out.println(t3+"/ceshi");
}
if(endtime != null && !"".equals(endtime)){
q.setDate(4, ed);
System.out.println(ed+"/ceshi");
}else{
Date t4=ConvertUtil.convertStringToDate("2050-1-1");
q.setDate(4, t4);
System.out.println(t4+"/ceshi");
}
}
//logid填和empid不填
if(logid!=0 && (empname ==null||empname.equals(""))){
q.setInteger(0, logid);
if(part_nameid != null && !"".equals(part_nameid)){
String t2 = "%"+part_nameid+"%";
q.setString(1, t2);
System.out.println(t2+"/ceshi");
}else{
String t2 ="%";
q.setString(1, t2);
System.out.println(t2+"/ceshi");
}
if(begintime != null && !"".equals(begintime)){
q.setDate(2, bd);
System.out.println(bd+"/ceshi");
}else{
Date t3=ConvertUtil.convertStringToDate("1900-1-1");
q.setDate(2, t3);
System.out.println(t3+"/ceshi");
}
if(endtime != null && !"".equals(endtime)){
q.setDate(3, ed);
System.out.println(ed+"/ceshi");
}else{
Date t4=ConvertUtil.convertStringToDate("2050-1-1");
q.setDate(3, t4);
System.out.println(t4+"/ceshi");
}
}
System.out.println(logid+"^^^^^^"+empname);
//logid不填和empid填
if(logid==0 && (empname!= null&&!"".equals(empname))){
q.setInteger(0, empid);
if(part_nameid != null && !"".equals(part_nameid)){
String t2 = "%"+part_nameid+"%";
q.setString(1, t2);
System.out.println(t2+"/ceshi");
}else{
String t2 ="%";
q.setString(1, t2);
System.out.println(t2+"/ceshi");
}
if(begintime != null && !"".equals(begintime)){
q.setDate(2, bd);
System.out.println(bd+"/ceshi");
}else{
Date t3=ConvertUtil.convertStringToDate("1900-1-1");
q.setDate(2, t3);
System.out.println(t3+"/ceshi");
}
if(endtime != null && !"".equals(endtime)){
q.setDate(3, ed);
System.out.println(ed+"/ceshi");
}else{
Date t4=ConvertUtil.convertStringToDate("2050-1-1");
q.setDate(3, t4);
System.out.println(t4+"/ceshi");
}
}
System.out.println(logid+"****"+empname);
//logid和empid全不填
if(logid == 0 && (empname==null||"".equals(empname))){
System.out.println("进入全不填");
if(part_nameid != null && !"".equals(part_nameid)){
String t2 = "%"+part_nameid+"%";
q.setString(0, t2);
System.out.println(t2+"/ceshi");
}else{
String t2 ="%";
q.setString(0, t2);
System.out.println(t2+"/ceshi");
}
if(begintime != null && !"".equals(begintime)){
q.setDate(1, bd);
System.out.println(bd+"/ceshi");
}else{
Date t3=ConvertUtil.convertStringToDate("1900-1-1");
q.setDate(1, t3);
System.out.println(t3+"/ceshi");
}
if(endtime != null && !"".equals(endtime)){
q.setDate(2, ed);
System.out.println(ed+"/ceshi");
}else{
Date t4=ConvertUtil.convertStringToDate("2050-1-1");
q.setDate(2, t4);
System.out.println(t4+"/ceshi");
}
}
List l=q.list();
System.out.println(ff.getBegin_time()+"-------dao");
session.close();
return l;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -