RoleDAO.java
资源名称:(J2EE)oa.rar [点击查看]
上传用户:lm2018
上传日期:2015-12-12
资源大小:30449k
文件大小:5k
源码类别:
Jsp/Servlet
开发平台:
Java
- package com.oa.module.office.role;
- import java.util.List;
- import org.hibernate.Query;
- import org.hibernate.Session;
- import org.hibernate.SessionFactory;
- import org.springframework.jdbc.core.JdbcTemplate;
- import org.springframework.orm.hibernate3.HibernateTemplate;
- import com.oa.util.XPage;
- public class RoleDAO implements InRoleDAO{
- private SessionFactory sfactory;
- private SessionFactory sessionFactory;
- private JdbcTemplate jdbcTemplate;//JDBC
- private HibernateTemplate ht = null;
- public XPage getRolelist(int currentPage, int count, Trole info) {
- String hql="select a from Trole a where 1=1";
- String path="role.do?method=query&";
- XPage page = new XPage();
- //开始设置xpage
- page.setCurrentPage(currentPage);
- page.setCount(count);
- //动态的构建hql语句和xpage的path
- if(info!=null){
- if(info.getRname()!=null&&!info.getRname().trim().equals("")){
- hql+=" and a.rname like :rname";
- path+="rname="+info.getRname()+"&";
- }
- }
- //设置分页路径
- page.setPath(path);
- Session session = null;
- Query query =null;
- List list = null;
- try {
- session = sfactory.openSession();
- query = session.createQuery(hql);
- // 设置查询参数
- if(info!=null){
- if(info.getRname()!=null&&!info.getRname().trim().equals("")){
- query.setParameter("rname","%"+info.getRname()+"%");
- }
- }
- 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{
- sfactory.close();
- }
- return page;
- }
- public List getFfunction() {
- String hql = "select a from Tfunction a where 1=1 ";
- List list = null;
- Session session = null;
- Query query = null;
- try {
- session = sfactory.openSession();
- query = session.createQuery(hql);
- list = query.list();
- session.flush();
- } catch (Exception e) {
- e.printStackTrace();
- }finally{
- session.close();
- }
- return list;
- }
- public List getSfunction() {
- String hql = "select a from Tfunction a where fpid!=0 ";
- List list = null;
- Session session = null;
- Query query = null;
- try {
- session = sfactory.openSession();
- query = session.createQuery(hql);
- list = query.list();
- session.flush();
- } catch (Exception e) {
- e.printStackTrace();
- }finally{
- session.close();
- }
- return list;
- }
- public boolean addList(Trole info) {
- HibernateTemplate ht = new HibernateTemplate(this.sfactory);
- try {
- ht.save(info);
- } catch (Exception e) {
- return false;
- }
- return true;
- }
- public List getRfList(long rid) {
- String sql = "select * from trole r left join trolefunction " +
- "rf on r.rid=rf.rid left join tfunction f on rf.fid=f.fid where r.rid=" + rid;
- List list = null;
- list = jdbcTemplate.queryForList(sql);
- return list;
- }
- public Trole getRfinfo(long rid) {
- HibernateTemplate ht = new HibernateTemplate(this.sfactory);
- Trole role = null;
- try {
- role = (Trole)ht.get(Trole.class,new Long(rid));
- } catch (Exception e) {
- e.printStackTrace();
- }
- return role;
- }
- public boolean editList(Trole info) {
- HibernateTemplate ht = new HibernateTemplate(this.sfactory);
- try {
- ht.update(info);
- return true;
- } catch (Exception e) {
- return false;
- }
- }
- public SessionFactory getSfactory() {
- return sfactory;
- }
- public void setSfactory(SessionFactory sfactory) {
- this.sfactory = sfactory;
- }
- public JdbcTemplate getJdbcTemplate() {
- return jdbcTemplate;
- }
- public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
- this.jdbcTemplate = jdbcTemplate;
- }
- public List getrole(){
- ht = new HibernateTemplate(this.sfactory);
- String hql="select r from Trole r ";
- return ht.find(hql);
- }
- public SessionFactory getSessionFactory() {
- return sessionFactory;
- }
- public void setSessionFactory(SessionFactory sessionFactory) {
- this.sessionFactory = sessionFactory;
- }
- public boolean getRoleByName(String rname) {
- List list = null;
- String sql = "select * from trole where rname='"+rname+"'";
- list = jdbcTemplate.queryForList(sql);
- if(list.size()<=0){
- return false;
- }else{
- return true;
- }
- }
- public boolean delList(Trole info) {
- HibernateTemplate ht = new HibernateTemplate(this.sfactory);
- try {
- ht.delete(info);
- return true;
- } catch (Exception e) {
- return false;
- }
- }
- public boolean getUserForRid(long rid) {
- List list = null;
- String sql = "select * from tuser u left join tuserrole ur on u.uno = ur.uno where u.uislocked = '0' and ur.rid='"+rid+"'";
- list = jdbcTemplate.queryForList(sql);
- if(list.size()<=0){
- return false;
- }else{
- return true;
- }
- }
- }