📄 rolemanager.java
字号:
package com.sure.oa.role;
import com.sure.businessmodel.Page;
import com.sure.businessmodel.UpdateException;
import com.sure.businesslogic.AlreadyExistsException;
import com.sure.businesslogic.NotFoundException;
import com.sure.dataabstraction.DBManager;
import com.sure.dataabstraction.DBPoolException;
import com.sure.util.StringUtils;
import java.sql.SQLException;
import java.sql.Connection;
import java.util.Vector;
import java.util.NoSuchElementException;
import java.io.*;
/**
* <p>Title: OA</p>
* <p>Description: 国办项目</p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: sure</p>
* @author mengzy
* @version 1.0
*/
public class roleManager {
public roleManager() {
}
/**
* 根据roleId获得角色详情
* @param roleId
* @throws SQLException
* @throws DBPoolException
* @throws NotFoundException
*/
public role getRole(int roleId) throws SQLException,DBPoolException, NotFoundException {
Connection cn = DBManager.getConnection();
try {
String where = "Where roleId = " + roleId;
Vector beans = rolePersistent.load(cn, where);
role bean = (role)beans.firstElement();
return bean;
}catch (SQLException sqle) {
throw new NotFoundException();
} finally {
cn.close();
}
}
/**
* 根据roleId获得角色详情
* @param roleId
* @throws SQLException
* @throws DBPoolException
* @throws NotFoundException
*/
public role getRole(String roleId) throws SQLException,
DBPoolException, NotFoundException{
return getRole(Integer.parseInt(roleId));
}
/**
* 显示某个单位下的所有角色(分页形式)
* @param start 开始位置
* @param roleId
* @throws SQLException
* @throws DBPoolException
*/
public Page getRoleList(int start,int unitId) throws SQLException,DBPoolException {
Connection cn = DBManager.getConnection();
try{
String where = "where unitId=" + unitId + " order by roleId";
Page p = rolePersistent.load(cn, start, 10, where);
return p;
}finally {
cn.close();
}
}
/**
* 显示某个单位的所有角色
* @param roleId
* @throws SQLException
* @throws DBPoolException
*/
public Vector getRoleList(int unitId) throws SQLException,DBPoolException {
Connection cn = DBManager.getConnection();
try{
String where = "where unitId=" + unitId + "";
Vector v = rolePersistent.load(cn, where);
return v;
}finally {
cn.close();
}
}
/**
* 保存角色信息
*/
public int saveRole(role d) throws SQLException, DBPoolException, UpdateException, NotFoundException {
Connection cn = DBManager.getConnection();
String roleName = StringUtils.getSQLencode(d.getRoleName());
String where = "Where roleName = '" + roleName + "' and unitId=" +
d.getUnitId() + " and roleId<>" + d.getRoleId();
int intResult = rolePersistent.getCount(cn, where);
if (intResult > 0){
throw new UpdateException("本单位中已经存在" + roleName + "这个角色");
}
int roleId = d.getRoleId().intValue();
int retval = 0;
try{
rolePersistent role = new rolePersistent(d);
if (roleId == 0){
retval = 2;
}else{
role.setRecordExists(true);
retval = 3;
}
role.persist(cn);
}finally {
cn.close();
}
return retval;
}
/**
* 删除角色
*/
public void delRole(int roleId) throws SQLException,DBPoolException, NotFoundException {
Connection cn = DBManager.getConnection();
try {
String where = "Where roleId = " + roleId;
rolePersistent.delete(cn, where);
}catch (SQLException sqle) {
throw new NotFoundException();
} finally {
cn.close();
}
}
/**
* 取得单位角色数目
*/
public int getRoleCount(String unitId) throws SQLException, DBPoolException{
Connection cn = DBManager.getConnection();
try{
String where = "where unitId = " + unitId + "";
return rolePersistent.getCount(cn, where);
}
finally {
cn.close();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -