📄 trademanagementsessionfacadebean.java
字号:
}
}
} catch(FinderException ex) {
throw (new RemoteException("Finder Exception in get Portfolio : " +
ex.toString()));
} catch(DatabaseException ex) {
throw (new RemoteException("SQL Exception in get Portfolio : " +
ex.toString()));
}
Collection retColl = createNewCollection(pfValue, recordNumber, linesPerPage);
retColl.add(new Float(totalAssetValue));
// return the new collection created
return retColl;
}
/**
* This method calls the methods on the Entity Beans to get the Trade details
* corresponding to the input User Account Number and returns the details
* as a Collection.
*
* @param accountNumber Account Number
* @param recordNumber Record Number
* @param linesPerPage Lines Per Page
* @return The Collection of Trade Details for the input Account Number
* @exception RemoteException If error occurs while getting the details
* @since 1.0
*/
public Collection getTradeDetails(Integer accountNumber, String recordNumber,
int linesPerPage)
throws RemoteException {
Collection allTrades = new ArrayList();
Collection tdColl = null;
try {
// Find the User Account Entity for the input account number
UserAccountLocal userAccountLocal =
userAccountHomeLocal.findByPrimaryKey(accountNumber);
// Get the Collection of TradeDetails corresponding to the user account
tdColl = (Collection)userAccountLocal.getTradeDetails();
// Create an iterator for the above Collection
Iterator tradesIter = tdColl.iterator();
while(tradesIter.hasNext()) {
// If the iterator has more values, get the next tradedetails info
TradeDetailsLocal td = (TradeDetailsLocal)tradesIter.next();
String action = "Sold";
// Set the full expansion of action depending on the value
if(td.getAction().equals("B")) {
action = "Bought";
} else if(td.getAction().equals("T")) {
action = "Transferred";
}
// Add the TradeDetails information to a new collection
allTrades.add(new TradeDetailsInfo(td.getTradeId(), action,
td.getQuantity(), td.getTradeDate(),
td.getPrice(), td.getSymbol(),
td.getOrderType(), td.getStatus(),
td.getExchangeId()));
}
} catch(FinderException ex) {
throw (new RemoteException("Finder Exception in get trade details : " +
ex.toString()));
}
// return the new collection created
return createNewCollection(allTrades, recordNumber, linesPerPage);
}
/**
* This method calls the methods on the Entity Bean and returns the Trade
* details for the input trade id as a Value Object which reduces the
* network traffic between the client and the server.
*
* @param tradeId Trade Id
* @return The Trade Details information as a Value Object TradeDetailsInfo
* @exception RemoteException If error occurs while getting the details
* @since 1.0
*/
private TradeDetailsInfo getTradeDetailsInfo(Integer tradeId)
throws RemoteException {
TradeDetailsInfo tdInfo = null;
try {
// Find the Trade Details Entity for the input trade id
TradeDetailsLocal tradeDetailsLocal =
tradeDetailsHomeLocal.findByPrimaryKey(tradeId);
// Create a new object with the obtained Trade Details Entity
tdInfo = new TradeDetailsInfo(tradeDetailsLocal.getTradeId(),
tradeDetailsLocal.getAction(),
tradeDetailsLocal.getQuantity(),
tradeDetailsLocal.getTradeDate(),
tradeDetailsLocal.getPrice(),
tradeDetailsLocal.getSymbol(),
tradeDetailsLocal.getOrderType(),
tradeDetailsLocal.getStatus(),
tradeDetailsLocal.getExchangeId());
} catch(FinderException ex) {
throw (new RemoteException("Finder Exception in get trade details info : "
+ ex.toString()));
}
return tdInfo;
}
/**
* This method calls the methods on the Entity Bean to insert a new record
* in the PORTFOLIO table.
*
* @param accountNumber Account Number
* @param pfInfo Portfolio Information
* @return The Line Number of the new Portfolio record created
* @exception RemoteException If error occurs while adding Portfolio
* @since 1.0
*/
private Integer addPortfolio(Integer accountNumber,
PortfolioInfo pfInfo)
throws RemoteException {
Collection pfColl = null;
Integer nextLineNo = new Integer(0);
int rowCount = 0;
try {
// Find the User Account Entity for the input account number
UserAccountLocal userAccountLocal =
userAccountHomeLocal.findByPrimaryKey(accountNumber);
// Get the Collection of Portfolio corresponding to the user account
pfColl = (Collection)userAccountLocal.getPortfolio();
rowCount = pfColl.size();
// Next Line Number is the next row count
nextLineNo = new Integer(rowCount + 1);
// get the next portfolio id
Integer nextPortfolioId = tradeHelper.getNextID("PORTFOLIO_SEQ");
if(nextPortfolioId.intValue() == 0) {
throw (new CreateException("Unable to set Portfolio details, " +
"PORTFOLIO_SEQ not found : "));
}
// Create a new Portfolio Entity
PortfolioLocal portfolioLocal =
portfolioHomeLocal.create(accountNumber,
nextPortfolioId,
nextLineNo,
pfInfo.getQuantity(),
pfInfo.getPrice(),
pfInfo.getSymbol(),
pfInfo.getPurchaseDate(),
pfInfo.getPurchaseMode(),
pfInfo.getTradeId());
// add the entity to the new collection
pfColl.add(portfolioLocal);
// Set the collection to the User Account Entity
userAccountLocal.setPortfolio(pfColl);
} catch(FinderException ex) {
throw (new RemoteException("Finder Exception in Add Portfolio : " +
ex.toString()));
} catch(CreateException ex) {
throw (new RemoteException("Create Exception in Add Portfolio : " +
ex.toString()));
} catch(DatabaseException ex) {
throw (new RemoteException("SQL Exception in Add Portfolio : " +
ex.toString()));
}
return nextLineNo;
}
/**
* This method is used to update the quantity of stocks in the PORTFOLIO
* Table once some quantity or all the stocks are sold. This method is
* called when the user chooses to sell stocks.
*
* @param accountNumber Account Number
* @param pfInfo Portfolio Information
* @return String indicating the success of the update operation
* @exception RemoteException If error occurs while updating Portfolio
* @since 1.0
*/
private String updatePortfolio(Integer accountNumber,
PortfolioInfo pfInfo)
throws RemoteException {
Collection allPortfolio = new ArrayList();
Collection pfColl = null;
String retValue = "SUCCESS";
boolean found = false;
try {
// Find the User Account Entity for the input account number
UserAccountLocal userAccountLocal =
userAccountHomeLocal.findByPrimaryKey(accountNumber);
// Get the Collection of Portfolio corresponding to the user account
pfColl = (Collection)userAccountLocal.getPortfolio();
// Create an iterator for the above Collection
Iterator pfIter = pfColl.iterator();
boolean set = true;
while (pfIter.hasNext()) {
// If the iterator has more values, get the next portfolio information
PortfolioLocal pf = (PortfolioLocal)pfIter.next();
if (pf.getLineNo().equals(pfInfo.getLineNo())) {
found = true;
if (pf.getQuantity().intValue() >= pfInfo.getQuantity().intValue()) {
// Update the quantity of the line number
// which is in the input portfolio collection
int newQty = 0;
newQty = pf.getQuantity().intValue() -
pfInfo.getQuantity().intValue();
if (newQty == 0) {
pf.remove();
set = false;
} else {
pf.setQuantity(new Integer(newQty)); // Set the new quantity
}
} else {
retValue = "INSUFFICIENTQUANTITY";
}
}
if (set) {
allPortfolio.add(pf); // Add the record to the new collection
} else {
set = true;
}
}
// Set the collection to the User Account Entity
userAccountLocal.setPortfolio(allPortfolio);
} catch(FinderException ex) {
throw (new RemoteException("Finder Exception in update Portfolio : " +
ex.toString()));
} catch(RemoveException ex) {
throw (new RemoteException("Remove Exception in update Portfolio : " +
ex.toString()));
}
if (!found) {
retValue = "RECORDNOTFOUND";
}
return retValue;
}
/**
* This method is called while creating a new record in the TRADEDETAILS
* table. This is called whenever any 'Buy', 'Sell' or 'Transfer'
* transaction is carried out by a user. The new record is created for the
* input user account number with the input tradedetails information.
*
* @param accountNumber Account Number
* @param tdInfo Trade Details Information
* @return The Next Trade Id of the Trade Details record created.
* @exception RemoteException If error occurs while adding TradeDetails
* @since 1.0
*/
private Integer addTradeDetails(Integer accountNumber,
TradeDetailsInfo tdInfo)
throws RemoteException {
Collection tdColl = null;
Integer nextTradeId = new Integer(0);
try {
// Find the User Account Entity for the input account number
UserAccountLocal userAccountLocal =
userAccountHomeLocal.findByPrimaryKey(accountNumber);
// Get the Collection of TradeDetails corresponding to the user account
tdColl = (Collection)userAccountLocal.getTradeDetails();
// Get the next trade id number
nextTradeId = tradeHelper.getNextID("TRADE_SEQ");
Symbol s = tradeHelper.getSymbol(tdInfo.getSymbol());
// Create a new Trade Details entity
TradeDetailsLocal tradeDetailsLocal =
tradeDetailsHomeLocal.create(nextTradeId, accountNumber, tdInfo.getAction(),
tdInfo.getQuantity(), tdInfo.getTradeDate(),
tdInfo.getPrice(), tdInfo.getSymbol(),
tdInfo.getOrderType(), tdInfo.getStatus(),
new Integer(s.getExchangeid().intValue()));
// Add the Trade details Entity to the new collection
tdColl.add(tradeDetailsLocal);
// Set the collection to the User Account Entity
userAccountLocal.setTradeDetails(tdColl);
} catch(FinderException ex) {
throw (new RemoteException("Finder Exception in Add Trade Details : " +
ex.toString()));
} catch(CreateException ex) {
throw (new RemoteException("Create Exception in Add Trade Details : " +
ex.toString()));
} catch(DatabaseException ex) {
throw (new RemoteException("SQL Exception in Add Trade Details : " +
ex.toString()));
}
return nextTradeId;
}
/**
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -