incubator-stonehenge-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From shan...@apache.org
Subject svn commit: r769245 [2/2] - in /incubator/stonehenge/trunk/stocktrader/wsas: business_service/src/org/apache/stonehenge/stocktrader/services/ common/src/org/apache/stonehenge/stocktrader/dal/ common/src/org/apache/stonehenge/stocktrader/mssql/ common/s...
Date Tue, 28 Apr 2009 05:15:25 GMT
Modified: incubator/stonehenge/trunk/stocktrader/wsas/common/src/org/apache/stonehenge/stocktrader/mssql/MSSQLOrderDAO.java
URL: http://svn.apache.org/viewvc/incubator/stonehenge/trunk/stocktrader/wsas/common/src/org/apache/stonehenge/stocktrader/mssql/MSSQLOrderDAO.java?rev=769245&r1=769244&r2=769245&view=diff
==============================================================================
--- incubator/stonehenge/trunk/stocktrader/wsas/common/src/org/apache/stonehenge/stocktrader/mssql/MSSQLOrderDAO.java (original)
+++ incubator/stonehenge/trunk/stocktrader/wsas/common/src/org/apache/stonehenge/stocktrader/mssql/MSSQLOrderDAO.java Tue Apr 28 05:15:22 2009
@@ -82,8 +82,7 @@
 		int accountId = -1;
 
 		try {
-			getAccountIdStat = sqlConnection
-					.prepareStatement(SQL_GET_ACCOUNTID_ORDER);
+			getAccountIdStat = sqlConnection.prepareStatement(SQL_GET_ACCOUNTID_ORDER);
 			getAccountIdStat.setInt(1, order.getOrderID());
 
 			ResultSet rs = getAccountIdStat.executeQuery();
@@ -98,9 +97,7 @@
 				logger.debug("", e);
 			}
 		} catch (SQLException e) {
-			throw new DAOException(
-					"Exception is thrown when selecting the accountID from order entries where order ID :"
-							+ order.getOrderID(), e);
+			throw new DAOException("Exception is thrown when selecting the accountID from order entries where order ID :" + order.getOrderID(), e);
 
 		} finally {
 			if (getAccountIdStat != null) {
@@ -117,15 +114,12 @@
 			PreparedStatement insertHoldingStat = null;
 
 			try {
-				insertHoldingStat = sqlConnection
-						.prepareStatement(SQL_INSERT_HOLDING);
+				insertHoldingStat = sqlConnection.prepareStatement(SQL_INSERT_HOLDING);
 				insertHoldingStat.setBigDecimal(1, order.getPrice());
 				// C# - insertHolding.setFloat(1, (float) order.getQuantity());
 				insertHoldingStat.setDouble(2, order.getQuantity());
-				Calendar openDate = (order.getOpenDate() != null) ? order
-						.getOpenDate() : Calendar.getInstance();
-				insertHoldingStat.setDate(3, StockTraderUtility
-						.convertToSqlDate(openDate));
+				Calendar openDate = (order.getOpenDate() != null) ? order.getOpenDate() : Calendar.getInstance();
+				insertHoldingStat.setDate(3, StockTraderUtility.convertToSqlDate(openDate));
 				insertHoldingStat.setInt(4, order.getAccountId());
 				insertHoldingStat.setString(5, order.getSymbol());
 
@@ -142,9 +136,7 @@
 				return holdingId;
 
 			} catch (SQLException e) {
-				throw new DAOException(
-						"An exception is thrown during an insertion of a holding entry",
-						e);
+				throw new DAOException("An exception is thrown during an insertion of a holding entry", e);
 
 			} finally {
 				if (insertHoldingStat != null) {
@@ -162,22 +154,18 @@
 	public void updateHolding(int holdingId, double quantity)
 			throws DAOException {
 		if (logger.isDebugEnabled()) {
-			logger.debug("OrderDAO.updateHolding()\nHolding ID :" + holdingId
-					+ "\nQuantity :" + quantity);
+			logger.debug("OrderDAO.updateHolding()\nHolding ID :" + holdingId + "\nQuantity :" + quantity);
 		}
 
 		PreparedStatement updateHoldingStat = null;
 		try {
-			updateHoldingStat = sqlConnection
-					.prepareStatement(SQL_UPDATE_HOLDING);
+			updateHoldingStat = sqlConnection.prepareStatement(SQL_UPDATE_HOLDING);
 			updateHoldingStat.setDouble(1, quantity);
 			updateHoldingStat.setInt(2, holdingId);
 			updateHoldingStat.executeUpdate();
 
 		} catch (SQLException e) {
-			throw new DAOException(
-					"An exception is thrown during an updation of holding entry",
-					e);
+			throw new DAOException("An exception is thrown during an updation of holding entry", e);
 		} finally {
 			if (updateHoldingStat != null) {
 				try {
@@ -196,15 +184,12 @@
 
 		PreparedStatement deleteHoldingStat = null;
 		try {
-			deleteHoldingStat = sqlConnection
-					.prepareStatement(SQL_DELETE_HOLDING);
+			deleteHoldingStat = sqlConnection.prepareStatement(SQL_DELETE_HOLDING);
 			deleteHoldingStat.setInt(1, holdingId);
 			deleteHoldingStat.execute();
 
 		} catch (SQLException e) {
-			throw new DAOException(
-					"An exception is thrown during deletion of a holding entry",
-					e);
+			throw new DAOException("An exception is thrown during deletion of a holding entry", e);
 		} finally {
 			if (deleteHoldingStat != null) {
 				try {
@@ -219,8 +204,7 @@
 	public CustomHoldingBean getHoldingForUpdate(int orderId)
 			throws DAOException {
 		if (logger.isDebugEnabled()) {
-			logger.debug("HoldingDataModel.getHoldingForUpdate()\nOrder ID :"
-					+ orderId);
+			logger.debug("HoldingDataModel.getHoldingForUpdate()\nOrder ID :" + orderId);
 		}
 		DAOFactory fac = MSSQLDAOFactory.getInstance();
 		CustomerDAO customerDAO = fac.getCustomerDAO();
@@ -231,8 +215,7 @@
 		CustomHoldingBean holding = null;
 		PreparedStatement selectHoldingStat = null;
 		try {
-			selectHoldingStat = sqlConnection
-					.prepareStatement(SQL_SELECT_HOLDING);
+			selectHoldingStat = sqlConnection.prepareStatement(SQL_SELECT_HOLDING);
 			selectHoldingStat.setInt(1, holdingId);
 			ResultSet rs = selectHoldingStat.executeQuery();
 			if (rs.next()) {
@@ -255,9 +238,7 @@
 				}
 			}
 		} catch (SQLException e) {
-			throw new DAOException(
-					"An Exception is thrown during selecting a holding entry",
-					e);
+			throw new DAOException("An Exception is thrown during selecting a holding entry", e);
 		} finally {
 			if (selectHoldingStat != null) {
 				try {
@@ -273,9 +254,7 @@
 	public void updateAccountBalance(int accountId, BigDecimal total)
 			throws DAOException {
 		if (logger.isDebugEnabled()) {
-			logger
-					.debug("OrderDAO.updateAccountBalance(int,BigDecimal)\nAccount ID :"
-							+ accountId + "\nTotal :" + total);
+			logger.debug("OrderDAO.updateAccountBalance(int,BigDecimal)\nAccount ID :" + accountId + "\nTotal :" + total);
 		}
 		DAOFactory fac = MSSQLDAOFactory.getInstance();
 		CustomerDAO customerDAO = fac.getCustomerDAO();
@@ -285,9 +264,7 @@
 	public void updateStockPriceVolume(double quantity, CustomQuoteBean quote)
 			throws DAOException {
 		if (logger.isDebugEnabled()) {
-			logger
-					.debug("OrderDAO.updateStockPriceVolume(double,QuatedataModle)\nQuantity :"
-							+ quantity + "\nQuote\nSymbol" + quote.getSymbol());
+			logger.debug("OrderDAO.updateStockPriceVolume(double,QuatedataModle)\nQuantity :" + quantity + "\nQuote\nSymbol" + quote.getSymbol());
 		}
 		DAOFactory fac = MSSQLDAOFactory.getInstance();
 		MarketSummaryDAO marketSummaryDAO = fac.getMarketSummaryDAO();
@@ -297,15 +274,13 @@
 	public void updateOrder(CustomOrderBean order) throws DAOException {
 		PreparedStatement updateHoldingStat = null;
 		try {
-			updateHoldingStat = sqlConnection
-					.prepareStatement(SQL_UPDATE_ORDER);
+			updateHoldingStat = sqlConnection.prepareStatement(SQL_UPDATE_ORDER);
 			updateHoldingStat.setDouble(1, order.getQuantity());
 			updateHoldingStat.setInt(2, order.getOrderID());
 			updateHoldingStat.executeUpdate();
 
 		} catch (SQLException e) {
-			throw new DAOException(
-					"An Exception is thrown during updating a holding entry", e);
+			throw new DAOException("An Exception is thrown during updating a holding entry", e);
 		} finally {
 			if (updateHoldingStat != null) {
 				try {
@@ -343,7 +318,6 @@
 
 		} catch (SQLException e) {
 			throw new DAOException("", e);
-
 		} finally {
 			if (closeOrderStat != null) {
 				try {
@@ -355,16 +329,20 @@
 		}
 	}
 
-	public CustomOrderBean createOrder(String userID, String symbol,
-			String orderType, double quantity, int holdingID)
-			throws DAOException {
+	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);
+		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;
@@ -400,7 +378,6 @@
 			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 = ?

Added: incubator/stonehenge/trunk/stocktrader/wsas/common/src/org/apache/stonehenge/stocktrader/mysql/AbstractMySQLDAO.java
URL: http://svn.apache.org/viewvc/incubator/stonehenge/trunk/stocktrader/wsas/common/src/org/apache/stonehenge/stocktrader/mysql/AbstractMySQLDAO.java?rev=769245&view=auto
==============================================================================
--- incubator/stonehenge/trunk/stocktrader/wsas/common/src/org/apache/stonehenge/stocktrader/mysql/AbstractMySQLDAO.java (added)
+++ incubator/stonehenge/trunk/stocktrader/wsas/common/src/org/apache/stonehenge/stocktrader/mysql/AbstractMySQLDAO.java Tue Apr 28 05:15:22 2009
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.stonehenge.stocktrader.mysql;
+
+import org.apache.stonehenge.stocktrader.dal.DAOException;
+import java.sql.Connection;
+import java.sql.SQLException;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stonehenge.stocktrader.dal.DAOException;
+
+public class AbstractMySQLDAO {
+
+	private static final Log logger = LogFactory.getLog(AbstractMySQLDAO.class);
+
+	protected Connection sqlConnection;
+
+	private int previousTransactionIsolation;
+
+	public AbstractMySQLDAO(Connection sqlConnection) throws DAOException {
+		this.sqlConnection = sqlConnection;
+	}
+
+	public void beginTransaction() throws DAOException {
+		logger.debug("AbstractMSSQLDAO.beginTransaction()");
+		try {
+			sqlConnection.setAutoCommit(false);
+			previousTransactionIsolation = sqlConnection.getTransactionIsolation();
+			sqlConnection.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
+		} catch (SQLException e) {
+			e.printStackTrace();
+			logger.debug("", e);
+			throw new DAOException("Exception was thrown during the start of transaction", e);
+		}
+	}
+
+	public void commitTransaction() throws DAOException {
+		logger.debug("AbstractMSSQLDAO.commitTransaction()");
+		try {
+			sqlConnection.commit();
+			sqlConnection.setAutoCommit(true);
+			sqlConnection.setTransactionIsolation(previousTransactionIsolation);
+		} catch (SQLException e) {
+			throw new DAOException("Exception is thrown during the commit of transaction", e);
+		}
+	}
+
+	public void rollbackTransaction() throws DAOException {
+		logger.debug("AbstractMySQLDAO.rollbackTransaction()");
+		try {
+			sqlConnection.rollback();
+			sqlConnection.setAutoCommit(true);
+			sqlConnection.setTransactionIsolation(previousTransactionIsolation);
+		} catch (SQLException e) {
+			throw new DAOException("Exception is thrown during the rollback of transaction", e);
+
+		}
+	}
+
+	public void close() throws DAOException {
+		try {
+			sqlConnection.close();
+		} catch (SQLException e) {
+			throw new DAOException("", e);
+		}
+	}
+}

Added: incubator/stonehenge/trunk/stocktrader/wsas/common/src/org/apache/stonehenge/stocktrader/mysql/MySQLCustomerDAO.java
URL: http://svn.apache.org/viewvc/incubator/stonehenge/trunk/stocktrader/wsas/common/src/org/apache/stonehenge/stocktrader/mysql/MySQLCustomerDAO.java?rev=769245&view=auto
==============================================================================
--- incubator/stonehenge/trunk/stocktrader/wsas/common/src/org/apache/stonehenge/stocktrader/mysql/MySQLCustomerDAO.java (added)
+++ incubator/stonehenge/trunk/stocktrader/wsas/common/src/org/apache/stonehenge/stocktrader/mysql/MySQLCustomerDAO.java Tue Apr 28 05:15:22 2009
@@ -0,0 +1,605 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.stonehenge.stocktrader.mysql;
+
+import java.math.BigDecimal;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.List;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stonehenge.stocktrader.CustomAccountBean;
+import org.apache.stonehenge.stocktrader.CustomAccountProfileBean;
+import org.apache.stonehenge.stocktrader.CustomHoldingBean;
+import org.apache.stonehenge.stocktrader.CustomOrderBean;
+import org.apache.stonehenge.stocktrader.mysql.AbstractMySQLDAO;
+import org.apache.stonehenge.stocktrader.dal.CustomerDAO;
+import org.apache.stonehenge.stocktrader.dal.DAOException;
+import org.apache.stonehenge.stocktrader.util.StockTraderUtility;
+
+public class MySQLCustomerDAO extends AbstractMySQLDAO implements CustomerDAO {
+    private static final Log logger = LogFactory.getLog(MySQLCustomerDAO.class);
+
+    private static final String SQL_DEBIT_ACCOUNT = "UPDATE account SET balance= balance - ? WHERE accountid = ?";
+    private static final String SQL_SELECT_HOLDING_LOCK = "SELECT h.account_accountid, h.holdingid, h.quantity, h.purchaseprice, h.purchasedate, h.quote_symbol FROM holding as h INNER JOIN orders as o on h.holdingid = o.holding_holdingid WHERE (o.orderid = ?)";
+    private static final String SQL_SELECT_HOLDING_NOLOCK = "SELECT account_accountid, quantity, purchaseprice, purchasedate, quote_symbol FROM holding WHERE holdingid = ? AND account_accountid = (SELECT accountid FROM account WHERE profile_userid = ?)";
+    private static final String SQL_SELECT_CUSTOMER_PROFILE_BY_USERID = "SELECT userid, password, fullname, address, email, creditcard FROM accountprofile WHERE userid = ?";
+    private static final String SQL_UPDATE_CUSTOMER_LOGIN = "UPDATE account SET logincount = logincount + 1, lastlogin = now() where profile_userid = ?";
+    private static final String SQL_SELECT_CUSTOMER_LOGIN = "SELECT accountid, creationdate, openbalance, logoutcount, balance, lastlogin, logincount FROM account WHERE profile_userid = ?";
+    private static final String SQL_UPDATE_LOGOUT = "UPDATE account SET logoutcount = logoutcount + 1 WHERE profile_userid = ?";
+    private static final String SQL_SELECT_GET_CUSTOMER_BY_USERID = "SELECT account.ACCOUNTID, account.PROFILE_USERID, account.CREATIONDATE, account.OPENBALANCE, account.LOGOUTCOUNT, account.BALANCE, account.LASTLOGIN, account.LOGINCOUNT FROM account WHERE account.PROFILE_USERID = ?";
+    private static final String SQL_SELECT_ORDERS_BY_ID = " o.orderid, o.ordertype, o.orderstatus, o.opendate, o.completiondate, o.quantity, o.price, o.orderfee, o.quote_symbol FROM orders o WHERE o.account_accountid = (SELECT a.accountid FROM account a WHERE a.profile_userid = ?) ORDER BY o.orderid DESC";
+    private static final String SQL_SELECT_CLOSED_ORDERS = "SELECT orderid, ordertype, orderstatus, completiondate, opendate, quantity, price, orderfee, quote_symbol FROM orders WHERE account_accountid = (SELECT accountid FROM account WHERE profile_userid = ?) AND orderstatus = 'closed'";
+    private static final String SQL_UPDATE_CLOSED_ORDERS = "UPDATE orders SET orderstatus = 'completed' WHERE orderstatus = 'closed' AND account_accountid = (SELECT accountid FROM account WHERE profile_userid = ?)";
+    private static final String SQL_INSERT_ACCOUNT_PROFILE = "INSERT INTO accountprofile VALUES (?, ?, ?, ?, ?, ?)";
+    private static final String SQL_INSERT_ACCOUNT = "INSERT INTO account (creationdate, openbalance, logoutcount, balance, lastlogin, logincount, profile_userid, accountid) VALUES (now(), ?, ?, ?, ?, ?, ?, null); SELECT LAST_INSERT_ID();";
+    private static final String SQL_UPDATE_ACCOUNT_PROFILE = "UPDATE accountprofile SET address = ?, password = ?, email = ?, creditcard = ?, fullname = ? WHERE userid = ?";
+    private static final String SQL_SELECT_HOLDINGS = "SELECT holdingid, quantity, purchaseprice, purchasedate, quote_symbol, account_accountid FROM holding WHERE account_accountid = (SELECT accountid FROM account WHERE profile_userid = ?) ORDER BY holdingid DESC";
+
+    public MySQLCustomerDAO(Connection sqlConnection) throws DAOException {
+        super(sqlConnection);
+    }
+
+    public CustomHoldingBean getHoldingForUpdate(int orderId) throws DAOException {
+        if (logger.isDebugEnabled()) {
+            logger.debug("MySQLCustomerDAO.getHoldingForUpdate(int)\nOrder ID :" + orderId);
+        }
+
+        CustomHoldingBean holding = null;
+        PreparedStatement selectHoldingLockStat = null;
+        try {
+            selectHoldingLockStat = sqlConnection.prepareStatement(SQL_SELECT_HOLDING_LOCK);
+            selectHoldingLockStat.setInt(1, orderId);
+            ResultSet rs = selectHoldingLockStat.executeQuery();
+            if (rs.next()) {
+                try {
+                    holding = new CustomHoldingBean(
+                            rs.getInt(1),
+                            rs.getInt(2),
+                            rs.getDouble(3),
+                            rs.getBigDecimal(4),
+                            StockTraderUtility.convertToCalendar(rs.getDate(5)),
+                            rs.getString(6));
+                    return holding;
+                } finally {
+                    try {
+                        rs.close();
+                    } catch (SQLException e) {
+                        logger.debug("", e);
+                    }
+                }
+            }
+        } catch (SQLException e) {
+            throw new DAOException("Exception is thrown when selecting the holding entry for order ID :" + orderId, e);
+        } finally {
+            if (selectHoldingLockStat != null) {
+                try {
+                    selectHoldingLockStat.close();
+                } catch (SQLException e) {
+                    logger.debug("", e);
+                }
+            }
+        }
+        return holding;
+    }
+
+    public CustomHoldingBean getHolding(String userId, int holdingID) throws DAOException {
+        if (logger.isDebugEnabled()) {
+            logger.debug("MSSQLCustomerDAO.getHolding(String,int)\nUserID :" + userId + "\nOrder ID :" + holdingID);
+        }
+        CustomHoldingBean holding = null;
+        PreparedStatement selectHoldingNoLockStat = null;
+        try {
+            selectHoldingNoLockStat = sqlConnection.prepareStatement(SQL_SELECT_HOLDING_NOLOCK);
+            selectHoldingNoLockStat.setInt(0, holdingID);
+            selectHoldingNoLockStat.setString(1, userId);
+
+            ResultSet rs = selectHoldingNoLockStat.executeQuery();
+            if (rs.next()) {
+                try {
+                    holding = new CustomHoldingBean(
+                            rs.getInt(1),
+                            rs.getInt(2),
+                            rs.getDouble(3),
+                            rs.getBigDecimal(4),
+                            StockTraderUtility.convertToCalendar(rs.getDate(5)),
+                            rs.getString(6));
+                    return holding;
+                } finally {
+                    try {
+                        rs.close();
+                    } catch (SQLException e) {
+                        logger.debug("", e);
+                    }
+                }
+            }
+        } catch (SQLException e) {
+            logger.debug("", e);
+            throw new DAOException("Exception is thrown when selecting the holding entry for userID :" + userId + " and orderID :" + holdingID, e);
+
+        } finally {
+            if (selectHoldingNoLockStat != null) {
+                try {
+                    selectHoldingNoLockStat.close();
+                } catch (SQLException e) {
+                    logger.debug("", e);
+                }
+            }
+        }
+        return holding;
+    }
+
+    public void updateAccountBalance(int accountId, BigDecimal total) throws DAOException {
+        if (logger.isDebugEnabled()) {
+            logger.debug("MySQLCustomerDAO.updateAccoutBalance(int,BigDecimal)\n Account ID :" + accountId + "\nTotal :" + total);
+        }
+        PreparedStatement debitAccountStat = null;
+        try {
+            debitAccountStat = sqlConnection.prepareStatement(SQL_DEBIT_ACCOUNT);
+            debitAccountStat.setBigDecimal(1, total);
+            debitAccountStat.setInt(2, accountId);
+            debitAccountStat.executeUpdate();
+
+        } catch (SQLException e) {
+            throw new DAOException("Excpetion is thrown when updating the account balance for accountID :" + accountId + " total :" + total, e);
+        } finally {
+            if (debitAccountStat != null) {
+                try {
+                    debitAccountStat.close();
+                } catch (SQLException e) {
+                    logger.debug("", e);
+                }
+            }
+        }
+    }
+
+    public CustomAccountBean login(String userId, String password) throws DAOException {
+        PreparedStatement selectCustomerProfileByUserId = null;
+        PreparedStatement updateCustomerLogin = null;
+        PreparedStatement selectCustomerLogin = null;
+        try {
+            selectCustomerProfileByUserId = sqlConnection.prepareStatement(SQL_SELECT_CUSTOMER_PROFILE_BY_USERID);
+            selectCustomerProfileByUserId.setString(1, userId);
+            ResultSet customerProfileRS = selectCustomerProfileByUserId.executeQuery();
+            if (customerProfileRS.next()) {
+                try {
+                    String userPassword = customerProfileRS.getString(2);
+                    if (userPassword.equals(password)) {
+                        try {
+                            updateCustomerLogin = sqlConnection.prepareStatement(SQL_UPDATE_CUSTOMER_LOGIN);
+                            updateCustomerLogin.setString(1, userId);
+                            updateCustomerLogin.executeUpdate();
+                            selectCustomerLogin = sqlConnection.prepareStatement(SQL_SELECT_CUSTOMER_LOGIN);
+                            selectCustomerLogin.setString(1, userId);
+                            ResultSet rs = selectCustomerLogin.executeQuery();
+                            if (rs.next()) {
+                                try {
+                                    CustomAccountBean accountData = new CustomAccountBean(
+                                            rs.getInt(1),
+                                            userId,
+                                            StockTraderUtility.convertToCalendar(rs.getDate(2)),
+                                            rs.getBigDecimal(3),
+                                            rs.getInt(4),
+                                            rs.getBigDecimal(5),
+                                            StockTraderUtility.convertToCalendar(rs.getDate(6)),
+                                            rs.getInt(7) + 1);
+                                    return accountData;
+                                } finally {
+                                    try {
+                                        rs.close();
+                                    } catch (SQLException e) {
+                                        logger.debug("", e);
+                                    }
+                                }
+                            }
+                        } catch (SQLException e) {
+                            throw new DAOException("", e);
+                        } finally {
+                            if (updateCustomerLogin != null) {
+                                try {
+                                    updateCustomerLogin.close();
+                                } catch (SQLException e) {
+                                    logger.debug("", e);
+                                }
+                            }
+                            if (selectCustomerLogin != null) {
+                                try {
+                                    selectCustomerLogin.close();
+                                } catch (SQLException e) {
+                                    logger.debug("", e);
+                                }
+                            }
+                        }
+                    }
+                } finally {
+                    try {
+                        customerProfileRS.close();
+                    } catch (SQLException e) {
+                        logger.debug("", e);
+                    }
+                }
+            }
+
+        } catch (SQLException e) {
+            throw new DAOException("", e);
+        } finally {
+            if (selectCustomerProfileByUserId != null) {
+                try {
+                    selectCustomerProfileByUserId.close();
+                } catch (SQLException e) {
+                    logger.debug("", e);
+                }
+            }
+        }
+        return null;
+    }
+
+    public void logoutUser(String userId) throws DAOException {
+        PreparedStatement updateLogout = null;
+        try {
+            updateLogout = sqlConnection.prepareStatement(SQL_UPDATE_LOGOUT);
+            updateLogout.setString(1, userId);
+            updateLogout.executeUpdate();
+        } catch (SQLException e) {
+            throw new DAOException("", e);
+        } finally {
+            if (updateLogout != null) {
+                try {
+                    updateLogout.close();
+                } catch (SQLException e) {
+                    logger.debug("", e);
+                }
+            }
+        }
+    }
+
+    public CustomAccountBean getCustomerByUserId(String userId) throws DAOException {
+        PreparedStatement getCustomerByUserId = null;
+
+        try {
+            getCustomerByUserId = sqlConnection.prepareStatement(SQL_SELECT_GET_CUSTOMER_BY_USERID);
+            getCustomerByUserId.setString(1, userId);
+            ResultSet rs = getCustomerByUserId.executeQuery();
+            if (rs.next()) {
+                try {
+                    CustomAccountBean bean = new CustomAccountBean(
+                            rs.getInt(1),
+                            rs.getString(2),
+                            StockTraderUtility.convertToCalendar(rs.getDate(3)),
+                            rs.getBigDecimal(4),
+                            rs.getInt(5),
+                            rs.getBigDecimal(6),
+                            StockTraderUtility.convertToCalendar(rs.getDate(7)),
+                            rs.getInt(8));
+                    return bean;
+                } finally {
+                    try {
+                        rs.close();
+                    } catch (SQLException e) {
+                        logger.debug("", e);
+                    }
+                }
+            }
+        } catch (SQLException e) {
+            throw new DAOException("", e);
+        } finally {
+            if (getCustomerByUserId != null) {
+                try {
+                    getCustomerByUserId.close();
+                } catch (SQLException e) {
+                    logger.debug("", e);
+                }
+            }
+        }
+        return null;
+    }
+
+    public CustomAccountProfileBean getAccountProfileData(String userId) throws DAOException {
+
+        PreparedStatement customerProfileByUserId = null;
+        try {
+            customerProfileByUserId = sqlConnection.prepareStatement(SQL_SELECT_CUSTOMER_PROFILE_BY_USERID);
+            customerProfileByUserId.setString(1, userId);
+            ResultSet rs = customerProfileByUserId.executeQuery();
+            if (rs.next()) {
+                try {
+                    CustomAccountProfileBean accountProfileDataBean = new CustomAccountProfileBean(
+                            rs.getString(1),
+                            rs.getString(2),
+                            rs.getString(3),
+                            rs.getString(4),
+                            rs.getString(5),
+                            rs.getString(6));
+                    return accountProfileDataBean;
+                } finally {
+                    try {
+                        rs.close();
+                    } catch (SQLException e) {
+                        logger.debug("", e);
+                    }
+                }
+            }
+        } catch (SQLException e) {
+            throw new DAOException("", e);
+        } finally {
+            if (customerProfileByUserId != null) {
+                try {
+                    customerProfileByUserId.close();
+                } catch (SQLException e) {
+                    logger.debug("", e);
+                }
+            }
+        }
+        return null;
+    }
+
+    public List<CustomOrderBean> getOrders(String userId, boolean top, int maxTop, int maxDefault) throws DAOException {
+        PreparedStatement selectOrdersById = null;
+        try {
+            String sqlQuery;
+            if (top) {
+                sqlQuery = "SELECT " + SQL_SELECT_ORDERS_BY_ID + " LIMIT " + maxTop;
+            } else {
+                sqlQuery = "SELECT " + SQL_SELECT_ORDERS_BY_ID + " LIMIT " + maxDefault;
+            }
+            selectOrdersById = sqlConnection.prepareStatement(sqlQuery);
+            selectOrdersById.setString(1, userId);
+            ResultSet rs = selectOrdersById.executeQuery();
+            List<CustomOrderBean> orders = new ArrayList<CustomOrderBean>();
+
+            try {
+                while (rs.next()) {
+                    int orderId = rs.getInt(1);
+                    Calendar openDate = StockTraderUtility.convertToCalendar(rs.getDate(4));
+                    Calendar completionDate = null;
+                    try {
+                        if (rs.getDate(5) != null) {
+                            completionDate = StockTraderUtility.convertToCalendar(rs.getDate(5));
+                        } else {
+                            completionDate = Calendar.getInstance();
+                            completionDate.setTimeInMillis(0);
+                        }
+                    } catch (SQLException e) {
+                        logger.debug("", e);
+                        completionDate = Calendar.getInstance();
+                        completionDate.setTimeInMillis(0);
+                    }
+
+                    CustomOrderBean orderBean = new CustomOrderBean(
+                            orderId,
+                            rs.getString(2),
+                            rs.getString(3),
+                            openDate,
+                            completionDate,
+                            rs.getDouble(6),
+                            rs.getBigDecimal(7),
+                            rs.getBigDecimal(8),
+                            rs.getString(9));
+                    orders.add(orderBean);
+                }
+
+            } finally {
+                try {
+                    rs.close();
+                } catch (SQLException e) {
+                    logger.debug("", e);
+                }
+            }
+            return orders;
+
+        } catch (SQLException e) {
+            throw new DAOException("", e);
+        } finally {
+            if (selectOrdersById != null) {
+                try {
+                    selectOrdersById.close();
+                } catch (SQLException e) {
+                    logger.debug("", e);
+                }
+            }
+        }
+    }
+
+    public List<CustomOrderBean> getClosedOrders(String userId) throws DAOException {
+        PreparedStatement selectClosedOrders = null;
+        PreparedStatement updateClosedOrders = null;
+        try {
+            selectClosedOrders = sqlConnection.prepareStatement(SQL_SELECT_CLOSED_ORDERS);
+            selectClosedOrders.setString(1, userId);
+            ResultSet rs = selectClosedOrders.executeQuery();
+            List<CustomOrderBean> closedOrders = new ArrayList<CustomOrderBean>();
+
+            try {
+                while (rs.next()) {
+                    int orderId = rs.getInt(1);
+                    Calendar openDate = StockTraderUtility.convertToCalendar(rs.getDate(4));
+                    Calendar completionDate = null;
+                    try {
+                        completionDate = StockTraderUtility.convertToCalendar(rs.getDate(5));
+                    } catch (SQLException e) {
+                        logger.debug("", e);
+                        completionDate = Calendar.getInstance();
+                        completionDate.setTimeInMillis(0);
+                    }
+                    CustomOrderBean closedOrderBean = new CustomOrderBean(
+                            orderId,
+                            rs.getString(2),
+                            rs.getString(3),
+                            openDate,
+                            completionDate,
+                            rs.getDouble(6),
+                            rs.getBigDecimal(7),
+                            rs.getBigDecimal(8),
+                            rs.getString(9));
+                    closedOrderBean.setOrderStatus(StockTraderUtility.ORDER_STATUS_CLOSED);
+                    closedOrders.add(closedOrderBean);
+                }
+            } finally {
+                try {
+                    rs.close();
+                } catch (SQLException e) {
+                    logger.debug("", e);
+                }
+            }
+
+            if (!closedOrders.isEmpty()) {
+                updateClosedOrders = sqlConnection.prepareStatement(SQL_UPDATE_CLOSED_ORDERS);
+                updateClosedOrders.setString(1, userId);
+                updateClosedOrders.executeUpdate();
+            }
+
+            return closedOrders;
+        } catch (SQLException e) {
+            throw new DAOException("", e);
+        } finally {
+            if (selectClosedOrders != null) {
+                try {
+                    selectClosedOrders.close();
+                } catch (SQLException e) {
+                    logger.debug("", e);
+                }
+            }
+            if (updateClosedOrders != null) {
+                try {
+                    selectClosedOrders.close();
+                } catch (SQLException e) {
+                    logger.debug("", e);
+                }
+            }
+
+        }
+    }
+
+    public void insertAccountProfile(CustomAccountProfileBean accountProfileBean) throws DAOException {
+        PreparedStatement insertAccountProfile = null;
+        try {
+            insertAccountProfile = sqlConnection.prepareStatement(SQL_INSERT_ACCOUNT_PROFILE);
+            insertAccountProfile.setString(1, accountProfileBean.getAddress());
+            insertAccountProfile.setString(2, accountProfileBean.getPassword());
+            insertAccountProfile.setString(3, accountProfileBean.getUserID());
+            insertAccountProfile.setString(4, accountProfileBean.getEmail());
+            insertAccountProfile.setString(5, accountProfileBean.getCreditCard());
+            insertAccountProfile.setString(6, accountProfileBean.getFullName());
+            insertAccountProfile.executeUpdate();
+        } catch (SQLException e) {
+            throw new DAOException("", e);
+        } finally {
+            if (insertAccountProfile != null) {
+                try {
+                    insertAccountProfile.close();
+                } catch (SQLException e) {
+                    logger.debug("", e);
+                }
+            }
+        }
+    }
+
+    public void insertAccount(CustomAccountBean accountBean) throws DAOException {
+        PreparedStatement insertAccount = null;
+        try {
+            insertAccount = sqlConnection.prepareStatement(SQL_INSERT_ACCOUNT);
+            insertAccount.setBigDecimal(1, accountBean.getOpenBalance());
+            insertAccount.setInt(2, accountBean.getLogoutCount());
+            insertAccount.setBigDecimal(3, accountBean.getBalance());
+            insertAccount.setDate(4, StockTraderUtility.convertToSqlDate(accountBean.getLastLogin()));
+            insertAccount.setInt(5, accountBean.getLoginCount());
+            insertAccount.setString(6, accountBean.getUserID());
+            insertAccount.executeUpdate();
+
+        } catch (SQLException e) {
+            throw new DAOException("", e);
+
+        } finally {
+            if (insertAccount != null) {
+                try {
+                    insertAccount.close();
+                } catch (SQLException e) {
+                    logger.debug("", e);
+                }
+            }
+        }
+    }
+
+    public CustomAccountProfileBean update(CustomAccountProfileBean customerAccountProfile) throws DAOException {
+        PreparedStatement updateAccountProfile = null;
+        try {
+            updateAccountProfile = sqlConnection.prepareStatement(SQL_UPDATE_ACCOUNT_PROFILE);
+            updateAccountProfile.setString(1, customerAccountProfile.getAddress());
+            updateAccountProfile.setString(2, customerAccountProfile.getPassword());
+            updateAccountProfile.setString(3, customerAccountProfile.getEmail());
+            updateAccountProfile.setString(4, customerAccountProfile.getCreditCard());
+            updateAccountProfile.setString(5, customerAccountProfile.getFullName());
+            updateAccountProfile.setString(6, customerAccountProfile.getUserID());
+            updateAccountProfile.executeUpdate();
+            return customerAccountProfile;
+        } catch (SQLException e) {
+            throw new DAOException("", e);
+        } finally {
+            if (updateAccountProfile != null) {
+                try {
+                    updateAccountProfile.close();
+                } catch (SQLException e) {
+                    logger.debug("", e);
+                }
+            }
+        }
+    }
+
+    public List<CustomHoldingBean> getHoldings(String userID) throws DAOException {
+        PreparedStatement selectHoldings = null;
+        try {
+            selectHoldings = sqlConnection.prepareStatement(SQL_SELECT_HOLDINGS);
+            selectHoldings.setString(1, userID);
+            ResultSet rs = selectHoldings.executeQuery();
+            List<CustomHoldingBean> holdings = new ArrayList<CustomHoldingBean>();
+            try {
+                while (rs.next()) {
+                    CustomHoldingBean holding = new CustomHoldingBean(
+                            rs.getInt(1),
+                            rs.getDouble(2),
+                            rs.getBigDecimal(3),
+                            StockTraderUtility.convertToCalendar(rs.getDate(4)),
+                            rs.getString(5),
+                            rs.getInt(6));
+                    holdings.add(holding);
+                }
+            } finally {
+                try {
+                    rs.close();
+                } catch (SQLException e) {
+                    logger.debug("", e);
+                }
+            }
+            return holdings;
+        } catch (SQLException e) {
+            throw new DAOException("", e);
+        } finally {
+            if (selectHoldings != null) {
+                try {
+                    selectHoldings.close();
+                } catch (SQLException e) {
+                    logger.debug("", e);
+                }
+            }
+        }
+    }
+}

Added: incubator/stonehenge/trunk/stocktrader/wsas/common/src/org/apache/stonehenge/stocktrader/mysql/MySQLDAOFactory.java
URL: http://svn.apache.org/viewvc/incubator/stonehenge/trunk/stocktrader/wsas/common/src/org/apache/stonehenge/stocktrader/mysql/MySQLDAOFactory.java?rev=769245&view=auto
==============================================================================
--- incubator/stonehenge/trunk/stocktrader/wsas/common/src/org/apache/stonehenge/stocktrader/mysql/MySQLDAOFactory.java (added)
+++ incubator/stonehenge/trunk/stocktrader/wsas/common/src/org/apache/stonehenge/stocktrader/mysql/MySQLDAOFactory.java Tue Apr 28 05:15:22 2009
@@ -0,0 +1,124 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.stonehenge.stocktrader.mysql;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stonehenge.stocktrader.dal.CustomerDAO;
+import org.apache.stonehenge.stocktrader.dal.DAOException;
+import org.apache.stonehenge.stocktrader.dal.DAOFactory;
+import org.apache.stonehenge.stocktrader.dal.MarketSummaryDAO;
+import org.apache.stonehenge.stocktrader.dal.OrderDAO;
+import org.apache.stonehenge.stocktrader.util.StockTraderUtility;
+
+public class MySQLDAOFactory extends DAOFactory {
+
+	private static Log logger = LogFactory.getLog(MySQLDAOFactory.class);
+	private static MySQLDAOFactory self = null;
+
+	private Connection sqlConnection = null;
+
+	private String connection = null;
+
+    static {
+		try {
+			Class.forName("com.mysql.jdbc.Driver");
+		} catch (ClassNotFoundException e) {
+			logger.warn("Unable to load DBDrive class", e);
+		}
+	}
+
+	public static DAOFactory getInstance() {
+		if (self == null) {
+			self = new MySQLDAOFactory();
+		}
+		return self;
+	}
+
+	private MySQLDAOFactory() {
+	}
+
+	public OrderDAO getOrderDAO() throws DAOException {
+		logger.debug("MySQLDAOFactory.getOrderDAO");
+		try {
+			OrderDAO orderDAO = new MySQLOrderDAO(getConnection());
+			return orderDAO;
+		} catch (SQLException e) {
+			logger.debug("", e);
+			throw new DAOException("Exception was thrown when instantiating MySQLOrderDAO object",e);
+		}
+	}
+
+	public CustomerDAO getCustomerDAO() throws DAOException {
+		logger.debug("MySQLDAOFactory.getCustomerDAO");
+		try {
+			CustomerDAO customerDAO = new MySQLCustomerDAO(getConnection());
+			return customerDAO;
+		} catch (SQLException e) {
+			logger.debug("", e);
+			throw new DAOException("Exception was thrown when instantiating a MySQLCustomerDAO",e);
+		}
+	}
+
+	public MarketSummaryDAO getMarketSummaryDAO() throws DAOException {
+		logger.debug("MySQLDAOFactory.getMarketSummaryDAO");
+		try {
+			MarketSummaryDAO marketSummaryDAO = new MySQLMarketSummaryDAO(getConnection());
+			return marketSummaryDAO;
+		} catch (SQLException e) {
+			logger.debug("", e);
+			throw new DAOException("Exception was thrown when instantiating a MarketSummaryDAO",e);
+		}
+	}
+
+	private String getConnectionString() {
+		if (connection == null) {
+            loadProperties();
+			if (prop == null) {
+				connection = "jdbc:mysql://localhost:3306/stocktraderdb?user=trade&password=yyy";
+			} else {
+				StringBuffer buf = new StringBuffer();
+				buf.append("jdbc:mysql://");
+				buf.append(prop.getProperty(PROP_DB_HOST));
+				buf.append(":" + prop.getProperty(PROP_DB_PORT));
+				buf.append("/" + prop.getProperty(PROP_DB_NAME));
+				buf.append("?user=" + prop.getProperty(PROP_DB_USER));
+				buf.append("&password=" + prop.getProperty(PROP_DB_PASSWORD));
+				connection = buf.toString();
+			}
+		}
+
+		if (logger.isDebugEnabled()) {
+			logger.debug("MySQLDAOFactory.getConnectionString()\nConnection :"+ connection);
+		}
+		return connection;
+	}
+
+	private Connection getConnection() throws SQLException {
+		if (sqlConnection == null || sqlConnection.isClosed()) {
+			sqlConnection = DriverManager.getConnection(getConnectionString());
+		}
+		return sqlConnection;
+	}
+}

Added: incubator/stonehenge/trunk/stocktrader/wsas/common/src/org/apache/stonehenge/stocktrader/mysql/MySQLMarketSummaryDAO.java
URL: http://svn.apache.org/viewvc/incubator/stonehenge/trunk/stocktrader/wsas/common/src/org/apache/stonehenge/stocktrader/mysql/MySQLMarketSummaryDAO.java?rev=769245&view=auto
==============================================================================
--- incubator/stonehenge/trunk/stocktrader/wsas/common/src/org/apache/stonehenge/stocktrader/mysql/MySQLMarketSummaryDAO.java (added)
+++ incubator/stonehenge/trunk/stocktrader/wsas/common/src/org/apache/stonehenge/stocktrader/mysql/MySQLMarketSummaryDAO.java Tue Apr 28 05:15:22 2009
@@ -0,0 +1,261 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.stonehenge.stocktrader.mysql;
+
+import org.apache.stonehenge.stocktrader.mssql.AbstractMSSQLDAO;
+import org.apache.stonehenge.stocktrader.dal.MarketSummaryDAO;
+import org.apache.stonehenge.stocktrader.dal.DAOException;
+import org.apache.stonehenge.stocktrader.CustomQuoteBean;
+import org.apache.stonehenge.stocktrader.CustomMarketSummaryBean;
+import org.apache.stonehenge.stocktrader.util.StockTraderUtility;
+import org.apache.stonehenge.stocktrader.util.StockTraderSQLUtil;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.math.BigDecimal;
+import java.util.List;
+import java.util.ArrayList;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+public class MySQLMarketSummaryDAO extends AbstractMSSQLDAO implements MarketSummaryDAO {
+	private static final Log logger = LogFactory.getLog(MySQLMarketSummaryDAO.class);
+
+	private static final String SQL_SELECT_QUOTE = "SELECT symbol, companyname, volume, price, open1, low, high, change1 FROM quote WHERE symbol = ?";
+	private static final String SQL_SELECT_QUOTE_NOLOCK = "SELECT symbol, companyname, volume, price, open1, low, high, change1 FROM quote WHERE symbol = ?";
+	private static final String SQL_UPDATE_STOCKPRICEVOLUME = "UPDATE quote SET price = ?, low = ?, high = ?, change1 = ? - open1, volume = volume + ? WHERE symbol = ?";
+
+	private static final String SQL_SELECT_MARKETSUMMARY_GAINERS = "SELECT symbol, companyname, volume, price, open1, low, high, change1 FROM quote WHERE symbol LIKE 's:1__' ORDER BY change1 DESC";
+	private static final String SQL_SELECT_MARKETSUMMARY_LOSERS = "SELECT symbol, companyname, volume, price, open1, low, high, change1 FROM quote WHERE symbol LIKE 's:1__' ORDER BY change1";
+	private static final String SQL_SELECT_MARKETSUMMARY_TSIA = "SELECT SUM(price) / COUNT(*) as tsia FROM quote WHERE symbol LIKE 's:1%'";
+	private static final String SQL_SELECT_MARKETSUMMARY_OPENTSIA = "SELECT SUM(open1) / COUNT(*) as opentsia FROM quote WHERE symbol LIKE 's:1%'";
+	private static final String SQL_SELECT_MARKETSUMMARY_VOLUME = "SELECT SUM(volume) FROM quote WHERE symbol LIKE 's:1%'";
+
+	public MySQLMarketSummaryDAO(Connection sqlConnection) throws DAOException {
+		super(sqlConnection);
+	}
+
+	public CustomQuoteBean getQuote(String symbol) throws DAOException {
+		if (logger.isDebugEnabled()) {
+			logger.debug("MarketSummaryDAO.getQouteForUpdate(String)\nSymbol :"+ symbol);
+		}
+		PreparedStatement selectQuote = null;
+		try {
+			selectQuote = sqlConnection.prepareStatement(SQL_SELECT_QUOTE_NOLOCK);
+			selectQuote.setString(1, symbol);
+			ResultSet rs = selectQuote.executeQuery();
+
+			try {
+				CustomQuoteBean quote = null;
+				if (rs.next()) {
+					quote = new CustomQuoteBean(
+                            rs.getString(1),
+                            rs.getString(2),
+                            rs.getDouble(3),
+							rs.getBigDecimal(4),
+                            rs.getBigDecimal(5),
+                            rs.getBigDecimal(6),
+                            rs.getBigDecimal(7),
+                            rs.getDouble(8));
+				}
+				return quote;
+			} finally {
+				try {
+					rs.close();
+				} catch (SQLException e) {
+					logger.debug("", e);
+				}
+			}
+		} catch (SQLException e) {
+			throw new DAOException("", e);
+		} finally {
+			try {
+				if (selectQuote != null) {
+					selectQuote.close();
+				}
+			} catch (SQLException e) {
+				logger.debug("", e);
+			}
+		}
+	}
+
+	public CustomQuoteBean getQuoteForUpdate(String symbol) throws DAOException {
+		if (logger.isDebugEnabled()) {
+			logger.debug("MarketSummaryDAO.getQouteForUpdate(String)\nSymbol :"+ symbol);
+		}
+		PreparedStatement qouteForUpdateStat = null;
+		try {
+			qouteForUpdateStat = sqlConnection.prepareStatement(SQL_SELECT_QUOTE);
+			CustomQuoteBean quote = null;
+
+			qouteForUpdateStat.setString(1, symbol);
+			ResultSet rs = qouteForUpdateStat.executeQuery();
+
+			if (rs.next()) {
+				quote = new CustomQuoteBean(
+                        rs.getString(1),
+                        rs.getString(2),
+						rs.getDouble(3),
+                        rs.getBigDecimal(4),
+                        rs.getBigDecimal(5),
+                        rs.getBigDecimal(6),
+                        rs.getBigDecimal(7),
+                        rs.getDouble(8));
+
+				try {
+					rs.close();
+				} catch (SQLException e) {
+					logger.debug("", e);
+				}
+				return quote;
+			} else {
+				throw new DAOException("No quote entry found");
+			}
+		} catch (SQLException e) {
+			throw new DAOException("", e);
+		} finally {
+			try {
+				if (qouteForUpdateStat != null) {
+					qouteForUpdateStat.close();
+				}
+			} catch (SQLException e) {
+				logger.debug("", e);
+			}
+		}
+	}
+
+	public void updateStockPriceVolume(double quantity, CustomQuoteBean quote) throws DAOException {
+		BigDecimal priceChangeFactor = StockTraderUtility.getRandomPriceChangeFactor(quote.getPrice());
+		BigDecimal newPrice = quote.getPrice().multiply(priceChangeFactor);
+
+		if (newPrice.compareTo(quote.getLow()) == -1) {
+			quote.setLow(newPrice);
+		}
+		if (newPrice.compareTo(quote.getHigh()) == 1) {
+			quote.setHigh(newPrice);
+		}
+
+		PreparedStatement updateStockPriceVolumeStat = null;
+		try {
+			updateStockPriceVolumeStat = sqlConnection.prepareStatement(SQL_UPDATE_STOCKPRICEVOLUME);
+			updateStockPriceVolumeStat.setBigDecimal(1, newPrice);
+			updateStockPriceVolumeStat.setBigDecimal(2, quote.getLow());
+			updateStockPriceVolumeStat.setBigDecimal(3, quote.getHigh());
+			updateStockPriceVolumeStat.setBigDecimal(4, newPrice);
+			updateStockPriceVolumeStat.setFloat(5, (float) quantity);
+			updateStockPriceVolumeStat.setString(6, quote.getSymbol());
+			updateStockPriceVolumeStat.executeUpdate();
+
+		} catch (SQLException e) {
+			throw new DAOException("", e);
+		} finally {
+			try {
+				if (updateStockPriceVolumeStat != null) {
+					updateStockPriceVolumeStat.close();
+				}
+			} catch (SQLException e) {
+				logger.debug("", e);
+			}
+		}
+	}
+
+	public CustomMarketSummaryBean getCustomMarketSummary() throws DAOException {
+		BigDecimal tSIA = (BigDecimal) StockTraderSQLUtil.executeScalarNoParm(SQL_SELECT_MARKETSUMMARY_TSIA, sqlConnection);
+		BigDecimal openTSIA = (BigDecimal) StockTraderSQLUtil.executeScalarNoParm(SQL_SELECT_MARKETSUMMARY_OPENTSIA, sqlConnection);
+		double totalVolume = ((Double) StockTraderSQLUtil.executeScalarNoParm(SQL_SELECT_MARKETSUMMARY_VOLUME, sqlConnection)).doubleValue();
+
+		List<CustomQuoteBean> topGainers = new ArrayList<CustomQuoteBean>();
+		PreparedStatement gainers = null;
+		try {
+			gainers = sqlConnection.prepareStatement(SQL_SELECT_MARKETSUMMARY_GAINERS);
+			ResultSet rs = gainers.executeQuery();
+
+			try {
+				for (int i = 0; rs.next() && i < 5; i++) {
+					CustomQuoteBean quote = new CustomQuoteBean(
+							rs.getString(1),
+                            rs.getString(2),
+                            rs.getDouble(3),
+							rs.getBigDecimal(4),
+                            rs.getBigDecimal(5),
+                            rs.getBigDecimal(6),
+                            rs.getBigDecimal(7),
+                            rs.getDouble(8));
+					topGainers.add(quote);
+				}
+			} finally {
+				try {
+					rs.close();
+				} catch (SQLException e) {
+					logger.debug("", e);
+				}
+			}
+		} catch (SQLException e) {
+			throw new DAOException("", e);
+		} finally {
+			if (gainers != null) {
+				try {
+					gainers.close();
+				} catch (SQLException e) {
+					logger.debug("", e);
+				}
+			}
+		}
+		List<CustomQuoteBean> topLosers = new ArrayList<CustomQuoteBean>();
+		PreparedStatement losers = null;
+		try {
+			losers = sqlConnection.prepareStatement(SQL_SELECT_MARKETSUMMARY_LOSERS);
+			ResultSet rs = losers.executeQuery();
+
+			try {
+				for (int i = 0; rs.next() && i < 5; i++) {
+					CustomQuoteBean quote = new CustomQuoteBean(
+							rs.getString(1),
+                            rs.getString(2),
+                            rs.getDouble(3),
+							rs.getBigDecimal(4),
+                            rs.getBigDecimal(5),
+                            rs.getBigDecimal(6),
+                            rs.getBigDecimal(7),
+                            rs.getDouble(8));
+					topLosers.add(quote);
+				}
+			} finally {
+				try {
+					rs.close();
+				} catch (SQLException e) {
+					logger.debug("", e);
+				}
+			}
+		} catch (SQLException e) {
+			throw new DAOException("", e);
+		} finally {
+			if (losers != null) {
+				try {
+					losers.close();
+				} catch (SQLException e) {
+					logger.debug("", e);
+				}
+			}
+		}
+		CustomMarketSummaryBean marketSummary = new CustomMarketSummaryBean(
+				tSIA, openTSIA, totalVolume, topGainers, topLosers);
+		return marketSummary;
+	}
+}

Added: incubator/stonehenge/trunk/stocktrader/wsas/common/src/org/apache/stonehenge/stocktrader/mysql/MySQLOrderDAO.java
URL: http://svn.apache.org/viewvc/incubator/stonehenge/trunk/stocktrader/wsas/common/src/org/apache/stonehenge/stocktrader/mysql/MySQLOrderDAO.java?rev=769245&view=auto
==============================================================================
--- incubator/stonehenge/trunk/stocktrader/wsas/common/src/org/apache/stonehenge/stocktrader/mysql/MySQLOrderDAO.java (added)
+++ incubator/stonehenge/trunk/stocktrader/wsas/common/src/org/apache/stonehenge/stocktrader/mysql/MySQLOrderDAO.java Tue Apr 28 05:15:22 2009
@@ -0,0 +1,419 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.stonehenge.stocktrader.mysql;
+
+import org.apache.stonehenge.stocktrader.mysql.AbstractMySQLDAO;
+import org.apache.stonehenge.stocktrader.mysql.MySQLDAOFactory;
+import org.apache.stonehenge.stocktrader.dal.*;
+import org.apache.stonehenge.stocktrader.CustomQuoteBean;
+import org.apache.stonehenge.stocktrader.CustomOrderBean;
+import org.apache.stonehenge.stocktrader.CustomHoldingBean;
+import org.apache.stonehenge.stocktrader.util.StockTraderUtility;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import java.sql.*;
+import java.util.Calendar;
+import java.math.BigDecimal;
+
+public class MySQLOrderDAO extends AbstractMySQLDAO implements OrderDAO {
+	private static Log logger = LogFactory.getLog(MySQLOrderDAO.class);
+
+	private static final String SQL_GET_ACCOUNTID_ORDER = "SELECT account_accountid FROM orders WHERE orderid = ?";
+	private static final String SQL_INSERT_HOLDING = "INSERT INTO holding (purchaseprice, quantity, purchasedate, account_accountid, quote_symbol, holdingid) VALUES (?, ?, ?, ?, ?, null)";
+	private static final String SQL_UPDATE_HOLDING = "UPDATE holding SET quantity =quantity - ? WHERE holdingid = ?";
+	private static final String SQL_DELETE_HOLDING = "DELETE FROM holding WHERE holdingid = ?";
+	private static final String SQL_SELECT_HOLDING = "SELECT holdingid, quantity, purchaseprice, purchasedate, quote_symbol, account_accountid FROM holding WHERE holdingid = ?";
+	private static final String SQL_UPDATE_ORDER = "UPDATE orders SET quantity = ? WHERE orderid = ?";
+	private static final String SQL_CLOSE_ORDER = "UPDATE orders SET orderstatus = ?, completiondate = now(), holding_holdingid = ?, price = ? WHERE orderid = ?";
+	private static final String SQL_GET_ACCOUNTID = "SELECT accountid FROM account  WHERE profile_userid = ?";
+    private static final String SQL_GET_LAST_INSERT_ID = "SELECT LAST_INSERT_ID()";
+
+	// CHECKME
+	private static final String SQL_INSERT_ORDER = "INSERT INTO orders (opendate, orderfee, price, quote_symbol, quantity, ordertype, orderstatus, account_accountid, holding_holdingid, orderid) VALUES (now(), ?, ?, ?, ?, ?, 'open', ?, ?, null)";
+	private static final String SQL_SELECT_ORDER_ID = "SELECT LAST_INSERT_ID() FROM orders WHERE orderfee = ? AND price = ? AND quote_symbol = ? AND quantity = ? AND ordertype = ? AND orderstatus = ? AND account_accountid = ? AND holding_holdingid = ?";
+
+	public MySQLOrderDAO(Connection sqlConnection) throws DAOException {
+		super(sqlConnection);
+	}
+
+	public CustomQuoteBean getQuoteForUpdate(String symbol) throws DAOException {
+		if (logger.isDebugEnabled()) {
+			logger.debug("OrderDAO.getQuoteForUpdate()\nSymbol :" + symbol);
+		}
+
+		DAOFactory fac = MySQLDAOFactory.getInstance();
+		MarketSummaryDAO marketSummaryDAO = fac.getMarketSummaryDAO();
+		return marketSummaryDAO.getQuoteForUpdate(symbol);
+	}
+
+	public int createHolding(CustomOrderBean order) throws DAOException {
+		if (logger.isDebugEnabled()) {
+			logger.debug("OrderDAO.createHolding(OrderDataModel)\nOrderID :"
+					+ order.getOrderID() + "\nOrderType :"
+					+ order.getOrderType() + "\nSymbol :" + order.getSymbol()
+					+ "\nQuantity :" + order.getQuantity() + "\nOrder Status :"
+					+ order.getOrderStatus() + "\nOrder Open Date :"
+					+ order.getOpenDate() + "\nCompletionDate :"
+					+ order.getCompletionDate());
+		}
+
+		PreparedStatement getAccountIdStat = null;
+		int accountId = -1;
+
+		try {
+			getAccountIdStat = sqlConnection.prepareStatement(SQL_GET_ACCOUNTID_ORDER);
+			getAccountIdStat.setInt(1, order.getOrderID());
+
+			ResultSet rs = getAccountIdStat.executeQuery();
+			if (rs.next()) {
+				accountId = Integer.parseInt(rs.getString(1));
+				order.setAccountId(accountId);
+			}
+
+			try {
+				rs.close();
+			} catch (Exception e) {
+				logger.debug("", e);
+			}
+		} catch (SQLException e) {
+			throw new DAOException("Exception is thrown when selecting the accountID from order entries where order ID :" + order.getOrderID(), e);
+
+		} finally {
+			if (getAccountIdStat != null) {
+				try {
+					getAccountIdStat.close();
+				} catch (Exception e) {
+					logger.debug("", e);
+				}
+			}
+		}
+
+		if (accountId != -1) {
+			int holdingId = -1;
+			PreparedStatement insertHoldingStat = null;
+
+			try {
+				insertHoldingStat = sqlConnection.prepareStatement(SQL_INSERT_HOLDING);
+				insertHoldingStat.setBigDecimal(1, order.getPrice());
+				insertHoldingStat.setDouble(2, order.getQuantity());
+				Calendar openDate = (order.getOpenDate() != null) ? order.getOpenDate() : Calendar.getInstance();
+				insertHoldingStat.setDate(3, StockTraderUtility.convertToSqlDate(openDate));
+				insertHoldingStat.setInt(4, order.getAccountId());
+				insertHoldingStat.setString(5, order.getSymbol());
+                insertHoldingStat.executeUpdate();
+
+				ResultSet rs = sqlConnection.prepareCall(SQL_GET_LAST_INSERT_ID).executeQuery();
+				if (rs.next()) {
+					holdingId = rs.getInt(1);
+				}
+
+				try {
+					rs.close();
+				} catch (Exception e) {
+					logger.debug("", e);
+				}
+				return holdingId;
+
+			} catch (SQLException e) {
+				throw new DAOException("An exception is thrown during an insertion of a holding entry",e);
+
+			} finally {
+				if (insertHoldingStat != null) {
+					try {
+						insertHoldingStat.close();
+					} catch (Exception e) {
+						logger.debug("", e);
+					}
+				}
+			}
+		}
+		return -1;
+	}
+
+	public void updateHolding(int holdingId, double quantity) throws DAOException {
+		if (logger.isDebugEnabled()) {
+			logger.debug("OrderDAO.updateHolding()\nHolding ID :" + holdingId + "\nQuantity :" + quantity);
+		}
+
+		PreparedStatement updateHoldingStat = null;
+		try {
+			updateHoldingStat = sqlConnection.prepareStatement(SQL_UPDATE_HOLDING);
+			updateHoldingStat.setDouble(1, quantity);
+			updateHoldingStat.setInt(2, holdingId);
+			updateHoldingStat.executeUpdate();
+
+		} catch (SQLException e) {
+			throw new DAOException("An exception is thrown during an updation of holding entry", e);
+		} finally {
+			if (updateHoldingStat != null) {
+				try {
+					updateHoldingStat.close();
+				} catch (Exception e) {
+					logger.debug("", e);
+				}
+			}
+		}
+	}
+
+	public void deleteHolding(int holdingId) throws DAOException {
+		if (logger.isDebugEnabled()) {
+			logger.debug("OrderDAO.deleteHolding()\nHolding ID :" + holdingId);
+		}
+
+		PreparedStatement deleteHoldingStat = null;
+		try {
+			deleteHoldingStat = sqlConnection.prepareStatement(SQL_DELETE_HOLDING);
+			deleteHoldingStat.setInt(1, holdingId);
+			deleteHoldingStat.execute();
+
+		} catch (SQLException e) {
+			throw new DAOException("An exception is thrown during deletion of a holding entry",e);
+		} finally {
+			if (deleteHoldingStat != null) {
+				try {
+					deleteHoldingStat.close();
+				} catch (SQLException e) {
+					logger.debug("", e);
+				}
+			}
+		}
+	}
+
+	public CustomHoldingBean getHoldingForUpdate(int orderId)
+			throws DAOException {
+		if (logger.isDebugEnabled()) {
+			logger.debug("HoldingDataModel.getHoldingForUpdate()\nOrder ID :"+ orderId);
+		}
+		DAOFactory fac = MySQLDAOFactory.getInstance();
+		CustomerDAO customerDAO = fac.getCustomerDAO();
+		return customerDAO.getHoldingForUpdate(orderId);
+	}
+
+	public CustomHoldingBean getHolding(int holdingId) throws DAOException {
+		CustomHoldingBean holding = null;
+		PreparedStatement selectHoldingStat = null;
+		try {
+			selectHoldingStat = sqlConnection.prepareStatement(SQL_SELECT_HOLDING);
+			selectHoldingStat.setInt(1, holdingId);
+			ResultSet rs = selectHoldingStat.executeQuery();
+			if (rs.next()) {
+				try {
+					holding = new CustomHoldingBean(
+							rs.getInt(1),
+							rs.getDouble(2),
+							rs.getBigDecimal(3),
+							StockTraderUtility.convertToCalendar(rs.getDate(4)),
+							rs.getString(5),
+							rs.getInt(6));
+					return holding;
+
+				} finally {
+					try {
+						rs.close();
+					} catch (Exception e) {
+						logger.debug("", e);
+					}
+				}
+			}
+		} catch (SQLException e) {
+			throw new DAOException("An Exception is thrown during selecting a holding entry",e);
+		} finally {
+			if (selectHoldingStat != null) {
+				try {
+					selectHoldingStat.close();
+				} catch (SQLException e) {
+					logger.debug("", e);
+				}
+			}
+		}
+		return holding;
+	}
+
+	public void updateAccountBalance(int accountId, BigDecimal total) throws DAOException {
+		if (logger.isDebugEnabled()) {
+			logger.debug("OrderDAO.updateAccountBalance(int,BigDecimal)\nAccount ID :" + accountId + "\nTotal :" + total);
+		}
+		DAOFactory fac = MySQLDAOFactory.getInstance();
+		CustomerDAO customerDAO = fac.getCustomerDAO();
+		customerDAO.updateAccountBalance(accountId, total);
+	}
+
+	public void updateStockPriceVolume(double quantity, CustomQuoteBean quote) throws DAOException {
+		if (logger.isDebugEnabled()) {
+			logger.debug("OrderDAO.updateStockPriceVolume(double,QuatedataModle)\nQuantity :" + quantity + "\nQuote\nSymbol" + quote.getSymbol());
+		}
+		DAOFactory fac = MySQLDAOFactory.getInstance();
+		MarketSummaryDAO marketSummaryDAO = fac.getMarketSummaryDAO();
+		marketSummaryDAO.updateStockPriceVolume(quantity, quote);
+	}
+
+	public void updateOrder(CustomOrderBean order) throws DAOException {
+		PreparedStatement updateHoldingStat = null;
+		try {
+			updateHoldingStat = sqlConnection.prepareStatement(SQL_UPDATE_ORDER);
+			updateHoldingStat.setDouble(1, order.getQuantity());
+			updateHoldingStat.setInt(2, order.getOrderID());
+			updateHoldingStat.executeUpdate();
+
+		} catch (SQLException e) {
+			throw new DAOException("An Exception is thrown during updating a holding entry", e);
+		} finally {
+			if (updateHoldingStat != null) {
+				try {
+					updateHoldingStat.close();
+				} catch (Exception e) {
+					logger.debug("", e);
+				}
+			}
+		}
+	}
+
+	public void closeOrder(CustomOrderBean order) throws DAOException {
+		if (logger.isDebugEnabled()) {
+			logger.debug("OrderDAO.closeOrder(OrderDataModel)\nOrderID :"
+					+ order.getOrderID() + "\nOrderType :"
+					+ order.getOrderType() + "\nSymbol :" + order.getSymbol()
+					+ "\nQuantity :" + order.getQuantity() + "\nOrder Status :"
+					+ order.getOrderStatus() + "\nOrder Open Date :"
+					+ order.getOpenDate() + "\nCompletionDate :"
+					+ order.getCompletionDate());
+		}
+
+		PreparedStatement closeOrderStat = null;
+		try {
+			closeOrderStat = sqlConnection.prepareStatement(SQL_CLOSE_ORDER);
+			closeOrderStat.setString(1, StockTraderUtility.ORDER_STATUS_CLOSED);
+			if (StockTraderUtility.ORDER_TYPE_SELL.equals(order.getOrderType())) {
+				closeOrderStat.setNull(2, Types.INTEGER);
+			} else {
+				closeOrderStat.setInt(2, order.getHoldingId());
+			}
+			closeOrderStat.setBigDecimal(3, order.getPrice());
+			closeOrderStat.setInt(4, order.getOrderID());
+			closeOrderStat.executeUpdate();
+
+		} catch (SQLException e) {
+			throw new DAOException("", e);
+
+		} finally {
+			if (closeOrderStat != null) {
+				try {
+					closeOrderStat.close();
+				} catch (Exception e) {
+					logger.debug("", e);
+				}
+			}
+		}
+	}
+
+	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);
+					}
+				}
+			}
+		} catch (SQLException e) {
+			throw new DAOException("", e);
+		} finally {
+			if (insertOrder != null) {
+				try {
+					insertOrder.close();
+				} catch (SQLException e) {
+					logger.debug("", e);
+				}
+			}
+			if (selectOrderID != null) {
+				try {
+					selectOrderID.close();
+				} catch (SQLException e) {
+					logger.debug("", e);
+				}
+			}
+		}
+		return order;
+	}
+}
+

Modified: incubator/stonehenge/trunk/stocktrader/wsas/common/src/org/apache/stonehenge/stocktrader/util/StockTraderUtility.java
URL: http://svn.apache.org/viewvc/incubator/stonehenge/trunk/stocktrader/wsas/common/src/org/apache/stonehenge/stocktrader/util/StockTraderUtility.java?rev=769245&r1=769244&r2=769245&view=diff
==============================================================================
--- incubator/stonehenge/trunk/stocktrader/wsas/common/src/org/apache/stonehenge/stocktrader/util/StockTraderUtility.java (original)
+++ incubator/stonehenge/trunk/stocktrader/wsas/common/src/org/apache/stonehenge/stocktrader/util/StockTraderUtility.java Tue Apr 28 05:15:22 2009
@@ -29,7 +29,7 @@
 	
 	public static final String TRADE_ORDER_SERVICE_PROPERTY_FILE = "config-svc.properties";
 	public static final String TRADE_ORDER_SERVICE_SECURITY_FILE = "security-policy.xml";
-	public static final String MSSQL_DB_PROPERRTIES_FILE = "mssql-db.properties";
+	public static final String DB_PROPERRTIES_FILE = "db.properties";
 	public static final String ORDER_TYPE_BUY = "buy";
 	public static final String ORDER_TYPE_SELL = "sell";
 	public static final String ORDER_TYPE_SELL_ENHANCED = "sellEnhanced";

Modified: incubator/stonehenge/trunk/stocktrader/wsas/order_processor/src/org/apache/stonehenge/stocktrader/service/OrderProcessManager.java
URL: http://svn.apache.org/viewvc/incubator/stonehenge/trunk/stocktrader/wsas/order_processor/src/org/apache/stonehenge/stocktrader/service/OrderProcessManager.java?rev=769245&r1=769244&r2=769245&view=diff
==============================================================================
--- incubator/stonehenge/trunk/stocktrader/wsas/order_processor/src/org/apache/stonehenge/stocktrader/service/OrderProcessManager.java (original)
+++ incubator/stonehenge/trunk/stocktrader/wsas/order_processor/src/org/apache/stonehenge/stocktrader/service/OrderProcessManager.java Tue Apr 28 05:15:22 2009
@@ -25,24 +25,20 @@
 import org.apache.stonehenge.stocktrader.CustomHoldingBean;
 import org.apache.stonehenge.stocktrader.CustomOrderBean;
 import org.apache.stonehenge.stocktrader.CustomQuoteBean;
-import org.apache.stonehenge.stocktrader.HoldingBean;
-import org.apache.stonehenge.stocktrader.QuoteBean;
 import org.apache.stonehenge.stocktrader.dal.DAOException;
 import org.apache.stonehenge.stocktrader.dal.DAOFactory;
-import org.apache.stonehenge.stocktrader.mssql.MSSQLOrderDAO;
+import org.apache.stonehenge.stocktrader.dal.OrderDAO;
 import org.apache.stonehenge.stocktrader.util.StockTraderUtility;
 
 public class OrderProcessManager {
-	private static final Log logger = LogFactory
-			.getLog(OrderProcessManager.class);
+	private static final Log logger = LogFactory.getLog(OrderProcessManager.class);
 
-	private MSSQLOrderDAO orderDAO = null;
+	private OrderDAO orderDAO = null;
 
 	public void processAndCompleteOrder(CustomOrderBean order)
 			throws DAOException {
 		if (logger.isDebugEnabled()) {
-			logger
-					.debug("ProcessOrder.processAndCompleteOrder(OrderDataModel) \nOrderID :"
+			logger.debug("ProcessOrder.processAndCompleteOrder(OrderDataModel) \nOrderID :"
 							+ order.getOrderID()
 							+ "\nOrderType :"
 							+ order.getOrderType()
@@ -59,10 +55,9 @@
 		}
 
 		try {
-			DAOFactory factory = DAOFactory
-					.getFacotry(DAOFactory.MS_SQL_FACTORY);
+			DAOFactory factory = DAOFactory.getFacotry();
 
-			orderDAO = (MSSQLOrderDAO) factory.getOrderDAO();
+			orderDAO = factory.getOrderDAO();
 			orderDAO.beginTransaction();
 
 			BigDecimal total = null;
@@ -71,9 +66,7 @@
 			CustomQuoteBean quote = orderDAO.getQuoteForUpdate(order.getSymbol());
 			if (quote == null) {
 				if (logger.isDebugEnabled()) {
-					logger
-							.debug("Unable to locate a quote entry for the symbol :"
-									+ order.getSymbol());
+					logger.debug("Unable to locate a quote entry for the symbol :" + order.getSymbol());
 				}
 				return;
 			}
@@ -82,8 +75,7 @@
 
 			if (StockTraderUtility.ORDER_TYPE_BUY.equals(order.getOrderType())) {
 				holdingId = orderDAO.createHolding(order);
-				BigDecimal orderQuantity = BigDecimal.valueOf(order
-						.getQuantity());
+				BigDecimal orderQuantity = BigDecimal.valueOf(order.getQuantity());
 				BigDecimal orderPrice = order.getPrice();
 				total = orderQuantity.multiply(orderPrice);
 
@@ -92,15 +84,13 @@
 					total = total.add(orderFee);
 				}
 
-			} else if (StockTraderUtility.ORDER_TYPE_SELL.equals(order
-					.getOrderType())) {
+			} else if (StockTraderUtility.ORDER_TYPE_SELL.equals(order.getOrderType())) {
 				holdingId = sellHolding(order);
 				if (holdingId == -1) {
 					return;
 				}
 
-				BigDecimal orderQuantity = BigDecimal.valueOf(-1
-						* order.getQuantity());
+				BigDecimal orderQuantity = BigDecimal.valueOf(-1 * order.getQuantity());
 				BigDecimal orderPrice = order.getPrice();
 				total = orderQuantity.multiply(orderPrice);
 
@@ -150,9 +140,7 @@
 
 		if (holding == null) {
 			// TODO : DAOException ..
-			throw new RuntimeException(
-					"Unable to locate a holding entry for orderID :"
-							+ order.getOrderID());
+			throw new RuntimeException("Unable to locate a holding entry for orderID :" + order.getOrderID());
 		}
 		order.setAccountId(holding.getAccountID());
 

Modified: incubator/stonehenge/trunk/stocktrader/wsas/order_processor/src/org/apache/stonehenge/stocktrader/service/OrderProcessorImpl.java
URL: http://svn.apache.org/viewvc/incubator/stonehenge/trunk/stocktrader/wsas/order_processor/src/org/apache/stonehenge/stocktrader/service/OrderProcessorImpl.java?rev=769245&r1=769244&r2=769245&view=diff
==============================================================================
--- incubator/stonehenge/trunk/stocktrader/wsas/order_processor/src/org/apache/stonehenge/stocktrader/service/OrderProcessorImpl.java (original)
+++ incubator/stonehenge/trunk/stocktrader/wsas/order_processor/src/org/apache/stonehenge/stocktrader/service/OrderProcessorImpl.java Tue Apr 28 05:15:22 2009
@@ -32,8 +32,7 @@
 import com.ibm.websphere.samples.trade.OrderDataBean;
 
 public class OrderProcessorImpl extends OrderProcessorSkeleton {
-	private static final Log logger = LogFactory
-			.getLog(OrderProcessorImpl.class);
+	private static final Log logger = LogFactory.getLog(OrderProcessorImpl.class);
 	// OrderProcessManager is the controller for managing order processing.
 	private final OrderProcessManager orderProcessManager = new OrderProcessManager();
 

Modified: incubator/stonehenge/trunk/stocktrader/wsas/order_processor/src/org/apache/stonehenge/stocktrader/service/OrderProcessorServicePasswordCB.java
URL: http://svn.apache.org/viewvc/incubator/stonehenge/trunk/stocktrader/wsas/order_processor/src/org/apache/stonehenge/stocktrader/service/OrderProcessorServicePasswordCB.java?rev=769245&r1=769244&r2=769245&view=diff
==============================================================================
--- incubator/stonehenge/trunk/stocktrader/wsas/order_processor/src/org/apache/stonehenge/stocktrader/service/OrderProcessorServicePasswordCB.java (original)
+++ incubator/stonehenge/trunk/stocktrader/wsas/order_processor/src/org/apache/stonehenge/stocktrader/service/OrderProcessorServicePasswordCB.java Tue Apr 28 05:15:22 2009
@@ -25,8 +25,7 @@
 import org.apache.ws.security.WSPasswordCallback;
 
 public class OrderProcessorServicePasswordCB implements CallbackHandler {
-	public void handle(Callback[] callbacks) throws IOException,
-			UnsupportedCallbackException {
+	public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
 		for (int i = 0; i < callbacks.length; i++) {
 			WSPasswordCallback pwcb = (WSPasswordCallback) callbacks[i];
 			String id = pwcb.getIdentifer();

Added: incubator/stonehenge/trunk/stocktrader/wsas/resources/conf/db.properties
URL: http://svn.apache.org/viewvc/incubator/stonehenge/trunk/stocktrader/wsas/resources/conf/db.properties?rev=769245&view=auto
==============================================================================
--- incubator/stonehenge/trunk/stocktrader/wsas/resources/conf/db.properties (added)
+++ incubator/stonehenge/trunk/stocktrader/wsas/resources/conf/db.properties Tue Apr 28 05:15:22 2009
@@ -0,0 +1,30 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+org.apache.stonehenge.stocktrader.database.host=localhost
+org.apache.stonehenge.stocktrader.database.port=1433
+org.apache.stonehenge.stocktrader.database.db=StockTraderDB
+org.apache.stonehenge.stocktrader.database.user=trade
+org.apache.stonehenge.stocktrader.database.password=yyy
+org.apache.stonehenge.stocktrader.database.type=mssql
+
+
+
+#mysql
+#org.apache.stonehenge.stocktrader.database.port=3306
+#org.apache.stonehenge.stocktrader.database.type=mysql
+
+#mssql
+#org.apache.stonehenge.stocktrader.database.port=1433
+#org.apache.stonehenge.stocktrader.database.type=mssql



Mime
View raw message