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

📄 tempfile.tmp

📁 this is example use EJB with jboss.
💻 TMP
📖 第 1 页 / 共 5 页
字号:
	 * 		   use method getObjectData() of JResult to get this.	 * @throws Exception	 * 			throws a exception if one unknown error is occurred.	 */	public JResult addPackage2DB(PackageVO object) throws Exception{				 JResult result = null;		 long packageID = -1;	     try{	    	 //Disable auto commit, so we want to make sure that overall data (package and ports)	    	 //are inserted successful.	    	 conn.setAutoCommit(false);	    	 	    	 PackageVO pkgvo = object;	    	 result = addObject2DBBuffer(pkgvo);	    	 if (result.isFailed()){	    		 throw new SQLException(result.getMessage());	    	 }	    	 //Get ID of package have just inserted	    	 packageID = result.getValue();	    	 String packageName = pkgvo.getName();	    	 //Get package type object from package name	    	 ArrayList<PackageTypeVO> lstPackageType = getPackageTypes("packagetype_name LIKE '" + packageName + "%'");	    	 if ((lstPackageType != null) && (!lstPackageType.isEmpty())){	    		//From package name, we want to get list of port name that corresponding	    		 String lstNamePorts = lstPackageType.get(0).getDescPorts();	    		 lstNamePorts = lstNamePorts.trim();	    		 //Get each port name from list	    		 String[] namePort = lstNamePorts.split(",");	    		 //For each port name from list, we will create one new port object, then	    		 //insert them to database	    		 for (int i = 0; i < namePort.length; i++){	    			 namePort[i] = namePort[i].trim();	    			 if ("".equalsIgnoreCase(namePort[i])){	    				 throw new SQLException("The list of port name is invalid. Check pakagetype_name table.");	    			 }else{	    				 PortVO pvo = new PortVO();	    				 pvo.setName(namePort[i]);	    				 pvo.setParentID(packageID);	    				 //insert ports	    				 result = addObject2DB(pvo);	    				 if (result.isFailed()){	    					 throw new SQLException(result.getMessage());	    				 }	    				 pvo.setID(result.getValue());	    				 pkgvo.getListPortVO().add(pvo);	    			 }	    		 }	    	 }else{	    		 throw new Exception("An error occurred during loads package type." +	    		 					  " Check for make sure that the package name existed.");	    	 }	    	 //If no any errors occurred, so commit	    	 conn.commit();	    	 pkgvo.setID(packageID);	    	 result.setValue(packageID);	    	 result.setObjectData(pkgvo);			 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_INSERT_FAILED);		return result;				}		/**	 * add a list of package-package connections into database	 * @param lstLogicalConn	 * 						list of package-package connections	 * @return a JResult object. Check method isSucceeded() true if success.	 * @throws Exception	 */	public JResult addLogicalConnection2DB(ArrayList<PackageConnection> lstLogicalConn) throws Exception{				 JResult result = null;		 String sql = null;	     try{	    	 result = new JResult();	    	 //Disable auto commit, so we want to make sure that overall data	    	 //are inserted successful.	    	 conn.setAutoCommit(false);	    	 //Delete overall connection data old			 sql = "DELETE FROM " + getTableName(DBConstants.PACKAGE_PACKAGE_OBJECT) ;			 conn.execUpdate(sql);			 //Insert new from list	    	 for (int i = 0; i < lstLogicalConn.size(); i++){	    		 result = addObject2DBBuffer(lstLogicalConn.get(i));	    		 if (result.isFailed()){	    			 throw new SQLException(result.getMessage());	    		 }	    	 }	    	 //If no any error occurred, so commit	    	 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_INSERT_FAILED);		return result;	}	/**	 * add an object into database	 * @param object	 * 				Type of object is valid consists of NodeVO, BlockVO	 * 				PortVO, UserVO, TrapVO, OperationVO, PackageConnection and PPConnection	 * @return a JResult object. Check method isSucceeded() true if success.	 * @throws Exception	 */	public JResult addObject2DB(Object object) throws Exception{		 JResult result = new JResult();		 try{		     conn.setAutoCommit(false);		     result = addObject2DBBuffer(object);		     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_INSERT_FAILED);		return result;		}		/**	 * add an object into cache store of database	 * @param object	 * 				Type of object is valid consists of NodeVO, BlockVO	 * 				PortVO, UserVO, TrapVO, OperationVO, PackageConnection and PPConnection	 * @return a JResult object. Check method isSucceeded() true if success.	 * @throws Exception	 */	private JResult addObject2DBBuffer(Object object){				JResult result = null;		try{			String sql = null;			int objectType = -1;			int objectID = -1;			result = new JResult(); 			if (object instanceof NodeVO){				objectType = DBConstants.NODE_OBJECT;				sql = getSQLCmd_InsUpd2NodeTbl((NodeVO)object, DBConstants.DBOPR_INSERT, DBConstants.DBPR_TYPE_ALL);      		 			} else if (object instanceof BlockVO){						objectType = DBConstants.FUNCBLOCK_OBJECT;				  		//Check the parent object						if (findObject(DBConstants.NODE_OBJECT, ((BlockVO)object).getParentID()) <= 0){							//Error object was not found							result.returnCode(JResult.DBOPR_ERROR_PARENT_OBJECT_NOT_FOUND);							return result;						}						//Generate insert SQL statement						sql = getSQLCmd_InsUpd2BlockTbl((BlockVO)object,DBConstants.DBOPR_INSERT, DBConstants.DBPR_TYPE_ALL);								 			} else if (object instanceof PackageVO){						objectType = DBConstants.PACKAGE_OBJECT;				        PackageVO packageVO = (PackageVO)object;				        //Check the parent object				        if (findObject(DBConstants.FUNCBLOCK_OBJECT, packageVO.getParentID()) <= 0){				        	 //Error object was not found							 result.returnCode(JResult.DBOPR_ERROR_PARENT_OBJECT_NOT_FOUND);							 result.setMessage("Block with ID '" + packageVO.getParentID() + "' was not found.");							 return result;				        }				        if (packageVO.getListPortVO() !=null){				        	if (!packageVO.getListPortVO().isEmpty()){				        		result.returnCode(JResult.DBOPR_ERROR_OBJECT_NOT_SUPPORTED);				        		result.setMessage("The input package object contains one or more of port's data. Use method addPackage2DB() instead of.");				        		return result;				        	}				        }				      //Generate insert SQL statement				        sql = getSQLCmd_InsUpd2PackageTbl((PackageVO)object, DBConstants.DBOPR_INSERT, DBConstants.DBPR_TYPE_ALL);				} else if (object instanceof PortVO){				    	objectType = DBConstants.PORT_OBJECT;						//Check the parent object				    	if(findObject(DBConstants.PACKAGE_OBJECT, ((PortVO)object).getParentID()) <= 0){				    		//Error object was not found				    		result.returnCode(JResult.DBOPR_ERROR_PARENT_OBJECT_NOT_FOUND);				    		return result;				    	}				    	 //Generate insert SQL statement				    	sql = getSQLCmd_InsUpd2PortTbl((PortVO)object, DBConstants.DBOPR_INSERT);				} else if (object instanceof UserVO){						objectType = DBConstants.USER_OBJECT;						sql = getSQLCmd_InsUpd2UserTbl((UserVO)object, DBConstants.DBOPR_INSERT); 				} else if (object instanceof PackageConnection){					    objectType = DBConstants.PACKAGE_PACKAGE_OBJECT;					    //Check the object					    JResult ret = checkPackagePConnection((PackageConnection)object);					    if (ret.isFailed()){					    	return ret;					    }						sql = getSQLCmd_InsUpd2PackageConnectionTbl((PackageConnection)object, DBConstants.DBOPR_INSERT);				} else if (object instanceof PPConnection){					 	objectType = DBConstants.PACKAGE_PORT_OBJECT;					 	JResult ret = checkPPConnection((PPConnection)object);					 	if(ret.isFailed()){					 		return ret;					 	}					 	 //Generate insert SQL statement					 	sql = getSQLCmd_InsUpd2PPConnectionTbl((PPConnection)object,DBConstants.DBOPR_INSERT);					 			} else if (object instanceof OperationVO){						objectType = DBConstants.LOG_OBJECT;						sql = getSQLCmd_Ins2LogTbl((OperationVO)object);								} else if (object instanceof PackageTypeVO){						objectType = DBConstants.PACKAGETYPE_OBJECT;						 //Generate insert SQL statement						sql = getSQLCmd_InsUpd2PackageTypeTbl((PackageTypeVO)object,DBConstants.DBOPR_INSERT);				} else if (object instanceof TrapVO){										objectType = DBConstants.TRAP_OBJECT;						//Check exceed the limit value of traps, delete one portion of data */						//if(countObject(DBConstants.TRAP_OBJECT, null)>);						//Insert one new						sql = getSQLCmd_Ins2TrapTbl((TrapVO)object);			} else {				System.out.println("Error: The object is not supported!");				//LOG HERE				result.returnCode(JResult.DBOPR_ERROR_OBJECT_NOT_SUPPORTED);				return result;			}						// Append keyword "RETURNING" to insert SQL statement to get ID which generated			// by auto-increment field.			sql += " RETURNING " + getIDName(objectType);			//Execute SQL statement			ResultSet rs =  conn.execQuery(sql);            while(rs.next()){        	   objectID =rs.getInt(1);             }            //Return object's id and operation code.            result.setValue(objectID);            result.returnCode(JResult.DBOPR_SUCCESS);            return result;        		}catch(SQLException e){			result.setMessage(e.getMessage());		}catch(Exception e){			result.setMessage(e.getMessage());		}		result.returnCode(JResult.DBOPR_ERROR_INSERT_FAILED);		return result;		}	/**	 * Update the position and dimension of node, block and package	 * @param nodeHelper	 * 					NodeHelper object contains new position of node, block and package		 * @return a JResult object. Check method isSucceeded() true if success.	 * @throws Exception	 */	public JResult updateObjectPosition2DB(NodeHelper nodeHelper) throws Exception{		 JResult result = new JResult();		 try{			 conn.setAutoCommit(false);			 Vector<NodeVO> vtNodes = nodeHelper.getListNodeVO();			 if (vtNodes != null){				 for (int iNode = 0; iNode < vtNodes.size(); iNode++){					 NodeVO nvo = vtNodes.get(iNode);					 //Update position and dimension of node 					 result = updateObjectSeparator2DBBuffer(nvo, DBConstants.DBPR_TYPE_POS);					 if (result.isFailed()){						 throw new SQLException(result.getMessage());					 }					 //Get list of child objects for each node 					 Vector<BlockVO> vtBlocks = nvo.getListBlockVO();					 if (vtBlocks != null){						 for (int iBlock = 0; iBlock < vtBlocks.size(); iBlock++){							 BlockVO bvo = vtBlocks.get(iBlock);							 //Update position and dimension of block							 result = updateObjectSeparator2DBBuffer(bvo, DBConstants.DBPR_TYPE_POS);							 if (result.isFailed()){								 throw new SQLException(result.getMessage());							 }							 //Get list of child objects for each block 							 Vector<PackageVO> vtPackages = bvo.getListPackageVO();							 if (vtPackages != null){								 for (int iPkg = 0; iPkg < vtPackages.size(); iPkg++){									 PackageVO pkgvo = vtPackages.get(iPkg);									 //Update position and dimension of package									 result = updateObjectSeparator2DBBuffer(pkgvo, DBConstants.DBPR_TYPE_POS);									 if (result.isFailed()){										 throw new SQLException(result.getMessage());									 }									 								 }							 }						 }					 }				 }			 }		  //if all of operation have complete with no error, so commit.		   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){}

⌨️ 快捷键说明

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