📄 manufacturehelper.java
字号:
p_productList.put(p_updatedProductInfo.getProductID(), p_updatedProductInfo);
return p_productList;
}
/**
* This method is called when the manufacturer wants to
* delete few products from his database. The basic functionality
* of this method is to construct one query for each of the
* product selected for deletion and send it to DBConnect.java
* to be executed, then send the details of all the products
* deleted to ENqueuePrdHelper to be enqueued and sent to
* Retail manager through message propagation. If everything goes
* on successfully then all the details are deleted from the
* products hash and returned to the calling method in the
* respective manager class.
*
* @param p_user Type of the user
* @param p_productList List of all the products the manufacturer has
* @param p_productsToBeDeleted Details of the products to be deleted
* @exception Exception Incase of some error or unreported Exception
* @return Details of the products the manufacturer currently has after
* deleting the product details sent.
* @see Product.java
* @see EnqueuePrdHelper.java
* @see DBConnect.java
*/
public static Hashtable deleteProducts(String p_user, Hashtable p_productList,
Product[] p_productsToBeDeleted) throws Exception{
// Get DBConnect Instance to execute query
DBConnect dbInstance = DBConnect.getInstance();
// Store the number of products to be deleted.
int noOfPrds=p_productsToBeDeleted.length;
String[] queriesArr=new String[noOfPrds];
for(int i=0;i<noOfPrds;i++){
// Construct array of queries for all the products to be deleted.
queriesArr[i] = new StringBuffer("DELETE PRODUCT_MASTER WHERE product_id='")
.append(p_productsToBeDeleted[i].getProductID())
.append("' AND manufacturer_id ='")
.append(p_productsToBeDeleted[i].getManufactureID())
.append("'").toString();
}
// Execute the query using the DBConnect instance retrieved.
int arr[]=dbInstance.executeUpdate(queriesArr, p_user);
// Add the product details into Queue.
EnqueuePrdHelper.addPrdToQueue(p_productsToBeDeleted,p_user,"DELETE");
// Delete all the details of the product from the hash table using their
// product id.
for(int i=0;i<noOfPrds;i++){
p_productList.remove(p_productsToBeDeleted[i].getProductID());
}
return p_productList;
}
/**
* This method is called by addProduct method. The basic
* functionality of this method is to construct a query
* to retrieve the next product ID from the sequence,
* convert it into product Id by appending the alphabet
* 'P' in front and return it.
*
* @param p_user Type of the user
* @exception Exception Incase of some error or unreported Exception
* @return The product id of the product to be added
*/
private static String getProductId(String p_user) throws Exception{
// Get DBConnect Instance to execute query
DBConnect dbInstance = DBConnect.getInstance();
// Construct the query
String query="SELECT Product_Id_Seq.NEXTVAL FROM DUAL";
// Execute the query using the instance retrieved.
Vector productIdVec=dbInstance.executeQuery(query, p_user);
String productId="";
// The Vector retrieved will contain one value in one row retrieved from
// the sequence.
for(int i=0;i<productIdVec.size();i++){
// Get the next sequence from the Vector
String[] resultArr=(String[])productIdVec.elementAt(i);
// Append the alphabet 'P' to it to form the product id.
productId=new StringBuffer().append("P").append(resultArr[0]).toString();
break;
}
return productId;
}
/**
* This method is called by addProduct method. The basic
* functionality of this method is to construct a query
* to retrieve the manufacturer ID from the Manufacturer master table,
* and return it to the function.
*
* @param p_user Type of the user
* @exception Exception Incase of some error or unreported Exception
* @return The manufacturer id of the product to be added
*/
private static String getManufacturerId(String p_user) throws Exception{
// Get DBConnect Instance to execute query
DBConnect dbInstance = DBConnect.getInstance();
// Construct the query
String query="SELECT manufacturer_id FROM Manufacturer_Master";
// Execute the query using the instance retrieved.
Vector manufacturerIdVec=dbInstance.executeQuery(query, p_user);
// The manufacturer table contains only one row which contains the id of the
// manufacturer. So the query returned contains only the manufacturer id in
// the string array as the only element in the vector.
return (((String[])manufacturerIdVec.elementAt(0))[0]);
}
/**
* This method converts the List of products stored in the vector as an
* array of string into a Hash table. The key of the Hash table is productId
* and value is object of the class Product.
*
* @exception Exception Incase of some error or unreported Exception
* @param productsVector Details of all the products stored as an array of
* strings in the Vector.
* @return Details of all the products the manufacturer has in the form of
* Hash table
* @see DBConnect.java
*/
private static Hashtable storePrdsInHash(Vector p_productsVector)
throws Exception {
Hashtable productHash = new Hashtable();
int noOfProducts = p_productsVector.size();
Product productObj = null;
String[] productArr;
for(int i=0;i<noOfProducts;i++){
// The information about the product is stored as an array of String in
// the Vector.
productArr = (String [])p_productsVector.elementAt(i);
// Store the details of the product present in the array in Product object.
productObj = storeProductDetails(productArr);
// ProductId is used as key for the hash table.
productHash.put(productArr[0], productObj);
}
return productHash;
}
/**
* Retrieves the product details stored as string array in Vector
* and assigns it to the corresponding element in the object of
* Product using the set methods provided in the class.
*
* @param productArr Details of the product
* @exception Exception Incase of some error or unreported Exception
* @return Object of the class Product containing the details of the product
* sent in vector
* @see Product.java
*/
private static Product storeProductDetails(String[] p_productArr)
throws Exception{
Product product = new Product();
product.setProductID(p_productArr[0]);
product.setProductName(p_productArr[1]);
product.setProductDesc(p_productArr[2]);
product.setManufactureID(p_productArr[3]);
product.setCategoryDesc(p_productArr[5]);
product.setProductPrice(p_productArr[4]);
product.setQuantityOnHand(p_productArr[6]);
return product;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -