📄 manufacturehelper.java
字号:
package oracle.otnsamples.AQ.Helper;
/**
* @author Anupama
* @version 1.0
*
* Development Environment : Oracle9i JDeveloper
* Name of the Application : ManufactureHelper.java
* Creation/Modification History :
*
* Anupama 27-Jan-2002 Created
*
*/
// Util imports
import java.util.Hashtable;
import java.util.Vector;
// Other imports
import oracle.otnsamples.AQ.DataBase.DBConnect;
/**
* This class is called for all the operations done by a Manufacturer.
* Whether the manufacturer wants to add, delete, update products
* from his database, all the requests go through this file.
* Every method in this class corresponds to a request from the manufacturer.
* This class generates the query required for any of the operations to
* be done on the database.
*/
public class ManufactureHelper{
/**
* Empty Constructor
*/
public ManufactureHelper() {
}
/**
* This method is called once when the manufacturer successfully logs
* in to the database. The basic functionality of this method
* is to display all the products that are available with the manufacturer.
* It constructors a query to retrieve all the products from the database
* and sends it to DBConnect. It returns a Hash table which contains information
* about the products present with the manufacturer. The Vector returned
* by DBConnect is converted into Hash table. Product ID is used as key in
* the Hash table.
*
* @exception Exception Incase of some error or unreported Exception
* @param p_user Type of the user
* @return Contains all the products which the manufacturer has in the
* database.
* @see DBConnect.java
*/
public static Hashtable displayProducts(String p_user) throws Exception {
// Get DBConnect Instance to execute query
DBConnect dbInstance = DBConnect.getInstance();
// Construct the query
String query = new StringBuffer().append("SELECT product_id, ")
.append("INITCAP(product_name), product_desc,")
.append(" manufacturer_id, price, category_desc, ")
.append("quantity_on_hand FROM product_master ")
.append("ORDER BY LOWER(product_name)").toString();
// Execute the query using the instance. The Vector retrieved is sent to the
// method and converted into a hash table.
Hashtable productHash = storePrdsInHash(dbInstance.executeQuery(query, p_user));
return productHash;
}
/**
* This method is called once when the manufacturer wants to add a product
* into the database. The basic functionality of this method
* is to retrieve the product ID, construct a query to add the product
* into the database using the product details sent and send it to DBConnect.
* Then call the method in EnqueuePrdHelper which adds the product to queue
* so that the Retail manager will know about the change occurred through message
* propagation. The product details are then added to the Hash of product
* list and returned.
*
* @exception Exception Incase of some error or unreported Exception
* @param p_user Type of the user
* @param p_productList List of all the products the manufacturer has
* @param p_addedProductInfo Details of the product to be added
* @return Contains details of all the products present with the
* manufacturer along with the one added recently
* @see DBConnect.java
* @see Product.java
* @see EnqueuePrdHelper.java
*/
public static Hashtable addProduct(String p_user, Hashtable p_productList,
Product p_addedProductInfo) throws Exception {
// Get DBConnect Instance to execute query
DBConnect dbInstance = DBConnect.getInstance();
// Get the next product id from the sequence present in the database.
p_addedProductInfo.setProductID(getProductId(p_user));
// If the manufacturer Id is not present (this is in case when no product
// is present in the table and the first product is being added) then
// retrieve the manufacturer ID from database.
if(p_addedProductInfo.getManufactureID()==null){
p_addedProductInfo.setManufactureID(getManufacturerId(p_user));
}
// Construct the query
String query = new StringBuffer().append("INSERT INTO Product_Master ")
.append("(product_id,product_name,product_desc,manufacturer_id,")
.append("price,category_desc,quantity_on_hand) VALUES('")
.append(p_addedProductInfo.getProductID()).append("','")
.append(p_addedProductInfo.getProductName()).append("','")
.append(p_addedProductInfo.getProductDesc()).append("','")
.append(p_addedProductInfo.getManufactureID()).append("','")
.append(p_addedProductInfo.getProductPrice()).append("','")
.append(p_addedProductInfo.getCategoryDesc()).append("','")
.append(p_addedProductInfo.getQuantityOnHand())
.append("')").toString();
// Execute the query using the DBConnect instance retrieved.
dbInstance.executeUpdate(query, p_user);
// Add the product details into Queue.
EnqueuePrdHelper.addPrdToQueue(p_addedProductInfo, p_user, "ADD");
// Add the product details into the list of product present in hash table.
p_productList.put(p_addedProductInfo.getProductID(), p_addedProductInfo);
return p_productList;
}
/**
* This method is called when the manufacturer wants to update the details
* of a product. The basic functionality of this method is construct a
* query to update the product whose details are sent in the database
* using the get methods present in Product.java and send it to DBConnect.
* Then call the method in EnqueuePrdHelper which adds the product to queue
* so that the Retail manager will know about the change occurred through message
* propagation. The product details are then added to the Hash of product
* list and returned.
*
* @exception Exception Incase of some error or unreported Exception
* @param p_user Type of the user
* @param p_productList List of all the products the manufacturer has
* @param p_updatedProductInfo Details of the product to be updated
* @return Contains details of all the products present with the
* manufacturer
* @see DBConnect.java
* @see EnqueuePrdHelper.java
* @see Product.java
*/
public static Hashtable updateProduct(String p_user, Hashtable p_productList,
Product p_updatedProductInfo) throws Exception{
// Get DBConnect Instance to execute query
DBConnect dbInstance = DBConnect.getInstance();
// Construct the query
String query=new StringBuffer().append("UPDATE PRODUCT_MASTER SET product_desc='")
.append(p_updatedProductInfo.getProductDesc())
.append("', price='")
.append(p_updatedProductInfo.getProductPrice())
.append("', category_desc='")
.append(p_updatedProductInfo.getCategoryDesc()).append("',")
.append(" quantity_on_hand='")
.append(p_updatedProductInfo.getQuantityOnHand())
.append("' WHERE ").append("product_id = '")
.append(p_updatedProductInfo.getProductID())
.append("' AND manufacturer_id ='")
.append(p_updatedProductInfo.getManufactureID())
.append("'").toString();
// Execute the query using the DBConnect instance retrieved.
dbInstance.executeUpdate(query, p_user);
// Add the product details into Queue.
EnqueuePrdHelper.addPrdToQueue(p_updatedProductInfo, p_user, "UPDATE");
// Add the product details into product list. The details of the product
// which are already present are overwritten.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -