📄 dbboardfactory.java
字号:
pstm.setString(9, board.getBoaMaster());
pstm.setInt(10, board.getBoaState());
pstm.setString(11, board.getBoaPasswd());
pstm.setString(12, timer.getNowDate());
pstm.executeUpdate();
logger.info("插入模板数据成功");
isSuccess = true;
}
catch (Exception ex) {
logger.info("插入数据发生错误 :" + ex.getMessage());
}
finally {
try {
pstm.close();
}
catch (Exception ex) {
logger.error("关闭 pstm 失败 error : " + ex.getMessage());
}
try {
conn.close();
}
catch (Exception ex) {
logger.error("关闭数据库连接失败 error : " + ex.getMessage());
}
}
return isSuccess;
}
/**
* 子节点的操作
*/
public void setChildId(int boaParId, int boaDepth) {
logger.info("boaParId = " + boaParId);
logger.info(String.valueOf(boaParId != 0));
if (boaParId != 0) {
if (boaDepth > 0) {
for (int i = 1; i <= boaDepth; i++) {
upChildId(boaParId);
logger.info("第二次更新... OK");
boaParId = getParId(boaParId);
}
}
else {
upChildId(boaParId);
}
}
else {
logger.info("第一次更新... OK");
upChildId(boaParId);
}
/*int boaId = boaParId;
//当子类ID不为O时检索其上个节点
if(boaId != 0){
logger.info("开始......");
int parentId = getParId(boaId);
logger.info("该父节点的值为 : " + parentId);
if (parentId != 0) { //其还有上一个节点
do {
boaId = parentId;
if (parentId != 0) {
upChildId(boaId);
}
}
while (parentId == 0);
}else{
upChildId(boaId);
}
}*/
}
/**
* 删除模板信息
*/
public boolean delBoard(int boaId) {
//boaId为真实的boaId
boolean isSuccess = false;
Connection conn = DBConnectionManager.getInstance().getConnection(
);
PreparedStatement pstm = null;
ResultSet rs = null;
try {
/**
* 取得该模板ID对应的子节点,如有子节点就不能删除,没有就删除。
*/
if (!getChildId(boaId)) {
//如果没有节点,就execute删除
pstm = conn.prepareStatement(DELETE_BOARD);
pstm.setInt(1, boaId);
pstm.executeUpdate();
isSuccess = true;
}
logger.info("成功删除模板....");
}
catch (Exception ex) {
logger.info("删除模板信息错误 : " + ex.getMessage());
}
finally {
try {
pstm.close();
}
catch (Exception ex) {
logger.error("关闭 pstm 失败 error : " + ex.getMessage());
}
try {
conn.close();
}
catch (Exception ex) {
logger.error("关闭数据库连接失败 error : " + ex.getMessage());
}
}
return isSuccess;
}
/**
* 管理用户数组
* @param boaId int
* @return ArrayList
*/
public List masterArray(int boaId) {
Connection conn = DBConnectionManager.getInstance().getConnection(
);
PreparedStatement pstm = null;
ResultSet rs = null;
List list = new ArrayList();
try {
/**
* 取得该模板ID对应的子节点,如有子节点就不能删除,没有就删除。
*/
//如果没有节点,就execute删除
pstm = conn.prepareStatement(SELECT_PARENDID);
pstm.setInt(1, boaId);
rs = pstm.executeQuery();
rs.next();
int boaParId = Integer.parseInt(rs.getString("boaParId"));
String boaMaster = rs.getString("boaMaster");
list.add(boaMaster);
rs.close();
pstm.close();
while(boaParId != 0){
pstm = conn.prepareStatement(SELECT_PARENDID);
pstm.setInt(1, boaParId);
rs = pstm.executeQuery();
rs.next();
boaParId = Integer.parseInt(rs.getString("boaParId"));
boaMaster = rs.getString("boaMaster");
list.add(boaMaster);
rs.close();
pstm.close();
}
}
catch (Exception ex) {
logger.error("用户权限获取 : " + ex.getMessage());
}
finally {
try {
rs.close();
}
catch (Exception ex) {
logger.error("关闭 pstm 失败 error : " + ex.getMessage());
}
try {
pstm.close();
}
catch (Exception ex) {
logger.error("关闭 pstm 失败 error : " + ex.getMessage());
}
try {
conn.close();
}
catch (Exception ex) {
logger.error("关闭数据库连接失败 error : " + ex.getMessage());
}
}
return list;
}
/**
* 是否有子节点(用户删除判断)
*/
public boolean getChildId(int boaId) {
Connection conn = DBConnectionManager.getInstance().getConnection(
);
PreparedStatement pstm = null;
ResultSet rs = null;
int boaParId = 0;
int tempBoaId = 0;
int parentId = 0;
boolean isChildId = false;
try {
pstm = conn.prepareStatement(SELECT_CHILDID);
pstm.setInt(1, boaId);
rs = pstm.executeQuery();
if (rs.next()) {
/**
* 有记录的话就代表是上节点不能被删除
*/
isChildId = true;
//boaParId = rs.getInt("boaParId");
logger.info("删除时候获取parId的值 : " + boaParId);
}
else {
//能删除的时候更新排序(子节点的个数order)
tempBoaId = getParId(boaId);
logger.info("tempBoaId = " + tempBoaId);
logger.info("while循环 ........");
if (tempBoaId != 0) { //其还有上一个节点
do {
parentId = getParId(tempBoaId);
if (parentId != 0) {
decreaseChild(tempBoaId);
tempBoaId = parentId;
logger.info("parentId = " + parentId);
/*try {
Thread.sleep(1000);
}
catch (Exception ex) {
}*/
}
else {
decreaseChild(tempBoaId);
break;
}
}
while (parentId != 0);
}
/*else {
decreaseChild(tempBoaId);
logger.info("最后一个删除");
//tempBoaId = parentId;
}*/
}
}
catch (Exception ex) {
logger.info("检索数据发生错误 :" + ex.getMessage());
}
finally {
try {
rs.close();
}
catch (Exception ex) {
logger.error("关闭 指针 失败 error : " + ex.getMessage());
}
try {
pstm.close();
}
catch (Exception ex) {
logger.error("关闭 pstm 失败 error : " + ex.getMessage());
}
try {
conn.close();
}
catch (Exception ex) {
logger.error("关闭数据库连接失败 error : " + ex.getMessage());
}
}
return isChildId;
}
/**
* decrease 删除的时候模板减一
* @param boaId int
* @return boolean
*/
public void decreaseChild(int boaId) {
Connection conn = DBConnectionManager.getInstance().getConnection(
);
PreparedStatement pstm = null;
ResultSet rs = null;
try {
pstm = conn.prepareStatement(DECREASE_CHILD);
pstm.setInt(1, boaId);
pstm.executeUpdate();
}
catch (Exception ex) {
logger.info("检索数据发生错误 :" + ex.getMessage());
}
finally {
try {
pstm.close();
}
catch (Exception ex) {
logger.error("关闭 pstm 失败 error : " + ex.getMessage());
}
try {
conn.close();
}
catch (Exception ex) {
logger.error("关闭数据库连接失败 error : " + ex.getMessage());
}
}
}
/**
* 更新模板信息
* @param boaResideId int
* @return boolean
*/
public boolean upBoard(Board board) {
boolean isSuccess = false;
Connection conn = DBConnectionManager.getInstance().getConnection(
);
PreparedStatement pstm = null;
ResultSet rs = null;
try {
pstm = conn.prepareStatement(UPDATE_BOARD);
pstm.setString(1, board.getBoaType());
pstm.setString(2, board.getBoaInfo());
pstm.setString(3, board.getBoaMaster());
pstm.setInt(4, board.getBoaState());
pstm.setString(5, board.getBoaPasswd());
pstm.setInt(6, board.getBoaId());
logger.info("更新模板 : " + board.getBoaId());
pstm.executeUpdate();
isSuccess = true;
logger.info("成功更新模板....");
}
catch (Exception ex) {
logger.error("更新模板错误 : " + ex.getMessage());
}
finally {
try {
pstm.close();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -