MeetRoomDao.java
资源名称:(J2EE)oa.rar [点击查看]
上传用户:lm2018
上传日期:2015-12-12
资源大小:30449k
文件大小:5k
源码类别:
Jsp/Servlet
开发平台:
Java
- package com.oa.module.meet.meetroomdao;
- import java.util.List;
- import javax.sql.DataSource;
- import org.hibernate.Query;
- import org.hibernate.Session;
- import org.hibernate.SessionFactory;
- import org.springframework.jdbc.core.JdbcTemplate;
- import org.springframework.jdbc.datasource.DriverManagerDataSource;
- import org.springframework.orm.hibernate3.HibernateTemplate;
- import com.oa.module.meet.hibernate.Tmeet;
- import com.oa.module.meet.hibernate.Tmeetroom;
- import com.oa.module.pub.ectomere.XPage;
- public class MeetRoomDao implements MeetRoomInterfer {
- private SessionFactory meetroom;
- private DriverManagerDataSource datasource;
- private DataSource ds = null;
- public DriverManagerDataSource getDatasource() {
- return datasource;
- }
- public void setDatasource(DriverManagerDataSource datasource) {
- this.datasource = datasource;
- }
- public SessionFactory getMeetroom() {
- return meetroom;
- }
- public void setMeetroom(SessionFactory meetroom) {
- this.meetroom = meetroom;
- }
- public XPage getItemlist(int currentPage, int count, Tmeetroom info) {
- String hql = "select a from Tmeetroom a where 1=1";
- String path = "/oa/meetroom.do?task=query&";
- XPage page = new XPage();
- // 开始设置xpage
- page.setCurrentPage(currentPage);
- page.setCount(count);
- // 动态的构建hql语句和xpage的pathrstate
- if (info != null) {
- if (info.getRmid() != 0 && info.getRmid()>0) {
- hql += " and a.rmid= :rmid";
- path += " rmid=" + info.getRmid() + "&";
- }
- if (info.getRname() != null && !info.getRname().trim().equals("")) {
- hql += " and a.rname like :rname";
- path += "rname=" + info.getRname() + "&";
- }
- if(info.getRstate()!=-1 && info.getRstate()>-1){
- hql += " and a.rstate= :rstate";
- path += " rstate=" +info.getRstate()+"&";
- }
- }
- // 设置分页路径
- page.setPath(path);
- Session session = null;
- Query query = null;
- List list = null;
- try {
- session = this.meetroom.openSession();
- query = session.createQuery(hql);
- // 设置查询参数
- if (info != null) {
- if (info.getRmid() != 0 && info.getRmid() > 0) {
- query.setParameter("rmid", new Long(info.getRmid()));
- }
- if (info.getRname() != null
- && !info.getRname().trim().equals("")) {
- query.setParameter("rname", "%" + info.getRname() + "%");
- }
- if(info.getRstate()!=-1 && info.getRstate()>-1){
- query.setParameter("rstate",new Long(info.getRstate()));
- }
- }
- // 获取总记录数
- int allcount = query.list().size();
- page.setAllCount(allcount);
- // 得到分页显示数据
- query.setFirstResult((currentPage - 1) * count);
- query.setMaxResults(count);
- list = query.list();
- page.setList(list);
- session.flush();
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- if (session != null) {
- session.close();
- }
- }
- return page;
- }
- public List addrlist() {
- List list = null;
- JdbcTemplate tem = null;
- try {
- tem = new JdbcTemplate(this.ds);
- String sql = "select pid,pname from tparam where tid='4'";
- list = tem.queryForList(sql);
- } catch (Exception e) {
- list = null;
- e.printStackTrace();
- }
- return list;
- }
- public DataSource getDs() {
- return ds;
- }
- public void setDs(DataSource ds) {
- this.ds = ds;
- }
- public boolean great(Tmeetroom room) {
- HibernateTemplate ht = null;
- try {
- ht = new HibernateTemplate(this.meetroom);
- ht.save(room);
- return true;
- } catch (Exception e) {
- e.printStackTrace();
- }
- return false;
- }
- public boolean update(Tmeetroom room) {
- HibernateTemplate ht = null;
- try {
- ht = new HibernateTemplate(this.meetroom);
- ht.update(room);
- return true;
- } catch (Exception e) {
- e.printStackTrace();
- }
- return false;
- }
- public Tmeetroom getlistroom(long rmid) {
- Tmeetroom room = null;
- HibernateTemplate ht = null;
- try {
- ht = new HibernateTemplate(this.meetroom);
- room = (Tmeetroom) ht.get(Tmeetroom.class, new Long(rmid));
- } catch (Exception e) {
- e.printStackTrace();
- }
- return room;
- }
- /**
- * 查找已存在的会议室名
- */
- public boolean selectname(String name) {
- boolean flag=false;
- List list=null;
- JdbcTemplate template=null;
- String sql=null;
- try {
- template=new JdbcTemplate(this.ds);
- sql="select * from tmeetroom t where t.rname='"+name+"'";
- list =template.queryForList(sql);
- if(list.size()>0){
- flag=true;
- }
- } catch (Exception e) {
- list=null;
- e.printStackTrace();
- }
- return flag;
- }
- public boolean updatestats(Tmeetroom room) {
- Session session = null;
- String hql = null;
- Query query = null;
- try {
- session = this.meetroom.openSession();
- hql = "update Tmeetroom set rstate='2' where rmid="+room.getRmid();
- query = session.createQuery(hql);
- query.executeUpdate();
- session.flush();
- return true;
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- session.close();
- }
- return false;
- }
- public boolean updatestats2(Tmeetroom room) {
- System.out.println(room.getRmid());
- Session session = null;
- String hql = null;
- Query query = null;
- try {
- session = this.meetroom.openSession();
- hql = "update Tmeetroom set rstate='0' where rmid="+room.getRmid();
- query = session.createQuery(hql);
- query.executeUpdate();
- return true;
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- session.close();
- }
- return false;
- }
- }