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

📄 userright.java

📁 java系统通用框架 很实用的东东 一般人都看的懂,
💻 JAVA
字号:
package com.corp.bisc.ebiz.member;

import com.corp.bisc.ebiz.base.*;
import com.corp.bisc.ebiz.exception.*;
import com.corp.bisc.ebiz.security.*;
import java.sql.*;
import java.io.PrintStream;
/**
 * 此处插入类型描述。
 * 创建日期:(2002-5-23 17:27:22)
 * @author:PangWei
 */
public class UserRight implements WebPrincipal,java.io.Serializable {
	protected long id;
	protected String name;
	protected String description;
	protected int isFolder= 0;//默认0,不是组
/**
 * UserRight 构造子注解。
 */
public UserRight() {
	super();
}
   /**
	* 将本权限组的定义加入数据库
	*/
   public void addToDB(Connection conn) throws SQLException
   {
	  try{

		System.out.println("UserRight- addToDB");

		//更新S_PRINCIPAL
	  	PreparedStatement preparestatement = conn.prepareStatement("insert into S_PRINCIPAL (FuncID, Description, isFolder, Name) values(?,?,?,?)");


	  	long id=0;
	  	//id = KeyContainer.getOracleSequence(conn,"S_PRINCIPAL");
	  	id = KeyContainer.getNewSequence(conn,"S_PRINCIPAL",1);
	  	System.out.println("UserRight- addToDB-id="+id);

	  	setId(id);
	  	preparestatement.setLong(1, id);
	  	preparestatement.setString(2,this.getDescription());
	  	preparestatement.setInt(3,this.getFolder());
	  	preparestatement.setString(4, this.getName());

	  	int result=preparestatement.executeUpdate();
	  	preparestatement.close();

	  	System.out.println("USER Right ---addToDB(conn) result="+result);

	  }catch(SQLException exp){

		System.out.println("SQLException="+exp);
	    exp.printStackTrace(System.out);
      	throw exp;
	  }

   }
/**
	* 将本权限组从数据库中删除
	*/
   public void deleteFromDB(Connection conn) throws SQLException
   {
	  long nId = id;

	   //先删除原有的权限组中包含的子权限
	  PreparedStatement ps = conn.prepareStatement("delete from S_PRINCIPALGROUP where FuncId = ? or subfunc = ?");
	  ps.setLong(1, nId);
	  ps.setLong(2, nId);
	  ps.executeUpdate();
	  ps.close();

	  //删除权限组的定义
	  ps = conn.prepareStatement("delete from S_PRINCIPAL where funcid=?");
	  ps.setLong(1, nId);
	  ps.executeUpdate();


	  //用户权限中的子权限删除
	  ps = conn.prepareStatement("delete from S_USERPRINCIPAL WHERE FUNCID = ?");
	  ps.setLong(1, nId);
	  ps.executeUpdate();

	  ps.close();

   }
/**
 * 显示权限信息。
 * 创建日期:(2002-9-14 15:53:16)
 * @param ps java.io.PrintStream
 */
public void dump(PrintStream ps) {
	ps.println("UserRight--->name: " + name);
	ps.println("UserRight--->id: " + id);
	ps.println("UserRight--->name: " + isFolder);
	ps.println("UserRight--->name: " + description);
}
/**
 * 此处插入方法描述。
 * 创建日期:(2002-8-8 19:16:08)
 */
 //蔡楚煌,0808
public String fromRequest(RequestContext context,Connection conn,int type) throws Exception{


	System.out.println("USER Right---fromRequest");

	setFolder(UserRightManager.SCOPE_UNIT);
	setDescription((String)context.getParameter("description"));
	setName((String) context.getParameter("name"));

	System.out.println("USER Right---description="+description);
	System.out.println("USER Right---name="+name);

	if(type == 0)
		addToDB(conn);
	else
		updateDB(conn);

	return "";

}
/**
 * getDescription 方法注解。
 */
public String getDescription() {
	return description;
}
/**
 * getFolder 方法注解。
 */
public int getFolder() {
	return isFolder;
}
/**
 * getName 方法注解。
 */
public String getId() {
	String strID = new Long(id).toString();
	return strID;
}
/**
 * getName 方法注解。
 */
public String getName() {
	return name;
}
/**
 * hasRight 方法注解。
 */
public boolean hasRight(long rightID) {
	return (id == rightID);
}
/**
 * hasRight 方法注解。
 */
public boolean hasRight(String rightName) {
	return (name.equalsIgnoreCase(rightName));
}
/**
 * 此处插入方法描述。
 * 创建日期:(2002-7-16 15:00:36)
 * @param args java.lang.String[]
 */
public static void main(String[] args) {

	try	{
		//oracle use
		Class.forName("oracle.jdbc.driver.OracleDriver");
		Connection conn = DriverManager.getConnection("jdbc:oracle:oci8:@portaldb", "sseuser", "ibmsse");

		UserRight ur = new UserRight();
		ur.setId(23);
		ur.setFolder(0);
		ur.setName("测试修改");
		ur.setDescription("description");
		//ur.updateDB(conn);
		//ur.addToDB(conn);
		ur.deleteFromDB(conn);
		int a = 0;
	}catch(Exception e){
		System.out.println(e);
	}
}
/**
 * getDescription 方法注解。
 */
public void setDescription(String des) {
	description = des;
}
/**
 * getName 方法注解。
 */
public void setFolder(int isfolder) {
	isFolder = isfolder;
}
/**
 * getName 方法注解。
 */
public void setId(long ID) {
	id = ID;
}
/**
 * getName 方法注解。
 */
public void setName(String str) {
	name = str;
}
/**
 * 显示权限信息。
 * 创建日期:(2002-9-14 15:53:16)
 * @param ps java.io.PrintStream
 */
public String toString() {
	return name + id +isFolder + description;
}
 /**
	* 更新本权限组在数据库中的定义
	*/
   public void updateDB(Connection conn) throws SQLException
   {
	  long nId = id;

	  //最后更新权限组定义
	  PreparedStatement ps = conn.prepareStatement("update S_PRINCIPAL set Description=?, name=?,isFolder=? where funcid=?");
	  ps.setString(1, this.getDescription());
	  ps.setString(2, this.getName());
	  ps.setInt(3, this.getFolder());
	  ps.setLong(4, nId);
	  ps.executeUpdate();
	  ps.close();
	}
}

⌨️ 快捷键说明

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