+ order.getOrderStatus() + "\nOrder Open Date :"
+ order.getOpenDate() + "\nCompletionDate :"
+ order.getCompletionDate());
}
CustomHoldingBean holding = orderDAO.getHoldingForUpdate(order.getOrderID());
if (holding == null) {
// TODO : DAOException ..
throw new RuntimeException(
"Unable to locate a holding entry for orderID :"
+ order.getOrderID());
}
order.setAccountId(holding.getAccountID());
// There are three distinct business cases here, each needs different
// treatment:
// a) Quantity requested is less than total shares in the holding --
// update holding.
// b) Quantity requested is equal to total shares in the holding --
// delete holding.
// c) Quantity requested is greater than total shares in the holding --
// delete holding, update order table.
if (order.getQuantity() < holding.getQuantity()) {
orderDAO.updateHolding(holding.getHoldingID(), order.getQuantity());
} else if (holding.getQuantity() == order.getQuantity()) {
orderDAO.deleteHolding(holding.getHoldingID());
} else if (order.getQuantity() > holding.getQuantity()) {
// We now need to back-update the order record quantity to reflect
// fact not all shares originally requested were sold since the
// holding had less shares in it, perhaps due to other orders placed
// against that holding that completed before this one. So we will
// sell the remaining shares, but need to update the final order to
// reflect this.
orderDAO.deleteHolding(holding.getHoldingID());
order.setQuantity(holding.getQuantity());
order.setAccountId(holding.getAccountID());
orderDAO.updateOrder(order);
}
return holding.getHoldingID();
}