clientdao.java
来自「一套自己原先在学校作的CRM,大家指点下」· Java 代码 · 共 349 行
JAVA
349 行
package com.crm.dao;
import java.util.List;
import org.apache.commons.logging.Log;
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 com.crm.pojo.Client;
/**
* Data access object (DAO) for domain model class Client.
*
* @see com.crm.pojo.Client
* @author MyEclipse Persistence Tools
*/
public class ClientDAO extends HibernateDaoSupport {
private static final Log log = LogFactory.getLog(ClientDAO.class);
// property constants
public static final String CLIENT_NAME = "clientName";
public static final String CLIENT_EMPLOYEE_NAME = "clientEmployeeName";
public static final String CLIENT_GRADE = "clientGrade";
public static final String CLIENT_SATISFACTION = "clientSatisfaction";
public static final String CLIENT_CREDIT = "clientCredit";
public static final String CLIENT_ADDRESS = "clientAddress";
public static final String CLIENT_PHON = "clientPhon";
public static final String CLIENT_ZIP = "clientZip";
public static final String CLIENT_FAX = "clientFax";
public static final String CLIENT_NETWORK_ADDRESS = "clientNetworkAddress";
public static final String CLIENT_LOGIN_NUMBER = "clientLoginNumber";
public static final String CLIENT_CORPORATION = "clientCorporation";
public static final String CLIENT_LOGIN_BANKROLL = "clientLoginBankroll";
public static final String CLIENT_YEAR_BANKROLL = "clientYearBankroll";
public static final String CLIENT_OPEN_BANK = "clientOpenBank";
public static final String CLIENT_BANK_NUMBER = "clientBankNumber";
public static final String CLIENT_PLACE_ENROL_NUMBER = "clientPlaceEnrolNumber";
public static final String CLIENT_COUNTRY_ENROL_NUMBER = "clientCountryEnrolNumber";
public static final String CLIENT_AREA = "clientArea";
protected void initDao() {
// do nothing
}
public void save(Client transientInstance) {
log.debug("saving Client instance");
try {
getHibernateTemplate().save(transientInstance);
log.debug("save successful");
} catch (RuntimeException re) {
log.error("save failed", re);
throw re;
}
}
public void delete(Client persistentInstance) {
log.debug("deleting Client instance");
try {
getHibernateTemplate().delete(persistentInstance);
log.debug("delete successful");
} catch (RuntimeException re) {
log.error("delete failed", re);
throw re;
}
}
public Client findById(java.lang.Integer id) {
log.debug("getting Client instance with id: " + id);
try {
Client instance = (Client) getHibernateTemplate().get(
"com.crm.pojo.Client", id);
return instance;
} catch (RuntimeException re) {
log.error("get failed", re);
throw re;
}
}
public List findByExample(Client instance) {
log.debug("finding Client 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 Client instance with property: " + propertyName
+ ", value: " + value);
try {
String queryString = "from Client 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 findByClientName(Object clientName) {
return findByProperty(CLIENT_NAME, clientName);
}
public List findByClientEmployeeName(Object clientEmployeeName) {
return findByProperty(CLIENT_EMPLOYEE_NAME, clientEmployeeName);
}
public List findByClientGrade(Object clientGrade) {
return findByProperty(CLIENT_GRADE, clientGrade);
}
public List findByClientSatisfaction(Object clientSatisfaction) {
return findByProperty(CLIENT_SATISFACTION, clientSatisfaction);
}
public List findByClientCredit(Object clientCredit) {
return findByProperty(CLIENT_CREDIT, clientCredit);
}
public List findByClientAddress(Object clientAddress) {
return findByProperty(CLIENT_ADDRESS, clientAddress);
}
public List findByClientPhon(Object clientPhon) {
return findByProperty(CLIENT_PHON, clientPhon);
}
public List findByClientZip(Object clientZip) {
return findByProperty(CLIENT_ZIP, clientZip);
}
public List findByClientFax(Object clientFax) {
return findByProperty(CLIENT_FAX, clientFax);
}
public List findByClientNetworkAddress(Object clientNetworkAddress) {
return findByProperty(CLIENT_NETWORK_ADDRESS, clientNetworkAddress);
}
public List findByClientLoginNumber(Object clientLoginNumber) {
return findByProperty(CLIENT_LOGIN_NUMBER, clientLoginNumber);
}
public List findByClientCorporation(Object clientCorporation) {
return findByProperty(CLIENT_CORPORATION, clientCorporation);
}
public List findByClientLoginBankroll(Object clientLoginBankroll) {
return findByProperty(CLIENT_LOGIN_BANKROLL, clientLoginBankroll);
}
public List findByClientYearBankroll(Object clientYearBankroll) {
return findByProperty(CLIENT_YEAR_BANKROLL, clientYearBankroll);
}
public List findByClientOpenBank(Object clientOpenBank) {
return findByProperty(CLIENT_OPEN_BANK, clientOpenBank);
}
public List findByClientBankNumber(Object clientBankNumber) {
return findByProperty(CLIENT_BANK_NUMBER, clientBankNumber);
}
public List findByClientPlaceEnrolNumber(Object clientPlaceEnrolNumber) {
return findByProperty(CLIENT_PLACE_ENROL_NUMBER, clientPlaceEnrolNumber);
}
public List findByClientCountryEnrolNumber(Object clientCountryEnrolNumber) {
return findByProperty(CLIENT_COUNTRY_ENROL_NUMBER,
clientCountryEnrolNumber);
}
public List findByClientArea(Object clientArea) {
return findByProperty(CLIENT_AREA, clientArea);
}
public List findAll() {
log.debug("finding all Client instances");
try {
String queryString = "from Client";
return getHibernateTemplate().find(queryString);
} catch (RuntimeException re) {
log.error("find all failed", re);
throw re;
}
}
public Client merge(Client detachedInstance) {
log.debug("merging Client instance");
try {
Client result = (Client) getHibernateTemplate().merge(
detachedInstance);
log.debug("merge successful");
return result;
} catch (RuntimeException re) {
log.error("merge failed", re);
throw re;
}
}
public void attachDirty(Client instance) {
log.debug("attaching dirty Client instance");
try {
getHibernateTemplate().saveOrUpdate(instance);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
public void attachClean(Client instance) {
log.debug("attaching clean Client instance");
try {
getHibernateTemplate().lock(instance, LockMode.NONE);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
public List find(String fangshi,String names, int pageNo, int pageSize) {
String sql = "";
Session s = this.getSessionFactory().openSession();
if (fangshi.equals("1")) {
sql = "select count(c.clientGrade) as num from Client as c " +
"where c.clientGrade ='" +names+"' group by c.clientGrade";
}else if(fangshi.equals("2")){
sql="select count(c.clientSatisfaction) as num from Client as c "+
"where c.clientSatisfaction ='" +names+"' group by c.clientSatisfaction";
}else{
sql="select count(c.clientCredit) as num from Client as c "+
"where c.clientCredit = '" +names+"' group by c.clientCredit";
}
Query query = s.createQuery(sql);
int fri = pageSize * (pageNo - 1);
query.setFirstResult(fri);
query.setMaxResults(pageSize);
List list = query.list();
s.close();
return list;
}
public List findByName(String names) {
String sql ="select c.clientId from Client as c where 1=1 ";
Session s = this.getSessionFactory().openSession();
if(!(names==null || names.equals(""))){
sql+="and c.clientName like '%"+names+"%'";
}
Query query = s.createQuery(sql);
List list = query.list();
s.close();
return list;
}
public List findByClientName(String names) {
String sql ="select c.clientName from Client as c where 1=1 ";
Session s = this.getSessionFactory().openSession();
if(!(names==null || names.equals(""))){
sql+="and c.clientName like '%"+names+"%'";
}
Query query = s.createQuery(sql);
List list = query.list();
s.close();
return list;
}
public List find(Client client,int pageNo,int pageSize){
String sql="from Client c where 1=1 ";
Session s=this.getSessionFactory().openSession();
if(!(client.getClientNum()==null || client.getClientNum().equals(""))){
sql+=" and c.clientNum like '%"+client.getClientNum()+"%'";
}
if(!(client.getClientName()==null || client.getClientName().equals(""))){
sql+=" and c.clientName like '%"+client.getClientName()+"%'";
}
if(!(client.getClientEmployeeName()==null || client.getClientEmployeeName().equals("") )){
sql+=" and c.clientEmployeeName like '%"+client.getClientEmployeeName()+"%'";
}
if(!(client.getClientArea()==null || client.getClientArea().equals("") || client.getClientArea().equals("0"))){
sql+=" and c.clientArea = '"+client.getClientArea()+"'";
}
if(!(client.getClientGrade()==null || client.getClientGrade().equals("") || client.getClientGrade().equals("0"))){
sql+=" and c.clientGrade = '"+client.getClientGrade()+"'";
}
sql+=" order by c.clientId asc";
Query query=s.createQuery(sql);
int fri=pageSize*(pageNo-1);
query.setFirstResult(fri);
query.setMaxResults(pageSize);
List list=query.list();
s.close();
return list;
}
public List findAll(Client client){
String sql="from Client c where 1=1 ";
Session s=this.getSessionFactory().openSession();
if(!(client.getClientNum()==null || client.getClientNum().equals(""))){
sql+=" and c.clientNum like '%"+client.getClientNum()+"%'";
}
if(!(client.getClientName()==null || client.getClientName().equals(""))){
sql+=" and c.clientName like '%"+client.getClientName()+"%'";
}
if(!(client.getClientEmployeeName()==null || client.getClientEmployeeName().equals(""))){
sql+=" and c.clientEmployeeName like '%"+client.getClientEmployeeName()+"%'";
}
if(!(client.getClientArea()==null || client.getClientArea().equals("") || client.getClientArea().equals("0"))){
sql+=" and c.clientArea = '"+client.getClientArea()+"'";
}
if(!(client.getClientGrade()==null || client.getClientGrade().equals("") || client.getClientGrade().equals("0"))){
sql+=" and c.clientGrade = '"+client.getClientGrade()+"'";
}
sql+=" order by c.clientId asc";
Query query=s.createQuery(sql);
List list=query.list();
s.close();
return list;
}
public static ClientDAO getFromApplicationContext(ApplicationContext ctx) {
return (ClientDAO) ctx.getBean("ClientDAO");
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?