⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 functiondao.java

📁 Java开发的权限管理的例子
💻 JAVA
字号:
package org.artemis.right.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.artemis.right.model.Permission;
import org.hibernate.Hibernate;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.type.Type;
import org.springframework.orm.hibernate3.HibernateCallback;
import com.gsta.eshore.framework.dao.BaseDao;
import com.gsta.eshore.framework.daoutil.PageSupport;
import com.gsta.eshore.framework.jcf.JCFException;
import com.gsta.eshore.framework.util.StringUtil;
import com.gsta.eshore.framework.daoutil.HqlQuery;

public class FunctionDao extends BaseDao {
	private static final Log logger = LogFactory.getLog(FunctionDao.class);
	private  String findFunctionByRoleId="select f from Role r,Permission p,Function f where r.id=p.id.roleId and f.id=p.id.functionId and r.id = ?";
	private	String findOtherFunctionByRoleId="from Function where id not in (select f.id from Role r,Permission p,Function f where r.id=p.id.roleId and f.id=p.id.functionId and r.id = ?)";
	private	String findOtherFunctionByRoleIdHQL="from Function where id not in (select f.id from Role r,Permission p,Function f where r.id=p.id.roleId and f.id=p.id.functionId and r.id = ?)";
	
	
	public List FindFunctionByRoleId(String roleId)
	{
 		logger.info(StringUtil.convert(findFunctionByRoleId, new String[]{roleId}));
		return find(findFunctionByRoleId, roleId);
	}
	
 	public List FindOtherFunctionByRoleId(String roleId)
	{
 		logger.info(StringUtil.convert(findOtherFunctionByRoleId, new String[]{roleId}));
		return find(findOtherFunctionByRoleId, roleId);
	}
 	
 	public PageSupport FindOtherFunctionByRoleId(final HqlQuery hqlQuery,String roleId) throws JCFException
	{
 		logger.info(StringUtil.convert(findOtherFunctionByRoleIdHQL, new String[]{roleId}));

 		hqlQuery.setQueryString(findOtherFunctionByRoleIdHQL);
 		hqlQuery.setParam(new Object[]{roleId});
 		hqlQuery.setTypes(new Type[]{Hibernate.STRING});
 		return find(hqlQuery, true);
     }
 	 	
 	public void savePermissions(final List permissions) throws Exception{
		getHibernateTemplate().execute(
				new HibernateCallback() {
			    	public Object doInHibernate(Session session) throws HibernateException, SQLException {
			    		Connection con=session.connection();
			    		PreparedStatement pstmt = null;
			     		for(int i=0;i<permissions.size();i++){
			     			Permission p=(Permission)permissions.get(i);
			     	 			pstmt = con.prepareStatement("insert into t_permission (role_id,function_id) values (?,?)");
			     	 			logger.info(StringUtil.convert("insert into t_permission (role_id,function_id) values (?,?)",
			     	 					new String[]{p.getId().getRoleId(),p.getId().getFunctionId()}));
			     	 			pstmt.setString(1, p.getId().getRoleId());
			     	 			pstmt.setString(2, p.getId().getFunctionId());
			     				pstmt.executeUpdate();	
			     		}
						return Boolean.TRUE;
							}		
			          }
				);
 		
 	}
// 	public int DeletePermissionByFunctionId(String functionId){
//			return getHibernateTemplate().bulkUpdate("delete  from Permission where id.functionId = "+functionId);
// 	}
 	
 	public void DeletePermissionByFunctionId(List permissions){
 		logger.info("DeletePermissionByFunctionId with size "+permissions.size());
		 deleteAll(permissions);
	}
 	}

⌨️ 快捷键说明

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