📄 clieatdao.java
字号:
/*
* Created on 2006-6-23
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package com.funddeal.model.dao.client;
import java.util.List;
import com.funddeal.base.PoolDAO;
import com.funddeal.model.pojo.client.Client;
import net.sf.hibernate.HibernateException;
import net.sf.hibernate.Query;
import net.sf.hibernate.Session;
import net.sf.hibernate.SessionFactory;
import net.sf.hibernate.Transaction;
import net.sf.hibernate.cfg.Configuration;
/**
* @author Administrator
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class ClieatDAO extends PoolDAO {
/* Add Client 添加用户 */
public String addClieat(Client clieat) throws HibernateException{
Configuration cfg=new Configuration().configure();
SessionFactory sessionFactory=cfg.buildSessionFactory();
Session session=sessionFactory.openSession();
String id=(String)session.save(clieat);
Transaction tx=session.beginTransaction();
tx.commit();
session.close();
return id;
}
/* Exist Client */
public boolean existClient(Client client) throws HibernateException{
Configuration cfg=new Configuration().configure();
SessionFactory sessionFactory=cfg.buildSessionFactory();
Session session=sessionFactory.openSession();
Query query=session.createQuery("from Client clt where clt.clientNo='"+ client.getClientNo() +"'");
List list=query.list();
if(list.size()>0)
return true;
else
return false;
}
public Session ell() throws HibernateException{
Configuration cfg=new Configuration().configure();
SessionFactory sessionFactory=cfg.buildSessionFactory();
Session session=sessionFactory.openSession();
return session;
}
/*查一个用户*/
public Client queryClient(String tr,String client_no) throws HibernateException{
Session session=this.ell();
String str="";
if(tr.equals("1"))
str="from Client clt where clt.clientNo='"+ client_no +"'";
else
str="from Client clt where clt.clientName='"+ client_no +"'";
Query query=session.createQuery(str);
List list=query.list();
if(list.size()>0){
return (Client)list.get(0);
}
else
return null;
}
/*查全部用户*/
public List queryClient() throws HibernateException{
Session session=this.ell();
Query query=session.createQuery("from Client");
List list=query.list();
if(list.size()>0){
return list;
}
else
return null;
}
/*修改用户*/
public boolean UpdateClient(Client client) throws HibernateException{
Session session=this.ell();
Transaction tx=session.beginTransaction();
if(this.existClient(client)){
session.update(client);
tx.commit();
session.close();
return true;
}
else
return false;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -