usergroupdao.java

来自「一个关于物流的管理系统」· Java 代码 · 共 98 行

JAVA
98
字号
package com.shunshi.ssh.dao;

import java.util.*;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.shunshi.ssh.entity.*;

public class UserGroupDAO extends HibernateDaoSupport implements IUserGroupDAO {

	public void save(UserGroup userGroup) {
		try {
			getHibernateTemplate().saveOrUpdate(userGroup);
		} catch (RuntimeException re) {
			throw re;
		}
	}

	public void delete(UserGroup userGroup) {
		try {
			getHibernateTemplate().delete(userGroup);
		} catch (RuntimeException re) {
			throw re;
		}
	}

	public UserGroup findById(int id) {
		try {
			UserGroup userGroup = (UserGroup) getHibernateTemplate().get(
					"com.shunshi.ssh.entity.UserGroup", id);
			return userGroup;
		} catch (RuntimeException re) {
			throw re;
		}
	}
	
	public UserGroup findByUserGroupName(String userGroupName) {
		UserGroup userGroup=null;
		try {
			String sql="from UserGroup userGroup where groupName=?";
			List list=getHibernateTemplate().find(sql, userGroupName);
			if(list!=null && list.size()>0){
				 userGroup=(UserGroup)list.get(0);
			}
		} catch (RuntimeException re) {
			throw re;
		}
		return userGroup;
	}


	public Collection findByProperty(String propertyName, Object value) {
		try {
			String queryString = "from UserGroup as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			throw re;
		}
	}

	public Collection findAll() {
		try {
			String queryString = "from UserGroup";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			throw re;
		}
	}

	public void update(UserGroup userGroup) {
		try {
			getHibernateTemplate().saveOrUpdate(userGroup);
		} catch (RuntimeException re) {
			throw re;
		}
	}

	public Collection queryPermissionsById(int id) {
		Collection permissionNames=new HashSet();
		UserGroup userGroup=null;
		try {
			String sql="from UserGroup userGroup where id=?";
			List list=getHibernateTemplate().find(sql, id);
			if(list!=null && list.size()>0){
				 userGroup= (UserGroup)list.get(0);
			}
			Set permissions=userGroup.getPermissions();
			Iterator iter=permissions.iterator();
			while(iter.hasNext()){
				Permission per=(Permission)iter.next();
				permissionNames.add(per.getName());
			}
		} catch (RuntimeException re) {
			throw re;
		}
		return permissionNames;
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?