?? serviceorderdaoimpl.java
字號:
package com.yuanchung.sales.dao.service.impl;
import java.sql.SQLException;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.HibernateException;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.context.ApplicationContext;
import org.springframework.dao.DataAccessException;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.yuanchung.sales.dao.service.ServiceOrderDAO;
import com.yuanchung.sales.model.customer.Customer;
import com.yuanchung.sales.model.customer.CustomerContact;
import com.yuanchung.sales.model.service.Category;
import com.yuanchung.sales.model.service.ProcessCource;
import com.yuanchung.sales.model.service.ServiceOrder;
import com.yuanchung.sales.model.service.ServiceOrderFile;
import com.yuanchung.sales.model.user.User;
import com.yuanchung.sales.model.userDefined.UserDefined;
import com.yuanchung.sales.model.userDefined.UserField;
import com.yuanchung.sales.model.userDefined.UserFilter;
import com.yuanchung.sales.util.Constants;
import com.yuanchung.sales.util.Page;
import com.yuanchung.sales.util.StringTool;
/**
* A data access object (DAO) providing persistence and search support for
* ServiceOrder 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 com.yuanchung.sales.hibernate.ServiceOrder
* @author MyEclipse Persistence Tools
*/
public class ServiceOrderDAOImpl extends HibernateDaoSupport implements
ServiceOrderDAO {
private static final Log log = LogFactory.getLog(ServiceOrderDAOImpl.class);
// property constants
public static final String SERIAL_NUM = "serialNum";
public static final String NAME = "name";
public static final String FLAG = "flag";
public static final String CONTACT_NAME = "contactName";
public static final String TITLE = "title";
public static final String DESCRIBE = "describe";
public static final String SOURCE = "source";
public static final String MONEY = "money";
public static final String OTHER_MONEY = "otherMoney";
public static final String CAPTION = "caption";
public static final String BEFIRST = "befirst";
public static final String REMARKS = "remarks";
public static final String PROCESS_COURCE = "processCource";
public static final String STATE = "state";
public static final String SATISFACTION = "satisfaction";
public static final String PHONE = "phone";
public static final String EMAIL = "email";
public static final String ADDRESS = "address";
public static final String COMPANY_NAME = "companyName";
public static final String CONTACT_PHONE = "contactPhone";
public static final String CONTACT_EMAIL = "contactEmail";
public static final String CONTACT_ADDRESS = "contactAddress";
public static final String REASON = "reason";
protected void initDao() {
// do nothing
}
public void save(ServiceOrder transientInstance) {
log.debug("saving ServiceOrder instance");
try {
getHibernateTemplate().save(transientInstance);
log.debug("save successful");
} catch (RuntimeException re) {
log.error("save failed", re);
throw re;
}
}
public void delete(ServiceOrder persistentInstance) {
log.debug("deleting ServiceOrder instance");
try {
getHibernateTemplate().delete(persistentInstance);
log.debug("delete successful");
} catch (RuntimeException re) {
log.error("delete failed", re);
throw re;
}
}
public ServiceOrder findById(java.lang.Integer id) {
log.debug("getting ServiceOrder instance with id: " + id);
try {
ServiceOrder instance = (ServiceOrder) getHibernateTemplate().get(
"com.yuanchung.sales.model.service.ServiceOrder", id);
return instance;
} catch (RuntimeException re) {
log.error("get failed", re);
throw re;
}
}
public List findByExample(ServiceOrder instance) {
log.debug("finding ServiceOrder 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 ServiceOrder instance with property: "
+ propertyName + ", value: " + value);
try {
String queryString = "from ServiceOrder as model where model."
+ propertyName + "= ?";
return getHibernateTemplate().find(queryString, value);
} catch (RuntimeException re) {
log.error("find by property name failed", re);
throw re;
}
}
public List findBySerialNum(Object serialNum) {
return findByProperty(SERIAL_NUM, serialNum);
}
public List findByName(Object name) {
return findByProperty(NAME, name);
}
public List findByFlag(Object flag) {
return findByProperty(FLAG, flag);
}
public List findByContactName(Object contactName) {
return findByProperty(CONTACT_NAME, contactName);
}
public List findByTitle(Object title) {
return findByProperty(TITLE, title);
}
public List findByDescribe(Object describe) {
return findByProperty(DESCRIBE, describe);
}
public List findBySource(Object source) {
return findByProperty(SOURCE, source);
}
public List findByMoney(Object money) {
return findByProperty(MONEY, money);
}
public List findByOtherMoney(Object otherMoney) {
return findByProperty(OTHER_MONEY, otherMoney);
}
public List findByCaption(Object caption) {
return findByProperty(CAPTION, caption);
}
public List findByBefirst(Object befirst) {
return findByProperty(BEFIRST, befirst);
}
public List findByRemarks(Object remarks) {
return findByProperty(REMARKS, remarks);
}
public List findByProcessCource(Object processCource) {
return findByProperty(PROCESS_COURCE, processCource);
}
public List findByState(Object state) {
return findByProperty(STATE, state);
}
public List findBySatisfaction(Object satisfaction) {
return findByProperty(SATISFACTION, satisfaction);
}
public List findByPhone(Object phone) {
return findByProperty(PHONE, phone);
}
public List findByEmail(Object email) {
return findByProperty(EMAIL, email);
}
public List findByAddress(Object address) {
return findByProperty(ADDRESS, address);
}
public List findByCompanyName(Object companyName) {
return findByProperty(COMPANY_NAME, companyName);
}
public List findByContactPhone(Object contactPhone) {
return findByProperty(CONTACT_PHONE, contactPhone);
}
public List findByContactEmail(Object contactEmail) {
return findByProperty(CONTACT_EMAIL, contactEmail);
}
public List findByContactAddress(Object contactAddress) {
return findByProperty(CONTACT_ADDRESS, contactAddress);
}
public List findByReason(Object reason) {
return findByProperty(REASON, reason);
}
public List findAll() {
log.debug("finding all ServiceOrder instances");
try {
String queryString = "from ServiceOrder";
return getHibernateTemplate().find(queryString);
} catch (RuntimeException re) {
log.error("find all failed", re);
throw re;
}
}
public ServiceOrder merge(ServiceOrder detachedInstance) {
log.debug("merging ServiceOrder instance");
try {
ServiceOrder result = (ServiceOrder) getHibernateTemplate().merge(
detachedInstance);
log.debug("merge successful");
return result;
} catch (RuntimeException re) {
log.error("merge failed", re);
throw re;
}
}
public void attachDirty(ServiceOrder instance) {
log.debug("attaching dirty ServiceOrder instance");
try {
getHibernateTemplate().saveOrUpdate(instance);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
public void attachClean(ServiceOrder instance) {
log.debug("attaching clean ServiceOrder instance");
try {
getHibernateTemplate().lock(instance, LockMode.NONE);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
public static ServiceOrderDAOImpl getFromApplicationContext(
ApplicationContext ctx) {
return (ServiceOrderDAOImpl) ctx.getBean("ServiceOrderDAO");
}
// 取得最大ID的服務(wù)單
public ServiceOrder getServiceOrderByMaxId() {
ServiceOrder serviceOrder = null;
try {
String queryString1 = "from ServiceOrder so";
String queryString2 = "from ServiceOrder so where so.id = (select max(id) from ServiceOrder where 1=1)";
List<ServiceOrder> solist1 = super.getSession().createQuery(
queryString1).list();
if (solist1.size()>0) {
List<ServiceOrder> solist2 = super.getSession().createQuery(
queryString2).list();
serviceOrder = solist2.get(0);
}
} catch (RuntimeException re) {
log.error("find by property name failed", re);
throw re;
}
return serviceOrder;
}
// 通過狀態(tài)和顯示條數(shù)取得服務(wù)單
public List<ServiceOrder> getServiceOrder(int userId,String userIds, Set<UserFilter> userFilterSet,
String path, int currentPage, int rowsPerPage) {
List<ServiceOrder> serviceOrderList = null;
StringBuffer hql = new StringBuffer(
"from ServiceOrder as so where 1=1 and (so.engineer.id in ("
+ userIds + ") or so.engineer.id = null or so.createrId = "+userId+")");
this.copyFilter(hql, userFilterSet);
hql.append(" order By so.createTime");
logger.debug("打印hql語句:" + hql);
try {
Query query = super.getSession().createQuery(hql.toString());
query.setFirstResult((currentPage - 1) * rowsPerPage);
query.setMaxResults(rowsPerPage);
serviceOrderList = query.list();
} catch (RuntimeException re) {
log.error("find by property name failed", re);
throw re;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -