📄 groupinsertbean.java
字号:
/**
* @(#)GroupInsertBean.java 2.0 2005/04/29
* <p>copyright: Copyright 东软 国际合作事业部版权所有</p>
* <p>company: neusoft</p>
* <p>time: 2005.04.29</p>
*/
package qujl.bean;
import java.io.Serializable;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import javax.naming.NamingException;
import javax.servlet.http.HttpServletRequest;
import javax.sql.DataSource;
import qujl.bean.DBConnectionBean;
import qujl.bean.SQLCommandBean;
import qujl.form.CommonGroupForm;
import qujl.LogWriter;
import zhangchunliang.model.AppMode;
/**
* 处理添加组的Bean.
*
* @author 曲金龙 qujl@neusoft.com
* @version 2.0, 2005/04/29
*/
public class GroupInsertBean implements Serializable {
/** 权限组的信息 */
private CommonGroupForm commonGroupForm;
/** 连接数据库的Bean */
private DBConnectionBean dbConnectionBean;
/** 执行SQL语句的Bean */
private SQLCommandBean sqlCommandBean;
/** 权限组是否已存在 */
private boolean existence;
/** 权限组是否添加成功 */
private boolean insert;
/**
* 权限组是否已存在的getter
*
* @return 权限组是否已存在
*/
public boolean isExistence() {
return this.existence;
}
/**
* 权限组是否已添加的getter
*
* @return 权限组是否已添加
*/
public boolean isInsert() {
return this.insert;
}
/**
* 权限组的信息的setter
*
* @param commonGroupForm 添加权限组的信息
*/
public void setCommonGroupForm(CommonGroupForm commonGroupForm) {
this.commonGroupForm = commonGroupForm;
}
/**
* 执行SQL语句的Bean的setter
*
* @throws SQLException
*/
private void setSqlCommandBean() throws SQLException {
/** 从连接池中取得一个连接 */
DataSource dataSource = this.dbConnectionBean.getDataSource();
/** 设置Connection */
this.sqlCommandBean.setConnection(dataSource.getConnection());
}
/**
* GroupInsertBean的构造方法
*
* @throws NamingException
* @throws SQLException
*/
public GroupInsertBean() throws NamingException, SQLException {
/** dbConnectionBean实例化 */
this.dbConnectionBean = new DBConnectionBean();
/** SQLCommandBean实例化 */
this.sqlCommandBean = new SQLCommandBean();
/** 设置sqlCommandBean属性 */
this.setSqlCommandBean();
}
/**
* 调用executeGroupInsertSQL(HttpServletRequest request)方法添加权限组
*
* @param request
* @throws SQLException
*/
public void executeGroupInsertSQL(HttpServletRequest request)
throws SQLException {
AppMode.registerUser();
/** SQL语句字符串缓冲 */
StringBuffer sqlStrBuffer;
/** SQL语句字符串 */
String sqlStr;
/** Values实例化 */
List values = new ArrayList();
try {
/** 设置SqlValues 查询指定权限组*/
this.sqlCommandBean
.setSqlValue("SELECT * FROM privgroup WHERE groupno=?");
/** 设置Values */
values.add(this.commonGroupForm.getGroupNo());
this.sqlCommandBean.setValues(values);
/** 判断权限组号是否已存在 */
if(this.sqlCommandBean.executeQuery().getRowCount() > 0) {
this.existence = true;
} else {
this.existence = false;
/** SQL语句字符串缓冲实例化, 添加权限组SQL语句 */
sqlStrBuffer = new StringBuffer(200);
sqlStrBuffer.append("INSERT INTO privgroup(groupno,groupname")
.append(",privselect,privadd,privdelete,")
.append("privupdate,insert_date,update_date,")
.append("insert_user_id,update_user_id) ")
.append("VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
/** SQL语句字符串实例化 */
sqlStr = sqlStrBuffer.toString();
/** 设置SqlValues 添加指定权限组*/
this.sqlCommandBean.setSqlValue(sqlStr);
/** 设置Values */
values.clear();
values.add(this.commonGroupForm.getGroupNo());
values.add(this.commonGroupForm.getGroupName());
/** 设置权限 */
String select = "N";
String add = "N";
String delete = "N";
String update = "N";
for(int i = 0; i < commonGroupForm.getPrivilege().length;
i++) {
if(this.commonGroupForm.
getPrivilege()[i].equals("select"))
select = "Y";
if(this.commonGroupForm.
getPrivilege()[i].equals("add"))
add = "Y";
if(this.commonGroupForm.
getPrivilege()[i].equals("delete"))
delete = "Y";
if(this.commonGroupForm.
getPrivilege()[i].equals("update"))
update="Y";
}
values.add(select);
values.add(add);
values.add(delete);
values.add(update);
values.add(this.commonGroupForm.getDate());
values.add(this.commonGroupForm.getDate());
values.add((String)request.getSession().getAttribute("sid"));
values.add((String)request.getSession().getAttribute("sid"));
sqlCommandBean.setValues(values);
if(this.sqlCommandBean.executeUpdate() == 1) {
this.insert = true;
} else {
this.insert = false;
}
}
} catch(SQLException e) {
this.insert = false;
/** 记录用户错误日志 */
LogWriter.writeError(request, this.getClass().getName()
+ "." + "executeGroupInsertSQL(HttpServletRequest request)"
, e.toString());
} finally {
AppMode.loginoutUser();
/** 释放Connection */
this.sqlCommandBean.releaseConn();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -