📄 daoutility.java
字号:
package com.primeton.eos.fbframe.fbrole.security.impl;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.*;
import javax.servlet.http.HttpServletRequest;
import com.primeton.tp.core.bizservice.EOSParameter;
import com.primeton.tp.core.config.EOSAppConfiguration;
import com.primeton.tp.core.prservice.context.SessionContext;
/**
* @author ZhangXueyong
*
* DAOUtility负责所有数据库的访问 。
*/
public class DAOUtility {
/*
* 外部不能实例化这个类 。
*/
private DAOUtility(){ }
/*
* 取得用户相关的菜单集合 。
*/
public static List getMyMenu(HttpServletRequest request){
//设法取得当前用户的登陆账号
SessionContext rc = (SessionContext)request.getSession().getAttribute(SessionContext.SESSION_SESSION_CONTEXT);
if( rc == null )
return null;
String userKey = rc.getUserID();
if( userKey == null || userKey.equalsIgnoreCase("") )
return null;
//取得当前用户的菜单项
EOSParameter param = new EOSParameter();
param.setAppID(EOSAppConfiguration.getDefaultAppID());
param.setUnitName("fbrole");
param.setUnitId("0");
PreparedStatement pstmt = null;
ResultSet rs = null;
List topMenus = new ArrayList();
HashMap menuTable = new HashMap();
try
{
Connection conn = param.getDBBroker().getConnection();
String sql = "select distinct c.menuLevel, c.displayOrder, c.menuID, c.isLeaf, c.parentsID, c.menuLabel, c.menuAction, c.inputValue, c.inputKey from EOSOperatorRole a, EOSRoleMenu b, EOSMenu c, EOSOperator d where d.userID=? and a.roleID = b.roleID and b.menuID=c.menuID and a.operatorID=d.operatorID order by menuLevel, displayOrder";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, userKey);
rs = pstmt.executeQuery();
//在内存中构造菜单树的数据结构
while(rs.next()){
int level = rs.getInt(1) - 1;
int order = rs.getInt(2);
String menuId = rs.getString(3);
String isLeaf = rs.getString(4);
String parentsID = rs.getString(5);
String label = rs.getString(6);
String action = rs.getString(7);
String image = rs.getString(8);
String target = rs.getString(9);
boolean bLeaf = isLeaf != null && isLeaf.equalsIgnoreCase("Y");
FbMenuItem item = new FbMenuItem();
item.setAction(action);
item.setLeaf(bLeaf);
item.setLevel(level);
item.setName(label);
item.setMenuImage(image);
item.setMenuTarget(target);
item.setParentID(parentsID);
item.setMenuID(menuId);
item.setDisplayOrder(order);
menuTable.put(menuId, item);
if(level == 0){
topMenus.add(item);
} else{
FbMenuItem pItem = (FbMenuItem)menuTable.get(parentsID);
if(pItem != null)
pItem.addChild(item);
}
}
}catch(Exception e){
e.printStackTrace();
} finally {
//释放空间
menuTable = null;
try{
if(rs != null)
rs.close();
if(pstmt != null)
pstmt.close();
param.closeDB();
}catch(Exception e){
e.printStackTrace();
}
}
return topMenus;
}
/*
* 取得用户相关的需要进行验证的“展现逻辑”集合 。
*/
public static Map getMyCheckedPrs(HttpServletRequest request){
return getMyCheckedEOSFunctionsByType(request,"1");
}
/*
* 取得用户相关的需要进行验证的“业务逻辑”集合 。
*/
public static Map getMyCheckedBizs(HttpServletRequest request){
return getMyCheckedEOSFunctionsByType(request,"3");
}
/*
* 取得用户相关的需要进行验证的JSP集合 。
*/
public static Map getMyCheckedJsps(HttpServletRequest request){
return getMyCheckedEOSFunctionsByType(request,"2");
}
public static void getMyCheckedEOSFunctions(HttpServletRequest request, Map prMap, Map jspMap, Map bizMap) {
//设法取得当前用户的登陆账号
SessionContext rc = (SessionContext)request.getSession().getAttribute(SessionContext.SESSION_SESSION_CONTEXT);
if( rc == null )
return;
String userKey = rc.getUserID();
if( userKey == null || userKey.equalsIgnoreCase("") )
return;
EOSParameter param = new EOSParameter();
param.setAppID(EOSAppConfiguration.getDefaultAppID());
param.setUnitName("fbrole");
param.setUnitId("0");
PreparedStatement pstmt = null;
ResultSet rs = null;
try{
Connection conn = param.getDBBroker().getConnection();
String sql = "select distinct f.functionID, f.functionType from EOSOperator o, EOSOperatorRole r, EOSRoleCatalog c, EOSBizCatalogDef d, EOSFunction f where o.userID=? and o.operatorID=r.operatorID and r.roleID=c.roleID and c.catalogID = d.catalogID and d.functionID=f.functionID";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, userKey);
rs = pstmt.executeQuery();
String functionID = null;
String functionType = null;
while( rs.next() ){
functionID = rs.getString(1);
functionType = rs.getString(2);
if (functionType != null) {
if (functionType.equals("1"))
prMap.put(functionID, "1");
if (functionType.equals("2"))
jspMap.put(functionID, "2");
if (functionType.equals("3"))
bizMap.put(functionID, "3");
}
}
}catch(Exception e){
e.printStackTrace();
} finally {
try{
if(rs != null)
rs.close();
if(pstmt != null)
pstmt.close();
param.closeDB();
}catch(Exception e){
e.printStackTrace();
}
}
}
/*
* 根据EOSFunction.functionType和userID取得用户相关的不同类型的需要进行验证的EOSFunction集合 。
*
* @type EOSFunction.functionType的类型 1:展现逻辑 2:JSP页面 3:业务逻辑
*/
private static Map getMyCheckedEOSFunctionsByType(HttpServletRequest request,String type){
//设法取得当前用户的登陆账号
SessionContext rc = (SessionContext)request.getSession().getAttribute(SessionContext.SESSION_SESSION_CONTEXT);
if( rc == null )
return null;
String userKey = rc.getUserID();
if( userKey == null || userKey.equalsIgnoreCase("") )
return null;
EOSParameter param = new EOSParameter();
param.setAppID(EOSAppConfiguration.getDefaultAppID());
param.setUnitName("fbrole");
param.setUnitId("0");
PreparedStatement pstmt = null;
ResultSet rs = null;
Map mybiz = new HashMap();
try{
Connection conn = param.getDBBroker().getConnection();
String sql = "select distinct f.functionID from EOSVOperatorFunction e, EOSFunction f, EOSOperator r where e.functionID = f.functionID and f.functionType = ? and e.operatorID = r.operatorID and r.userID = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, type);
pstmt.setString(2, userKey);
rs = pstmt.executeQuery();
String functionID = null;
while( rs.next() ){
functionID = rs.getString(1);
mybiz.put(functionID,"1");
}
}catch(Exception e){
e.printStackTrace();
} finally {
try{
if(rs != null)
rs.close();
if(pstmt != null)
pstmt.close();
param.closeDB();
}catch(Exception e){
e.printStackTrace();
}
}
return mybiz;
}
/*
* 取得需要进行验证的“展现逻辑”集合 。
*/
public static Map getAllCheckedPrs(){
return getAllCheckedEOSFunctionsByType("1");
}
/*
* 取得需要进行验证的“业务逻辑”集合 。
*/
public static Map getAllCheckedBizs(){
return getAllCheckedEOSFunctionsByType("3");
}
/*
* 取得需要进行验证的JSP集合 。
*/
public static Map getAllCheckedJsps(){
return getAllCheckedEOSFunctionsByType("2");
}
/*
* 根据EOSFunction.functionType取得不同类型的需要进行验证的EOSFunction集合 。
*
* @type EOSFunction.functionType的类型 1:展现逻辑 2:JSP页面 3:业务逻辑
*/
private static Map getAllCheckedEOSFunctionsByType(String type){
EOSParameter param = new EOSParameter();
param.setAppID(EOSAppConfiguration.getDefaultAppID());
param.setUnitName("fbrole");
param.setUnitId("0");
PreparedStatement pstmt = null;
ResultSet rs = null;
Map mybiz = new HashMap();
try{
Connection conn = param.getDBBroker().getConnection();
String sql = "select distinct f.functionID from EOSFunction f where f.functionType = ? and f.isCheck = '1'";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, type);
rs = pstmt.executeQuery();
String functionID = null;
while (rs.next()){
functionID = rs.getString(1);
mybiz.put(functionID,"");
}
}catch(Exception e){
e.printStackTrace();
} finally {
try{
if(rs != null)
rs.close();
if(pstmt != null)
pstmt.close();
param.closeDB();
}catch(Exception e){
e.printStackTrace();
}
}
return mybiz;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -