package StockTradeServices;
import Framework.Array_Of_ListElement;
import Framework.Constants;
import Framework.ErrorMgr;
import Framework.ListElement;
import Framework.RuntimeProperties;
import Framework.TextData;
import GenericDBMS.ArrayRowMapper;
import GenericDBMS.BeanRowMapper;
import GenericDBMS.DBConnectionManager;
import GenericDBMS.ResultSetHelper;
import StockTradeBusinessClasses.Array_Of_Holding;
import StockTradeBusinessClasses.Customer;
import StockTradeBusinessClasses.Holding;
import StockTradeServices.NoSuchCustomerException;
import StockTradeServices.NoSuchHoldingException;
import java.io.Serializable;
import java.lang.Cloneable;
import java.lang.String;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import org.springframework.dao.support.DataAccessUtils;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator;
/**
* CustDBMgr<p>
* <p>
* @author Generated from Forte
* @since 24-Aug-2010
*/
@RuntimeProperties(isDistributed=false, isAnchored=false, isShared=false, isTransactional=false)
@SuppressWarnings("serial")
public class CustDBMgr
implements Cloneable, Serializable
{
// ----------
// Attributes
// ----------
private Array_Of_ListElement<ListElement> stockNameList;
// ------------
// Constructors
// ------------
public CustDBMgr() {
// Explicitly call the superclass constructor to prevent the implicit call
super();
}
// -------
// Methods
// -------
/**
* setupStockNameList<p>
* self.StockNameList[1] = new;<br>
* self.StockNameList[1].TextValue.Setvalue('MacDonna');<br>
* self.StockNameList[2] = new;<br>
* self.StockNameList[2].TextValue.Setvalue('Boston Quicken');<br>
* self.StockNameList[3] = new;<br>
* self.StockNameList[3].TextValue.Setvalue('Giorgio Osmondi');<br>
* self.StockNameList[4] = new;<br>
* self.StockNameList[4].TextValue.Setvalue('Microshift');<br>
* self.StockNameList[5] = new;<br>
* self.StockNameList[5].TextValue.Setvalue('Paco Bella');<br>
* self.StockNameList[6] = new;<br>
* self.StockNameList[6].TextValue.Setvalue('Happy Duck');<br>
* self.StockNameList[7] = new;<br>
* self.StockNameList[7].TextValue.Setvalue('Coarse Light');<br>
* self.StockNameList[8] = new;<br>
* self.StockNameList[8].TextValue.Setvalue('Forte');<br>
* <p>
*/
private void setupStockNameList() {
DBConnectionManager dBConnection = DBConnectionManager.getInstance("DBConnection");
ResultSet qq_rs = null;
PreparedStatement qq_cmd = null;
String qq_SQL = null;
try {
// -- =============== Original SQL ===============
// select StockName from Stock
// on session DBConnection
// -- ============================================
qq_SQL = "select StockName from Stock ";
qq_cmd = dBConnection.getPreparedStatement(qq_SQL);
qq_rs = qq_cmd.executeQuery();
ResultSetHelper qq_rsHelper = new ResultSetHelper(qq_rs);
while (qq_rsHelper.next()) {
TextData temp = qq_rsHelper.getTextData(1);
ListElement row = new ListElement();
row.getTextValue().setValue( temp.getValue() );
this.stockNameList.add(row);
}
}
catch (SQLException qq_error) {
throw new SQLErrorCodeSQLExceptionTranslator(dBConnection.getDataSource()).translate("Running SQL", qq_SQL, qq_error);
}
finally {
dBConnection.cleanup(qq_cmd);
}
}
/**
* SQLDeleteHolding<p>
* <p>
* @param pHolding Type: Holding
*/
private void SQLDeleteHolding(Holding pHolding) {
DBConnectionManager dBConnection = DBConnectionManager.getInstance("DBConnection");
// -- =============== Original SQL ===============
// delete from Holding
// where CustomerName=:pHolding.CustomerName and
// StockName=:pHolding.StockName
// on session DBConnection
// -- ============================================
String qq_SQL = "delete from Holding " +
"where CustomerName=? and " +
"StockName=? ";
Object[] qq_SQLParams = new Object[] {
pHolding.getCustomerName(),
pHolding.getStockName()
};
dBConnection.getTemplate().update(qq_SQL, qq_SQLParams);
}
/**
* SQLInsertHolding<p>
* <p>
* @param pHolding Type: Holding
*/
private void SQLInsertHolding(Holding pHolding) {
DBConnectionManager dBConnection = DBConnectionManager.getInstance("DBConnection");
// -- =============== Original SQL ===============
// insert into Holding (CustomerName, StockName, Quantity, Price)
// values (:pHolding.CustomerName, :pHolding.StockName,
// :pHolding.Quantity, :pHolding.Price)
// on session DBConnection
// -- ============================================
String qq_SQL = "insert into Holding (CustomerName, StockName, Quantity, Price) " +
"values (?, ?, " +
"?, ?) ";
Object[] qq_SQLParams = new Object[] {
pHolding.getCustomerName(),
pHolding.getStockName(),
new Integer(pHolding.getQuantity()),
new Float(pHolding.getPrice())
};
dBConnection.getTemplate().update(qq_SQL, qq_SQLParams);
}
/**
* SQLSelectCustomer<p>
* <p>
* @param pName Type: TextData
* @return Customer
*/
private Customer SQLSelectCustomer(TextData pName) {
Customer aCustomer = new Customer();
int recsReturned = 0;
int qq_RowCount = 0;
DBConnectionManager dBConnection = DBConnectionManager.getInstance("DBConnection");
// -- =============== Original SQL ===============
// select * into :aCustomer from Customer
// where CustomerName = :pName
// on session DBConnection
// -- ============================================
String qq_SQL = "select * from Customer " +
"where CustomerName = ? ";
Object[] qq_SQLParams = new Object[] {pName };
// TODO [112,Info]: Using the * in a query rather than explicitly enumerating the column list is often inefficient.
JdbcTemplate qq_Template = dBConnection.getTemplate();
List qq_List = qq_Template.query(qq_SQL, qq_SQLParams, new BeanRowMapper(aCustomer, Customer.class));
if (!qq_List.isEmpty()) {
aCustomer = (Customer)DataAccessUtils.singleResult(qq_List);
}
qq_RowCount = qq_List.size();
recsReturned = qq_RowCount;
if (recsReturned == 1) {
return aCustomer;
}
else {
NoSuchCustomerException noSuchCust = new NoSuchCustomerException();
noSuchCust.setWithParams(Constants.SP_ER_ERROR, "Customer %1 does not exist", pName);
ErrorMgr.addError(noSuchCust);
throw noSuchCust;
}
}
/**
* SQLSelectHolding<p>
* <p>
* @param pSelHoldCustName Type: TextData
* @param pSelHoldStockName Type: String
* @return Holding
*/
private Holding SQLSelectHolding(TextData pSelHoldCustName, String pSelHoldStockName) {
Holding aHolding = new Holding();
int recsReturned = 0;
int qq_RowCount = 0;
DBConnectionManager dBConnection = DBConnectionManager.getInstance("DBConnection");
// -- =============== Original SQL ===============
// select * into :aHolding from Holding
// where CustomerName = :pSelHoldCustName
// and StockName = :pSelHoldStockName
// on session DBConnection
// -- ============================================
String qq_SQL = "select * from Holding " +
"where CustomerName = ? " +
"and StockName = ? ";
Object[] qq_SQLParams = new Object[] {
pSelHoldCustName,
pSelHoldStockName
};
// TODO [112,Info]: Using the * in a query rather than explicitly enumerating the column list is often inefficient.
JdbcTemplate qq_Template = dBConnection.getTemplate();
List qq_List = qq_Template.query(qq_SQL, qq_SQLParams, new BeanRowMapper(aHolding, Holding.class));
if (!qq_List.isEmpty()) {
aHolding = (Holding)DataAccessUtils.singleResult(qq_List);
}
qq_RowCount = qq_List.size();
recsReturned = qq_RowCount;
if (recsReturned == 1) {
return aHolding;
}
else {
NoSuchHoldingException noHolding = new NoSuchHoldingException();
noHolding.setWithParams(Constants.SP_ER_ERROR, "Customer %1 does not own this stock", pSelHoldCustName);
ErrorMgr.addError(noHolding);
throw noHolding;
}
}
/**
* SQLSelectHoldingList<p>
* <p>
* @param pName Type: TextData
* @return Array_Of_Holding<Holding>
*/
private Array_Of_Holding<Holding> SQLSelectHoldingList(TextData pName) {
Array_Of_Holding<Holding> aCustomersHoldingList = new Array_Of_Holding<Holding>();
DBConnectionManager dBConnection = DBConnectionManager.getInstance("DBConnection");
// -- =============== Original SQL ===============
// select * into :aCustomersHoldingList
// from Holding
// where CustomerName = :pName
// on session DBConnection
// -- ============================================
String qq_SQL = "select * " +
"from Holding " +
"where CustomerName = ? ";
Object[] qq_SQLParams = new Object[] {pName };
// TODO [112,Info]: Using the * in a query rather than explicitly enumerating the column list is often inefficient.
JdbcTemplate qq_Template = dBConnection.getTemplate();
aCustomersHoldingList = (Array_Of_Holding)qq_Template.query(qq_SQL, qq_SQLParams, new ArrayRowMapper(aCustomersHoldingList, Array_Of_Holding.class));
return aCustomersHoldingList;
}
/**
* SQLUpdateHolding<p>
* <p>
* @param pHolding Type: Holding
*/
private void SQLUpdateHolding(Holding pHolding) {
DBConnectionManager dBConnection = DBConnectionManager.getInstance("DBConnection");
// -- =============== Original SQL ===============
// update Holding set Quantity = :pHolding.Quantity
// where CustomerName=:pHolding.CustomerName and
// StockName=:pHolding.StockName
// on session DBConnection
// -- ============================================
String qq_SQL = "update Holding set Quantity = ? " +
"where CustomerName=? and " +
"StockName=? ";
Object[] qq_SQLParams = new Object[] {
new Integer(pHolding.getQuantity()),
pHolding.getCustomerName(),
pHolding.getStockName()
};
dBConnection.getTemplate().update(qq_SQL, qq_SQLParams);
}
} // end class CustDBMgr
// c Pass 2 Conversion Time: 390 milliseconds