EctomereDAO.java
资源名称:(J2EE)oa.rar [点击查看]
上传用户:lm2018
上传日期:2015-12-12
资源大小:30449k
文件大小:5k
源码类别:
Jsp/Servlet
开发平台:
Java
- package com.oa.module.pub.ectomere;
- import java.io.Serializable;
- import java.util.List;
- import org.springframework.jdbc.core.JdbcTemplate;
- import org.hibernate.Query;
- import org.hibernate.HibernateException;
- import org.hibernate.Session;
- import org.hibernate.SessionFactory;
- import org.springframework.orm.hibernate3.HibernateCallback;
- import org.springframework.orm.hibernate3.HibernateTemplate;
- import org.hibernate.Transaction;
- import com.oa.module.pub.ectomere.Ectomere;
- import com.oa.module.pub.ectomere.HibernateSessionFactory;
- import com.oa.module.pub.ectomere.HibernateUtil;
- import com.oa.module.pub.ectomere.XPage;
- import com.oa.module.system.Ttype;
- public class EctomereDAO {
- private SessionFactory sf;
- private HibernateUtil hibernateutil;
- private JdbcTemplate jdbcTemplate;//JDBC
- public JdbcTemplate getJdbcTemplate() {
- return jdbcTemplate;
- }
- public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
- this.jdbcTemplate = jdbcTemplate;
- }
- /*
- select rownum as rnum,a.* ,b.pname,c.uname
- from (texterior a left join tparam b on a.etype=b.pid
- left join tuser c on a.uno=c.uno)
- where 1=1
- */
- public XPage getEctomerelist(int currentPage,int count,Ectomere ect){
- String content="select rownum as rnum,a.* ,b.pname,c.uname ";
- content=content+" from (texterior a left join tparam b on a.etype=b.pid ";
- content=content+" left join tuser c on a.uno=c.uno) ";
- content=content+" where 1=1 ";
- String path="ectomere.do?task=query&";
- String sql ="SELECT * FROM("+content+") m where m.rnum<="+currentPage*count+ " AND m.rnum>"+(currentPage-1)*count;
- XPage page=new XPage();
- //开始设置xpage
- page.setCurrentPage(currentPage);
- page.setCount(count);
- //动态的购建sql语句和xpage的path
- if(ect!=null){
- //单位名称
- if(ect.getEunit()!=null&&!ect.getEunit().trim().equals("")){
- sql+=" and m.eunit like '%"+ect.getEunit()+"%'";
- path+=" eunit="+ect.getEunit()+"&";
- }
- //联系人
- if(ect.getElinkman()!=null&&!ect.getElinkman().trim().equals("")){
- sql+=" and m.elinkman like '%"+ect.getElinkman()+"%'";
- path+=" elinkman="+ect.getElinkman()+"&";
- }
- //企业类别
- if(ect.getEtype()!=null&&!ect.getEtype().trim().equals("")){
- sql+=" and m.etype='"+ect.getEtype()+"'";
- path+=" etype="+ect.getEtype()+"'";
- }
- }
- //设置分页路径
- page.setPath(path);
- List list = null;
- List list1 = null;
- try {
- System.out.println(content);
- list1 = jdbcTemplate.queryForList(content);
- list = jdbcTemplate.queryForList(sql);
- int allcount = list1.size();
- page.setAllCount(allcount);
- page.setList(list);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return page;
- }
- //添加-----------------------------------
- public boolean create(Texterior info){
- HibernateTemplate ht=new HibernateTemplate(this.sf);
- try{
- ht.save(info);
- return true;
- }catch(Exception e){
- e.printStackTrace();
- return false;
- }
- }
- //修改
- public boolean update(Texterior info){
- HibernateTemplate ht=new HibernateTemplate(this.sf);
- try {
- ht.update(info);
- return true;
- } catch (Exception e) {
- e.printStackTrace();
- return false;
- }
- }
- //删除
- public boolean del(long eid){
- HibernateTemplate ht=new HibernateTemplate(this.sf);
- String hql=" from Texterior a where a.eid='"+eid+"'";
- List list=ht.find(hql);
- if(list.size()==0){
- return false;
- }else{
- Texterior text=(Texterior) list.get(0);
- ht.delete(text);
- return true;
- }
- }
- //判断录入人是否是本人
- public boolean checkuser(String user){
- HibernateTemplate ht=new HibernateTemplate(this.sf);
- String hql=" from Texterior a where a.uno='"+user+"'";
- //查到数据
- int count=ht.find(hql).size();
- if(count>0){
- return true;
- }else{
- return false;
- }
- }
- //企业类别
- public List getParam() {
- String hql = " from Tparam a where a.tid=3 ";
- List list = null;
- Session session = null;
- Query query = null;
- try {
- session = sf.openSession();
- query = session.createQuery(hql);
- list = query.list();
- session.flush();
- } catch (Exception e) {
- e.printStackTrace();
- }finally{
- session.close();
- }
- return list;
- }
- //录入人
- public List getUser() {
- String hql = " from Tuser a where 1=1 ";
- List list = null;
- Session session = null;
- Query query = null;
- try {
- session = sf.openSession();
- query = session.createQuery(hql);
- list = query.list();
- session.flush();
- } catch (Exception e) {
- e.printStackTrace();
- }finally{
- session.close();
- }
- return list;
- }
- public Texterior getTexteriorById(Serializable eid) {
- return (Texterior)hibernateutil.get(Texterior.class,eid);
- }
- public SessionFactory getSf() {
- return sf;
- }
- public void setSf(SessionFactory sf) {
- this.sf = sf;
- }
- public HibernateUtil getHibernateutil() {
- return hibernateutil;
- }
- public void setHibernateutil(HibernateUtil hibernateutil) {
- this.hibernateutil = hibernateutil;
- }
- }