MeetInfoDao.java
资源名称:(J2EE)oa.rar [点击查看]
上传用户:lm2018
上传日期:2015-12-12
资源大小:30449k
文件大小:5k
源码类别:
Jsp/Servlet
开发平台:
Java
- package com.oa.module.meet.meetinfodao;
- import java.util.List;
- import java.util.Map;
- 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.Tmeetinfo;
- import com.oa.module.pub.ectomere.XPage;
- public class MeetInfoDao implements MeetInfoInterfer {
- private SessionFactory meetinfo;
- private DataSource ds;
- private DriverManagerDataSource datasource;
- public DriverManagerDataSource getDatasource() {
- return datasource;
- }
- public void setDatasource(DriverManagerDataSource datasource) {
- this.datasource = datasource;
- }
- public SessionFactory getMeetinfo() {
- return meetinfo;
- }
- public void setMeetinfo(SessionFactory meetinfo) {
- this.meetinfo = meetinfo;
- }
- public DataSource getDs() {
- return ds;
- }
- public void setDs(DataSource ds) {
- this.ds = ds;
- }
- public XPage getItemlist(int currentPage, int count, Tmeetinfo info) {
- String hql = "select a from Tmeetinfo a where 1=1";
- String path = "/oa/meetinfo.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() + "&";
- }
- }
- // 设置分页路径
- page.setPath(path);
- Session session = null;
- Query query = null;
- List list = null;
- try {
- session = this.meetinfo.openSession();
- query = session.createQuery(hql);
- // 设置查询参数
- if (info != null) {
- if (info.getRmid() != 0 && info.getRmid() > 0) {
- query.setParameter("rmid", new Long(info.getRmid()));
- }
- }
- // 获取总记录数
- 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 selectbyid(String miid) {
- List detail = null;
- JdbcTemplate template = null;
- String sql = null;
- try {
- template = new JdbcTemplate(this.ds);
- sql="select t.*,tm.rname from tmeetinfo t,tmeetroom tm " +
- "where t.rmid=tm.rmid and miid="+miid;
- detail = template.queryForList(sql);
- } catch (Exception e) {
- detail = null;
- e.printStackTrace();
- }
- return detail;
- }
- public List listbyid(String miid) {
- List list = null;
- JdbcTemplate template = null;
- String sql = null;
- try {
- template = new JdbcTemplate(this.ds);
- sql = "select t.*,tm.rname from tmeet t,tmeetroom tm "
- + "where t.rmid=tm.rmid and t.mid=" + miid;
- list = template.queryForList(sql);
- } catch (Exception e) {
- list = null;
- e.printStackTrace();
- }
- return list;
- }
- public Map addmeet(String user) {
- Map map = null;
- List list = null;
- JdbcTemplate template = null;
- String sql = null;
- try {
- template = new JdbcTemplate(this.ds);
- sql = "select tu.uno,tu.uname from tuser tu where tu.uno="
- + user;
- list = template.queryForList(sql);
- if(list.size()>0){
- map = (Map) list.get(0);
- }else{
- map=null;
- }
- } catch (Exception e) {
- list = null;
- e.printStackTrace();
- }
- return map;
- }
- public List userlist() {
- List list = null;
- JdbcTemplate template = null;
- String sql = null;
- try {
- template = new JdbcTemplate(this.ds);
- sql = "select uno,uname from tuser where uislocked='0'";
- list = template.queryForList(sql);
- } catch (Exception e) {
- list = null;
- e.printStackTrace();
- }
- return list;
- }
- public List allroom() {
- List roomlist = null;
- JdbcTemplate template = null;
- String sql = null;
- try {
- template = new JdbcTemplate(this.ds);
- sql="select t.rmid,t.rname from tmeetroom t ";
- roomlist = template.queryForList(sql);
- } catch (Exception e) {
- roomlist = null;
- e.printStackTrace();
- }
- return roomlist;
- }
- public Tmeetinfo getItemById(long miid) {
- Tmeetinfo info = null;
- HibernateTemplate ht = null;
- try {
- ht = new HibernateTemplate(this.meetinfo);
- info = (Tmeetinfo) ht.get(Tmeetinfo.class, new Long(miid));
- } catch (Exception e) {
- e.printStackTrace();
- }
- return info;
- }
- public boolean update(Tmeetinfo info) {
- HibernateTemplate template=null;
- try {
- template=new HibernateTemplate(meetinfo);
- template.update(info);
- return true;
- } catch (Exception e) {
- e.printStackTrace();
- }
- return false;
- }
- public List listbyid(long miid) {
- List list = null;
- JdbcTemplate template = null;
- String sql = null;
- try {
- template = new JdbcTemplate(this.ds);
- sql = "select t.*,tm.rname from tmeet t,tmeetroom tm "
- + "where t.rmid=tm.rmid and t.mid=" + miid;
- list = template.queryForList(sql);
- } catch (Exception e) {
- list = null;
- e.printStackTrace();
- }
- return list;
- }
- }