public CustomOrderBean createOrder(String userID, String symbol, String orderType, double quantity, int holdingID) throws DAOException {
int orderID = 0;
Calendar minCalender = Calendar.getInstance();
minCalender.setTimeInMillis(0);
CustomOrderBean order = new CustomOrderBean(
orderID,
orderType,
StockTraderUtility.ORDER_STATUS_OPEN,
Calendar.getInstance(),
minCalender,
quantity,
BigDecimal.valueOf(1),
StockTraderUtility.getOrderFee(orderType),
symbol);
order.setHoldingId(holdingID);
PreparedStatement getAccountId = null;
try {
getAccountId = sqlConnection.prepareStatement(SQL_GET_ACCOUNTID);
getAccountId.setString(1, userID);
ResultSet rs = getAccountId.executeQuery();
if (rs.next()) {
order.setAccountId(rs.getInt(1));
}
} catch (SQLException e) {
} finally {
if (getAccountId != null) {
try {
getAccountId.close();
} catch (SQLException e) {
logger.debug("", e);
}
}
}
PreparedStatement insertOrder = null;
PreparedStatement selectOrderID = null;
try {
insertOrder = sqlConnection.prepareStatement(SQL_INSERT_ORDER);
insertOrder.setBigDecimal(1, order.getOrderFee());
insertOrder.setBigDecimal(2, order.getPrice());
insertOrder.setString(3, order.getSymbol());
insertOrder.setFloat(4, (float) order.getQuantity());
insertOrder.setString(5, order.getOrderType());
insertOrder.setInt(6, order.getAccountId());
insertOrder.setInt(7, order.getHoldingId());
insertOrder.executeUpdate();
selectOrderID = sqlConnection.prepareStatement(SQL_SELECT_ORDER_ID);
// ORDERFEE = ? AND PRICE = ? AND QUOTE_SYMBOL = ? AND QUANTITY = ?
// ORDERTYPE = ? ORDERSTATUS = ? AND ACCOUNT_ACCOUNTID = ?
// HOLDING_HOLDINGID = ?"
selectOrderID.setBigDecimal(1, order.getOrderFee());
selectOrderID.setBigDecimal(2, order.getPrice());
selectOrderID.setString(3, order.getSymbol());
selectOrderID.setDouble(4, order.getQuantity());
selectOrderID.setString(5, order.getOrderType());
selectOrderID.setString(6, "open");
selectOrderID.setInt(7, order.getAccountId());
selectOrderID.setInt(8, order.getHoldingId());
ResultSet rs = selectOrderID.executeQuery();
if (rs.next()) {
try {
order.setOrderID(rs.getInt(1));
} finally {
try {
rs.close();
} catch (SQLException e) {
logger.debug("", e);