📄 tempfile.2.tmp
字号:
result.returnCode(JResult.DBOPR_ERROR_UPDATE_FAILED); return result; } /** * Update object data in database * @param object * Type of object is valid consists of NodeVO, BlockVO * PortVO, UserVO, PackageConnection and PPConnection (not for Trap and Operation) * @return a JResult object. Check method isSucceeded() true if success. * @throws Exception */ public JResult updateObjectSeparator2DB(Object object) throws Exception{ JResult result = new JResult(); try{ conn.setAutoCommit(false); result = updateObjectSeparator2DBBuffer(object, DBConstants.DBPR_TYPE_ALL); if (result.isFailed()){ throw new SQLException(result.getMessage()); } conn.commit(); result.returnCode(JResult.DBOPR_SUCCESS); return result; }catch(SQLException e){ result.setMessage(e.getMessage()); try{ conn.rollback(); result.setOperationInfo("System is rolling back the operation --> OK!"); }catch(SQLException erollback){ //ERROR_DURING_ROLLBACK result.setOperationInfo("System is rolling back the operation --> Failed with message: " + erollback.getMessage()); } //LOG HERE }catch(Exception e){ result.setMessage(e.getMessage()); try{ conn.rollback(); }catch(Exception e1){} } result.returnCode(JResult.DBOPR_ERROR_UPDATE_FAILED); return result; } /** * Update object data in database * @param object * Type of object is valid consists of NodeVO, BlockVO * PortVO, UserVO, PackageConnection and PPConnection (not for Trap and Operation) * @param op * Specify that update all field of object or only position and dimension. * (DBConstants.DBPR_TYPE_ALL for all or DBConstants.DBPR_TYPE_POS for only position * and dimension) * * @return a JResult object. Check method isSucceeded() true if success. * @throws Exception */ private JResult updateObjectSeparator2DBBuffer(Object object, int op){ JResult result = null; String sql = null; try{ result = new JResult(); if (object instanceof NodeVO){ sql = getSQLCmd_InsUpd2NodeTbl((NodeVO)object, DBConstants.DBOPR_UPDATE, op); } else if (object instanceof BlockVO){ //Check the parent object if (findObject(DBConstants.NODE_OBJECT, ((BlockVO)object).getParentID()) <= 0){ //Error object not existed result.returnCode(JResult.DBOPR_ERROR_PARENT_OBJECT_NOT_FOUND); return result; } sql = getSQLCmd_InsUpd2BlockTbl((BlockVO)object, DBConstants.DBOPR_UPDATE, op); } else if (object instanceof PackageVO){ //Check the parent object if (findObject(DBConstants.FUNCBLOCK_OBJECT, ((PackageVO)object).getParentID()) <= 0){ //Error object not existed result.returnCode(JResult.DBOPR_ERROR_PARENT_OBJECT_NOT_FOUND); result.setMessage("Block with ID:" + ((PackageVO)object).getParentID() + "was not found."); return result; } sql = getSQLCmd_InsUpd2PackageTbl((PackageVO)object, DBConstants.DBOPR_UPDATE, op); } else if (object instanceof PortVO){ //Check the parent object if (findObject(DBConstants.PACKAGE_OBJECT, ((PortVO)object).getParentID()) <= 0){ //Error object not existed result.returnCode(JResult.DBOPR_ERROR_PARENT_OBJECT_NOT_FOUND); return result; } //Generate update SQL statement sql = getSQLCmd_InsUpd2PortTbl((PortVO)object, DBConstants.DBOPR_UPDATE); } else if (object instanceof UserVO){ //Generate update SQL statement sql = getSQLCmd_InsUpd2UserTbl((UserVO)object, DBConstants.DBOPR_UPDATE); } else if (object instanceof PackageConnection){ //Check the object JResult ret = checkPackagePConnection((PackageConnection)object); if (ret.isFailed()){ return ret; } //Generate update SQL statement sql = getSQLCmd_InsUpd2PackageConnectionTbl((PackageConnection)object, DBConstants.DBOPR_UPDATE); } else if (object instanceof PPConnection){ JResult ret = checkPPConnection((PPConnection)object); if (ret.isFailed()){ return ret; } //Generate update SQL statement sql = getSQLCmd_InsUpd2PPConnectionTbl((PPConnection)object, DBConstants.DBOPR_UPDATE); } else if (object instanceof PackageTypeVO){ sql = getSQLCmd_InsUpd2PackageTypeTbl((PackageTypeVO)object, DBConstants.DBOPR_UPDATE); } else { System.out.println("Error: The object is not supported!"); //LOG HERE result.returnCode(JResult.DBOPR_ERROR_OBJECT_NOT_SUPPORTED); return result; } //Execute SQL statement if (conn.execUpdate(sql)>0){ result.returnCode(JResult.DBOPR_SUCCESS); return result; } result.returnCode(JResult.DBOPR_ERROR_UPDATE_FAILED); result.setMessage("The object's value id maybe not existed."); return result; } catch (SQLException e){ result.setMessage(e.getMessage()); } catch (Exception e){ result.setMessage(e.getMessage()); } result.returnCode(JResult.DBOPR_ERROR_UPDATE_FAILED); return result; } /* LOAD DATA FROM DATABASE*/ /** * @Description: Load all nodes from database. * @return: null if no node is loaded, otherwise one set of NodeVO contained in vector object. */ private Vector<NodeVO> loadNodesForTree(){ Vector<NodeVO> vtNodes = new Vector<NodeVO>(); ArrayList<NodeVO> lstNodes = loadNodes(); if (lstNodes != null){ //Collections.copy(vtNodes, lstNodes); for (int i = 0; i < lstNodes.size(); i++){ vtNodes.add(lstNodes.get(i)); } return vtNodes; } return null; } /** * Load all node from database * @return null if an error occurred, otherwise list of node objects * contained in one ArrayList<NodeVO> object */ public ArrayList<NodeVO> loadNodes(){ return (getNodes(null)); } /** * Get nodes with a specified condition * @param condition * set null if get node without condition, otherwise such as * " column_name = 'x'" * @return null if an error occurred, otherwise list of node objects * contained in one ArrayList<NodeVO> object */ public ArrayList<NodeVO> getNodes(String condition){ try{ ResultSet rs = null; String sql = null; ArrayList<NodeVO> lstNodes = new ArrayList<NodeVO>(); if (conn != null){ conn.setAutoCommit(true); sql = " SELECT " + NodeVO.NODE_ID + "," + NodeVO.NODE_NAME + "," + NodeVO.NODE_ADDR + "," + NodeVO.NODE_POS_X + "," + NodeVO.NODE_POS_Y + "," + NodeVO.NODE_POS_W + "," + NodeVO.NODE_POS_H + " FROM " + NodeVO.NODE_TBL + ((condition == null)?"":(" WHERE " + condition)); rs = conn.execQuery(sql); while (rs.next()){ NodeVO nodeVO = new NodeVO(); nodeVO.setID(rs.getLong(NodeVO.NODE_ID)); nodeVO.setName(rs.getString(NodeVO.NODE_NAME)); nodeVO.setAddress(rs.getString(NodeVO.NODE_ADDR)); nodeVO.setPosX(rs.getInt(NodeVO.NODE_POS_X)); nodeVO.setPosY(rs.getInt(NodeVO.NODE_POS_Y)); nodeVO.setWidth(rs.getInt(NodeVO.NODE_POS_W)); nodeVO.setHeigh(rs.getInt(NodeVO.NODE_POS_H)); lstNodes.add(nodeVO); } conn.closeStatement(); rs.close(); } return lstNodes; } catch (SQLException e){ e.printStackTrace(); } catch (Exception e){ } return null; } /** * Load all block from database * @return null if an error occurred, otherwise list of block objects * contained in one ArrayList<BlockVO> object */ public ArrayList<BlockVO> loadBlocks(){ return (getBlocks(null)); } /** * Get blocks with a specified condition * @param condition * set null if get block without condition, otherwise such as * " column_name = 'x'" * @return null if an error occurred, otherwise list of block objects * contained in one ArrayList<BlockVO> object */ public ArrayList<BlockVO> getBlocks(String condition){ try{ String sql = null; ResultSet rs = null; ArrayList<BlockVO> lstBlocks = new ArrayList<BlockVO>(); conn.setAutoCommit(true); sql = " SELECT " + BlockVO.BLOCK_ID + "," + BlockVO.BLOCK_NAME + "," + NodeVO.NODE_ID + "," + BlockVO.BLOCK_IP + "," + BlockVO.BLOCK_TYPE + "," + BlockVO.BLOCK_ALARM + "," + BlockVO.BLOCK_POS_X + "," + BlockVO.BLOCK_POS_Y + "," + BlockVO.BLOCK_POS_W + "," + BlockVO.BLOCK_POS_H + " " + " FROM " + BlockVO.BLOCK_TBL + ((condition == null)?"":(" WHERE "+condition));; rs = conn.execQuery(sql); while (rs.next()){ BlockVO blockVO = new BlockVO(); blockVO.setID(rs.getLong(BlockVO.BLOCK_ID)); blockVO.setName(rs.getString(BlockVO.BLOCK_NAME)); blockVO.setParentID(rs.getInt(NodeVO.NODE_ID)); blockVO.setIP(rs.getString(BlockVO.BLOCK_IP)); blockVO.setType(rs.getInt(BlockVO.BLOCK_TYPE)); blockVO.setAlarm(rs.getInt(BlockVO.BLOCK_ALARM)); blockVO.setPosX(rs.getInt(BlockVO.BLOCK_POS_X)); blockVO.setPosY(rs.getInt(BlockVO.BLOCK_POS_Y)); blockVO.setWidth(rs.getInt(BlockVO.BLOCK_POS_W)); blockVO.setHeigh(rs.getInt(BlockVO.BLOCK_POS_H)); lstBlocks.add(blockVO); } conn.closeStatement(); rs.close(); return lstBlocks; } catch (SQLException e){ System.out.println(e.getMessage()); } catch (Exception e){ System.out.println(e.getMessage()); } return null; } /** * Load all package from database * @return null if an error occurred, otherwise list of package objects * contained in one ArrayList<PackageVO> object */ public ArrayList<PackageVO> loadPackages(){ return (getPackages(null)); } /** * Get packages with a specified condition * @param condition * set null if get package without condition, otherwise such as * " column_name = 'x'" * @return null if an error occurred, otherwise list of package objects * contained in one ArrayList<PackageVO> object */ public ArrayList<PackageVO> getPackages(String condition){ try{ String sql = null; ResultSet rs = null; ArrayList<PackageTypeVO> lstPkgType = loadPackageTypes(); ArrayList<PackageVO> lstPackages = new ArrayList<PackageVO>(); conn.setAutoCommit(true); sql = " SELECT " + PackageVO.PACKAGE_ID + "," + PackageVO.PACKAGE_SLOT + "," + BlockVO.BLOCK_ID + "," + PackageTypeVO.PACKAGETYPE_ID + "," + PackageVO.PACKAGE_POS_X + "," + PackageVO.PACKAGE_POS_Y + "," + PackageVO.PACKAGE_POS_W + "," + PackageVO.PACKAGE_POS_H + "," + PackageVO.PACKAGE_ALARM_1 + "," + PackageVO.PACKAGE_ALARM_2 + " " + " FROM " + PackageVO.PACKAGE_TBL + ((condition == null)?"":(" WHERE " + condition)); rs = conn.execQuery(sql); while (rs.next()){ PackageVO packageVO = new PackageVO(); packageVO.setID(rs.getLong(PackageVO.PACKAGE_ID)); packageVO.setPackageSlot(rs.getInt(PackageVO.PACKAGE_SLOT)); packageVO.setParentID(rs.getLong(BlockVO.BLOCK_ID)); packageVO.setPosX(rs.getInt(PackageVO.PACKAGE_POS_X)); packageVO.setPosY(rs.getInt(PackageVO.PACKAGE_POS_Y)); packageVO.setWidth(rs.getInt(PackageVO.PACKAGE_POS_W)); packageVO.setHeigh(rs.getInt(PackageVO.PACKAGE_POS_H)); packageVO.setAlarm1(rs.getInt(PackageVO.PACKAGE_ALARM_1)); packageVO.setAlarm2(rs.getInt(PackageVO.PACKAGE_ALARM_2)); long ptid = rs.getLong(PackageTypeVO.PACKAGETYPE_ID); /*Get package type id*/ packageVO.setPackageTypeID(ptid); //Get package name and list port name that corresponding with package type id for (int i = 0; i < lstPkgType.size(); i++){ if (lstPkgType.get(i).getID() == ptid ){ packageVO.setName(lstPkgType.get(i).getName()) ; packageVO.setListPorts(lstPkgType.get(i).getDescPorts()); } } lstPackages.add(packageVO); } conn.closeStatement(); rs.close(); return lstPackages; } catch (SQLException e){ } catch (Exception e){ } return null; } /** * Load all port from database * @return null if an error occurred, otherwise list of port objects * contained in one ArrayList<PortVO> object */ public ArrayList<PortVO> loadPorts(){ return (getPorts(null)); } /** * Get ports with a specified condition * @param condition * set null if get port without condition, otherwise such as * " column_name = 'x'" * @return null if an error occurred, otherwise list of port objects
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -