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 [1/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
Author: shankar
Date: Tue Apr 28 05:15:22 2009
New Revision: 769245

URL: http://svn.apache.org/viewvc?rev=769245&view=rev
Log:
MySQL support for WSAS Stocktrader (Applying patch from STONEHENGE-40)

Added:
    incubator/stonehenge/trunk/stocktrader/wsas/common/src/org/apache/stonehenge/stocktrader/mysql/
    incubator/stonehenge/trunk/stocktrader/wsas/common/src/org/apache/stonehenge/stocktrader/mysql/AbstractMySQLDAO.java
    incubator/stonehenge/trunk/stocktrader/wsas/common/src/org/apache/stonehenge/stocktrader/mysql/MySQLCustomerDAO.java
    incubator/stonehenge/trunk/stocktrader/wsas/common/src/org/apache/stonehenge/stocktrader/mysql/MySQLDAOFactory.java
    incubator/stonehenge/trunk/stocktrader/wsas/common/src/org/apache/stonehenge/stocktrader/mysql/MySQLMarketSummaryDAO.java
    incubator/stonehenge/trunk/stocktrader/wsas/common/src/org/apache/stonehenge/stocktrader/mysql/MySQLOrderDAO.java
    incubator/stonehenge/trunk/stocktrader/wsas/resources/conf/db.properties
Removed:
    incubator/stonehenge/trunk/stocktrader/wsas/resources/conf/mssql-db.properties
Modified:
    incubator/stonehenge/trunk/stocktrader/wsas/business_service/src/org/apache/stonehenge/stocktrader/services/TradeConfigServiceClient.java
    incubator/stonehenge/trunk/stocktrader/wsas/business_service/src/org/apache/stonehenge/stocktrader/services/TradeOrderServiceClient.java
    incubator/stonehenge/trunk/stocktrader/wsas/business_service/src/org/apache/stonehenge/stocktrader/services/TradeOrderServiceClientPasswordCB.java
    incubator/stonehenge/trunk/stocktrader/wsas/business_service/src/org/apache/stonehenge/stocktrader/services/TradeServiceImpl.java
    incubator/stonehenge/trunk/stocktrader/wsas/business_service/src/org/apache/stonehenge/stocktrader/services/TraderServiceManager.java
    incubator/stonehenge/trunk/stocktrader/wsas/common/src/org/apache/stonehenge/stocktrader/dal/DAOFactory.java
    incubator/stonehenge/trunk/stocktrader/wsas/common/src/org/apache/stonehenge/stocktrader/dal/MarketSummaryDAO.java
    incubator/stonehenge/trunk/stocktrader/wsas/common/src/org/apache/stonehenge/stocktrader/dal/OrderDAO.java
    incubator/stonehenge/trunk/stocktrader/wsas/common/src/org/apache/stonehenge/stocktrader/mssql/AbstractMSSQLDAO.java
    incubator/stonehenge/trunk/stocktrader/wsas/common/src/org/apache/stonehenge/stocktrader/mssql/MSSQLCustomerDAO.java
    incubator/stonehenge/trunk/stocktrader/wsas/common/src/org/apache/stonehenge/stocktrader/mssql/MSSQLDAOFactory.java
    incubator/stonehenge/trunk/stocktrader/wsas/common/src/org/apache/stonehenge/stocktrader/mssql/MSSQLMarketSummaryDAO.java
    incubator/stonehenge/trunk/stocktrader/wsas/common/src/org/apache/stonehenge/stocktrader/mssql/MSSQLOrderDAO.java
    incubator/stonehenge/trunk/stocktrader/wsas/common/src/org/apache/stonehenge/stocktrader/util/StockTraderUtility.java
    incubator/stonehenge/trunk/stocktrader/wsas/order_processor/src/org/apache/stonehenge/stocktrader/service/OrderProcessManager.java
    incubator/stonehenge/trunk/stocktrader/wsas/order_processor/src/org/apache/stonehenge/stocktrader/service/OrderProcessorImpl.java
    incubator/stonehenge/trunk/stocktrader/wsas/order_processor/src/org/apache/stonehenge/stocktrader/service/OrderProcessorServicePasswordCB.java

Modified: incubator/stonehenge/trunk/stocktrader/wsas/business_service/src/org/apache/stonehenge/stocktrader/services/TradeConfigServiceClient.java
URL: http://svn.apache.org/viewvc/incubator/stonehenge/trunk/stocktrader/wsas/business_service/src/org/apache/stonehenge/stocktrader/services/TradeConfigServiceClient.java?rev=769245&r1=769244&r2=769245&view=diff
==============================================================================
--- incubator/stonehenge/trunk/stocktrader/wsas/business_service/src/org/apache/stonehenge/stocktrader/services/TradeConfigServiceClient.java (original)
+++ incubator/stonehenge/trunk/stocktrader/wsas/business_service/src/org/apache/stonehenge/stocktrader/services/TradeConfigServiceClient.java Tue Apr 28 05:15:22 2009
@@ -46,10 +46,8 @@
 	private TradeConfigServiceClient() throws IOException {
 		super();
 		// CHECKME .. there might be a better of doing this
-		ClassLoader cl = MessageContext.getCurrentMessageContext()
-				.getAxisService().getClassLoader();
-		InputStream is = cl
-				.getResourceAsStream(StockTraderUtility.TRADE_ORDER_SERVICE_PROPERTY_FILE);
+		ClassLoader cl = MessageContext.getCurrentMessageContext().getAxisService().getClassLoader();
+		InputStream is = cl.getResourceAsStream(StockTraderUtility.TRADE_ORDER_SERVICE_PROPERTY_FILE);
 		prop.load(is);
 	}
 

Modified: incubator/stonehenge/trunk/stocktrader/wsas/business_service/src/org/apache/stonehenge/stocktrader/services/TradeOrderServiceClient.java
URL: http://svn.apache.org/viewvc/incubator/stonehenge/trunk/stocktrader/wsas/business_service/src/org/apache/stonehenge/stocktrader/services/TradeOrderServiceClient.java?rev=769245&r1=769244&r2=769245&view=diff
==============================================================================
--- incubator/stonehenge/trunk/stocktrader/wsas/business_service/src/org/apache/stonehenge/stocktrader/services/TradeOrderServiceClient.java (original)
+++ incubator/stonehenge/trunk/stocktrader/wsas/business_service/src/org/apache/stonehenge/stocktrader/services/TradeOrderServiceClient.java Tue Apr 28 05:15:22 2009
@@ -44,10 +44,8 @@
 	private TradeOrderServiceClient() throws IOException {
 		super();
 		// CHECKME .. there might be a better of doing this
-		ClassLoader cl = MessageContext.getCurrentMessageContext()
-				.getAxisService().getClassLoader();
-		InputStream is = cl
-				.getResourceAsStream(StockTraderUtility.TRADE_ORDER_SERVICE_SECURITY_FILE);
+		ClassLoader cl = MessageContext.getCurrentMessageContext().getAxisService().getClassLoader();
+		InputStream is = cl.getResourceAsStream(StockTraderUtility.TRADE_ORDER_SERVICE_SECURITY_FILE);
 		securityPolicy = PolicyEngine.getPolicy(is);
 	}
 
@@ -59,11 +57,9 @@
 		return self;
 	}
 
-	public void SubmitOrderTrasactedQueue(CustomOrderBean order)
-			throws IOException {
+	public void SubmitOrderTrasactedQueue(CustomOrderBean order) throws IOException {
 		TradeOrderConfig config = geTradeOrderConfig();
-		OrderProcessorStub stub = new OrderProcessorStub(config
-				.getEndpointURL());
+		OrderProcessorStub stub = new OrderProcessorStub(config.getEndpointURL());
 		ServiceClient serviceClient = stub._getServiceClient();
 		serviceClient.getOptions().setProperty(HTTPConstants.CHUNKED,  Boolean.FALSE);
 		if (config.isSecure()) {
@@ -77,8 +73,7 @@
 	}
 
 	private TradeOrderConfig geTradeOrderConfig() throws IOException {
-		TradeConfigServiceClient client = TradeConfigServiceClient
-				.getInstance();
+		TradeConfigServiceClient client = TradeConfigServiceClient.getInstance();
 		return client.getTradeOrderConfig();
 	}
 

Modified: incubator/stonehenge/trunk/stocktrader/wsas/business_service/src/org/apache/stonehenge/stocktrader/services/TradeOrderServiceClientPasswordCB.java
URL: http://svn.apache.org/viewvc/incubator/stonehenge/trunk/stocktrader/wsas/business_service/src/org/apache/stonehenge/stocktrader/services/TradeOrderServiceClientPasswordCB.java?rev=769245&r1=769244&r2=769245&view=diff
==============================================================================
--- incubator/stonehenge/trunk/stocktrader/wsas/business_service/src/org/apache/stonehenge/stocktrader/services/TradeOrderServiceClientPasswordCB.java (original)
+++ incubator/stonehenge/trunk/stocktrader/wsas/business_service/src/org/apache/stonehenge/stocktrader/services/TradeOrderServiceClientPasswordCB.java Tue Apr 28 05:15:22 2009
@@ -26,8 +26,7 @@
 import org.apache.ws.security.WSPasswordCallback;
 
 public class TradeOrderServiceClientPasswordCB 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();

Modified: incubator/stonehenge/trunk/stocktrader/wsas/business_service/src/org/apache/stonehenge/stocktrader/services/TradeServiceImpl.java
URL: http://svn.apache.org/viewvc/incubator/stonehenge/trunk/stocktrader/wsas/business_service/src/org/apache/stonehenge/stocktrader/services/TradeServiceImpl.java?rev=769245&r1=769244&r2=769245&view=diff
==============================================================================
--- incubator/stonehenge/trunk/stocktrader/wsas/business_service/src/org/apache/stonehenge/stocktrader/services/TradeServiceImpl.java (original)
+++ incubator/stonehenge/trunk/stocktrader/wsas/business_service/src/org/apache/stonehenge/stocktrader/services/TradeServiceImpl.java Tue Apr 28 05:15:22 2009
@@ -77,8 +77,7 @@
 	public BuyResponse buy(Buy buy) {
 		CustomOrderBean order;
 		try {
-			order = mgr
-					.buy(buy.getUserID(), buy.getSymbol(), buy.getQuantity());
+			order = mgr.buy(buy.getUserID(), buy.getSymbol(), buy.getQuantity());
 		} catch (DAOException e) {
 			logger.debug("", e);
 			throw new RuntimeException(e);
@@ -101,12 +100,10 @@
 		return getAccountDataResponse;
 	}
 
-	public GetAccountProfileDataResponse getAccountProfileData(
-			GetAccountProfileData getAccountProfileData) {
+	public GetAccountProfileDataResponse getAccountProfileData(GetAccountProfileData getAccountProfileData) {
 		CustomAccountProfileBean accountProfileData;
 		try {
-			accountProfileData = mgr
-					.getAccountProfileData(getAccountProfileData.getUserID());
+			accountProfileData = mgr.getAccountProfileData(getAccountProfileData.getUserID());
 		} catch (DAOException e) {
 			logger.debug("", e);
 			throw new RuntimeException(e);
@@ -116,8 +113,7 @@
 		return response;
 	}
 
-	public GetClosedOrdersResponse getClosedOrders(
-			GetClosedOrders getClosedOrders) {
+	public GetClosedOrdersResponse getClosedOrders(GetClosedOrders getClosedOrders) {
 		List<CustomOrderBean> closedOrders;
 		try {
 			closedOrders = mgr.getClosedOrders(getClosedOrders.getUserID());
@@ -135,8 +131,7 @@
 	public GetHoldingResponse getHolding(GetHolding getHolding) {
 		CustomHoldingBean holding;
 		try {
-			holding = mgr.getHolding(getHolding.getUserID(), getHolding
-					.getHoldingID());
+			holding = mgr.getHolding(getHolding.getUserID(), getHolding.getHoldingID());
 		} catch (DAOException e) {
 			logger.debug("", e);
 			throw new RuntimeException(e);
@@ -161,8 +156,7 @@
 		return response;
 	}
 
-	public GetMarketSummaryResponse getMarketSummary(
-			GetMarketSummary getMarketSummary) {
+	public GetMarketSummaryResponse getMarketSummary(GetMarketSummary getMarketSummary) {
 		CustomMarketSummaryBean param;
 		try {
 			param = mgr.getMarketSummary();
@@ -251,10 +245,14 @@
 	public RegisterResponse register(Register register) {
 		CustomAccountBean param;
 		try {
-			param = mgr.register(register.getUserID(), register.getPassword(),
-					register.getFullname(), register.getAddress(), register
-							.getEmail(), register.getCreditcard(), register
-							.getOpenBalance());
+			param = mgr.register(
+                    register.getUserID(),
+                    register.getPassword(),
+					register.getFullname(),
+                    register.getAddress(),
+                    register.getEmail(),
+                    register.getCreditcard(),
+                    register.getOpenBalance());
 		} catch (DAOException e) {
 			logger.debug("", e);
 			throw new RuntimeException(e);
@@ -267,8 +265,7 @@
 	public SellResponse sell(Sell sell) {
 		CustomOrderBean param;
 		try {
-			param = mgr.sell(sell.getUserID(), sell.getHoldingID(), sell
-					.getOrderProcessingMode());
+			param = mgr.sell(sell.getUserID(), sell.getHoldingID(), sell.getOrderProcessingMode());
 		} catch (DAOException e) {
 			logger.debug("", e);
 			throw new RuntimeException(e);
@@ -281,8 +278,7 @@
 	public SellEnhancedResponse sellEnhanced(SellEnhanced sellEnhanced) {
 		CustomOrderBean param;
 		try {
-			param = mgr.sellEnhanced(sellEnhanced.getUserID(), sellEnhanced
-					.getHoldingID(), sellEnhanced.getQuantity());
+			param = mgr.sellEnhanced(sellEnhanced.getUserID(), sellEnhanced.getHoldingID(), sellEnhanced.getQuantity());
 		} catch (DAOException e) {
 			logger.debug("", e);
 			throw new RuntimeException(e);
@@ -292,10 +288,8 @@
 		return response;
 	}
 
-	public UpdateAccountProfileResponse updateAccountProfile(
-			UpdateAccountProfile updateAccountProfile) {
-		CustomAccountProfileBean accountProfile = new CustomAccountProfileBean(
-				updateAccountProfile.getProfileData());
+	public UpdateAccountProfileResponse updateAccountProfile(UpdateAccountProfile updateAccountProfile) {
+		CustomAccountProfileBean accountProfile = new CustomAccountProfileBean(updateAccountProfile.getProfileData());
 		CustomAccountProfileBean param;
 		try {
 			param = mgr.updateAccountProfile(accountProfile);

Modified: incubator/stonehenge/trunk/stocktrader/wsas/business_service/src/org/apache/stonehenge/stocktrader/services/TraderServiceManager.java
URL: http://svn.apache.org/viewvc/incubator/stonehenge/trunk/stocktrader/wsas/business_service/src/org/apache/stonehenge/stocktrader/services/TraderServiceManager.java?rev=769245&r1=769244&r2=769245&view=diff
==============================================================================
--- incubator/stonehenge/trunk/stocktrader/wsas/business_service/src/org/apache/stonehenge/stocktrader/services/TraderServiceManager.java (original)
+++ incubator/stonehenge/trunk/stocktrader/wsas/business_service/src/org/apache/stonehenge/stocktrader/services/TraderServiceManager.java Tue Apr 28 05:15:22 2009
@@ -20,8 +20,7 @@
 import java.math.BigDecimal;
 import java.util.Calendar;
 
-import java.util.List;
-
+import java.util.List;                
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.stonehenge.stocktrader.CustomAccountBean;
@@ -35,22 +34,19 @@
 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.mssql.MSSQLOrderDAO;
 import org.apache.stonehenge.stocktrader.util.StockTraderUtility;
 
 public class TraderServiceManager {
 
-	private static final Log logger = LogFactory
-			.getLog(TraderServiceManager.class);
+	private static final Log logger = LogFactory.getLog(TraderServiceManager.class);
 
 	private DAOFactory factory = null;
 
 	public TraderServiceManager() {
-		factory = DAOFactory.getFacotry(DAOFactory.MS_SQL_FACTORY);
+		factory = DAOFactory.getFacotry();
 	}
 
-	public CustomAccountBean login(String userId, String password)
-			throws DAOException {
+	public CustomAccountBean login(String userId, String password) throws DAOException {
 		CustomerDAO customerDAO = factory.getCustomerDAO();
 		return customerDAO.login(userId, password);
 	}
@@ -65,29 +61,22 @@
 		return customerDAO.getCustomerByUserId(userId);
 	}
 
-	public CustomAccountProfileBean getAccountProfileData(String userId)
-			throws DAOException {
+	public CustomAccountProfileBean getAccountProfileData(String userId) throws DAOException {
 		CustomerDAO customerDAO = factory.getCustomerDAO();
 		return customerDAO.getAccountProfileData(userId);
 	}
 
 	public List<CustomOrderBean> getOrders(String userId) throws DAOException {
 		CustomerDAO customerDAO = factory.getCustomerDAO();
-		return customerDAO.getOrders(userId, false,
-				StockTraderUtility.MAX_QUERY_TOP_ORDERS,
-				StockTraderUtility.MAX_QUERY_ORDERS);
+		return customerDAO.getOrders(userId, false, StockTraderUtility.MAX_QUERY_TOP_ORDERS, StockTraderUtility.MAX_QUERY_ORDERS);
 	}
 
-	public List<CustomOrderBean> getTopOrders(String userId)
-			throws DAOException {
+	public List<CustomOrderBean> getTopOrders(String userId) throws DAOException {
 		CustomerDAO customerDAO = factory.getCustomerDAO();
-		return customerDAO.getOrders(userId, true,
-				StockTraderUtility.MAX_QUERY_TOP_ORDERS,
-				StockTraderUtility.MAX_QUERY_ORDERS);
+		return customerDAO.getOrders(userId, true, StockTraderUtility.MAX_QUERY_TOP_ORDERS, StockTraderUtility.MAX_QUERY_ORDERS);
 	}
 
-	public List<CustomOrderBean> getClosedOrders(String userId)
-			throws DAOException {
+	public List<CustomOrderBean> getClosedOrders(String userId) throws DAOException {
 		CustomerDAO customerDAO = factory.getCustomerDAO();
 		return customerDAO.getClosedOrders(userId);
 	}
@@ -147,7 +136,7 @@
 
 	public CustomOrderBean placeOrder(String orderType, String userID,
 			int holdingID, String symbol, double quantity) throws DAOException {
-		MSSQLOrderDAO orderDAO = (MSSQLOrderDAO) factory.getOrderDAO();
+		OrderDAO orderDAO = factory.getOrderDAO();
 		CustomOrderBean order = null;
 		CustomHoldingBean holding = new CustomHoldingBean();
 		try {

Modified: incubator/stonehenge/trunk/stocktrader/wsas/common/src/org/apache/stonehenge/stocktrader/dal/DAOFactory.java
URL: http://svn.apache.org/viewvc/incubator/stonehenge/trunk/stocktrader/wsas/common/src/org/apache/stonehenge/stocktrader/dal/DAOFactory.java?rev=769245&r1=769244&r2=769245&view=diff
==============================================================================
--- incubator/stonehenge/trunk/stocktrader/wsas/common/src/org/apache/stonehenge/stocktrader/dal/DAOFactory.java (original)
+++ incubator/stonehenge/trunk/stocktrader/wsas/common/src/org/apache/stonehenge/stocktrader/dal/DAOFactory.java Tue Apr 28 05:15:22 2009
@@ -18,22 +18,66 @@
 package org.apache.stonehenge.stocktrader.dal;
 
 import org.apache.stonehenge.stocktrader.mssql.MSSQLDAOFactory;
+import org.apache.stonehenge.stocktrader.mysql.MySQLDAOFactory;
+import org.apache.stonehenge.stocktrader.util.StockTraderUtility;
+
+import java.util.Properties;
+import java.io.InputStream;
+import java.io.IOException;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.description.AxisService;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 public abstract class DAOFactory {
-	public static final int MS_SQL_FACTORY = 1;
+    public static final String PROP_DB_HOST = "org.apache.stonehenge.stocktrader.database.host";
+	public static final String PROP_DB_PORT = "org.apache.stonehenge.stocktrader.database.port";
+	public static final String PROP_DB_NAME = "org.apache.stonehenge.stocktrader.database.db";
+	public static final String PROP_DB_USER = "org.apache.stonehenge.stocktrader.database.user";
+	public static final String PROP_DB_PASSWORD = "org.apache.stonehenge.stocktrader.database.password";
+    public static final String PROP_DB_TYPE = "org.apache.stonehenge.stocktrader.database.type";
+
+    public static Properties prop = null;
 
 	public abstract CustomerDAO getCustomerDAO() throws DAOException;
 	public abstract MarketSummaryDAO getMarketSummaryDAO() throws DAOException;
 	public abstract OrderDAO getOrderDAO() throws DAOException;
 
-	public static DAOFactory getFacotry(int type) {
-		switch (type) {
-		case MS_SQL_FACTORY:
-			DAOFactory factory = MSSQLDAOFactory.getInstance();
-			return factory;
-		default:
-			throw new IllegalArgumentException("Unknown Database type " + type);
-		}
+	public static DAOFactory getFacotry() {
+        DAOFactory factory;
+        loadProperties();
+        if ("mysql".equals(prop.getProperty(PROP_DB_TYPE))) {
+            factory = MySQLDAOFactory.getInstance();
+            return factory;
+        } else if ("mssql".equals(prop.getProperty(PROP_DB_TYPE))) {
+			factory = MSSQLDAOFactory.getInstance();
+            return factory;
+        } else {
+			throw new IllegalArgumentException("Unknown Database type " + prop.getProperty(PROP_DB_TYPE));
+        }
 	}
 
+    public static void loadProperties() {
+        Log logger = LogFactory.getLog(DAOFactory.class);
+        if (prop == null) {
+            prop = new Properties();
+			MessageContext messageContext = MessageContext.getCurrentMessageContext();
+			if (messageContext != null) {
+				AxisService service = messageContext.getAxisService();
+				ClassLoader serviceClassLoader = service.getClassLoader();
+				InputStream is = serviceClassLoader.getResourceAsStream(StockTraderUtility.DB_PROPERRTIES_FILE);
+				if (is != null) {
+					try {
+						prop.load(is);
+					} catch (IOException e) {
+						logger.debug("Unable to load mysql-db properties file and using [jdbc:mysql://localhost/stocktraderdb?user=trade&password=trade] as the default connection",e);
+					}
+				} else {
+					logger.debug("Unable to load mysql-db properties file and using [jdbc:mysql://localhost/stocktraderdb?user=trade&password=trade] as the default connection");
+
+				}
+			}
+        }
+    }
+
 }

Modified: incubator/stonehenge/trunk/stocktrader/wsas/common/src/org/apache/stonehenge/stocktrader/dal/MarketSummaryDAO.java
URL: http://svn.apache.org/viewvc/incubator/stonehenge/trunk/stocktrader/wsas/common/src/org/apache/stonehenge/stocktrader/dal/MarketSummaryDAO.java?rev=769245&r1=769244&r2=769245&view=diff
==============================================================================
--- incubator/stonehenge/trunk/stocktrader/wsas/common/src/org/apache/stonehenge/stocktrader/dal/MarketSummaryDAO.java (original)
+++ incubator/stonehenge/trunk/stocktrader/wsas/common/src/org/apache/stonehenge/stocktrader/dal/MarketSummaryDAO.java Tue Apr 28 05:15:22 2009
@@ -31,6 +31,4 @@
 
 	public CustomMarketSummaryBean getCustomMarketSummary() throws DAOException;
 	
-	 
-
 }

Modified: incubator/stonehenge/trunk/stocktrader/wsas/common/src/org/apache/stonehenge/stocktrader/dal/OrderDAO.java
URL: http://svn.apache.org/viewvc/incubator/stonehenge/trunk/stocktrader/wsas/common/src/org/apache/stonehenge/stocktrader/dal/OrderDAO.java?rev=769245&r1=769244&r2=769245&view=diff
==============================================================================
--- incubator/stonehenge/trunk/stocktrader/wsas/common/src/org/apache/stonehenge/stocktrader/dal/OrderDAO.java (original)
+++ incubator/stonehenge/trunk/stocktrader/wsas/common/src/org/apache/stonehenge/stocktrader/dal/OrderDAO.java Tue Apr 28 05:15:22 2009
@@ -52,4 +52,12 @@
 			throws DAOException;
 
 	public void closeOrder(CustomOrderBean order) throws DAOException;
+
+    public void beginTransaction() throws DAOException;
+
+    public void commitTransaction() throws DAOException;
+
+    public void rollbackTransaction() throws DAOException;
+
+    public void close() throws DAOException;
 }

Modified: incubator/stonehenge/trunk/stocktrader/wsas/common/src/org/apache/stonehenge/stocktrader/mssql/AbstractMSSQLDAO.java
URL: http://svn.apache.org/viewvc/incubator/stonehenge/trunk/stocktrader/wsas/common/src/org/apache/stonehenge/stocktrader/mssql/AbstractMSSQLDAO.java?rev=769245&r1=769244&r2=769245&view=diff
==============================================================================
--- incubator/stonehenge/trunk/stocktrader/wsas/common/src/org/apache/stonehenge/stocktrader/mssql/AbstractMSSQLDAO.java (original)
+++ incubator/stonehenge/trunk/stocktrader/wsas/common/src/org/apache/stonehenge/stocktrader/mssql/AbstractMSSQLDAO.java Tue Apr 28 05:15:22 2009
@@ -40,15 +40,12 @@
 		logger.debug("AbstractMSSQLDAO.beginTransaction()");
 		try {
 			sqlConnection.setAutoCommit(false);
-			previousTransactionIsolation = sqlConnection
-					.getTransactionIsolation();
-			sqlConnection
-					.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
+			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);
+			throw new DAOException("Exception was thrown during the start of transaction", e);
 		}
 	}
 
@@ -59,8 +56,7 @@
 			sqlConnection.setAutoCommit(true);
 			sqlConnection.setTransactionIsolation(previousTransactionIsolation);
 		} catch (SQLException e) {
-			throw new DAOException(
-					"Exception is thrown during the commit of transaction", e);
+			throw new DAOException("Exception is thrown during the commit of transaction", e);
 		}
 	}
 
@@ -71,9 +67,7 @@
 			sqlConnection.setAutoCommit(true);
 			sqlConnection.setTransactionIsolation(previousTransactionIsolation);
 		} catch (SQLException e) {
-			throw new DAOException(
-					"Exception is thrown during the rollback of transaction", e);
-
+			throw new DAOException("Exception is thrown during the rollback of transaction", e);
 		}
 	}
 

Modified: incubator/stonehenge/trunk/stocktrader/wsas/common/src/org/apache/stonehenge/stocktrader/mssql/MSSQLCustomerDAO.java
URL: http://svn.apache.org/viewvc/incubator/stonehenge/trunk/stocktrader/wsas/common/src/org/apache/stonehenge/stocktrader/mssql/MSSQLCustomerDAO.java?rev=769245&r1=769244&r2=769245&view=diff
==============================================================================
--- incubator/stonehenge/trunk/stocktrader/wsas/common/src/org/apache/stonehenge/stocktrader/mssql/MSSQLCustomerDAO.java (original)
+++ incubator/stonehenge/trunk/stocktrader/wsas/common/src/org/apache/stonehenge/stocktrader/mssql/MSSQLCustomerDAO.java Tue Apr 28 05:15:22 2009
@@ -38,606 +38,564 @@
 import org.apache.stonehenge.stocktrader.util.StockTraderUtility;
 
 public class MSSQLCustomerDAO extends AbstractMSSQLDAO implements CustomerDAO {
-	private static final Log logger = LogFactory.getLog(MSSQLCustomerDAO.class);
+    private static final Log logger = LogFactory.getLog(MSSQLCustomerDAO.class);
 
-	private static final String SQL_DEBIT_ACCOUNT = "UPDATE dbo.ACCOUNT WITH (ROWLOCK) SET BALANCE=(BALANCE-?) WHERE ACCOUNTID=?";
-	private static final String SQL_SELECT_HOLDING_LOCK = "Set NOCOUNT ON; SELECT dbo.HOLDING.ACCOUNT_ACCOUNTID, HOLDING.HOLDINGID, HOLDING.QUANTITY, HOLDING.PURCHASEPRICE, HOLDING.PURCHASEDATE, HOLDING.QUOTE_SYMBOL FROM dbo.HOLDING WITH (ROWLOCK) INNER JOIN ORDERS ON HOLDING.HOLDINGID = ORDERS.HOLDING_HOLDINGID WHERE (ORDERS.ORDERID = ?)";
-	private static final String SQL_SELECT_HOLDING_NOLOCK = "Set NOCOUNT ON; SELECT HOLDING.ACCOUNT_ACCOUNTID, HOLDING.QUANTITY, HOLDING.PURCHASEPRICE, HOLDING.PURCHASEDATE, HOLDING.QUOTE_SYMBOL FROM HOLDING WITH(NOLOCK) WHERE HOLDING.HOLDINGID=? AND HOLDING.ACCOUNT_ACCOUNTID = (SELECT ACCOUNTID FROM dbo.ACCOUNT WHERE PROFILE_USERID = ?)";
-	private static final String SQL_SELECT_CUSTOMER_PROFILE_BY_USERID = "Set NOCOUNT ON; SELECT accountprofile.USERID, accountprofile.PASSWORD, accountprofile.FULLNAME, accountprofile.ADDRESS, accountprofile.EMAIL, accountprofile.CREDITCARD FROM dbo.accountprofile WITH (NOLOCK) WHERE accountprofile.USERID = ?";
-	private static final String SQL_UPDATE_CUSTOMER_LOGIN = "UPDATE dbo.account WITH (ROWLOCK) SET LOGINCOUNT = (LOGINCOUNT + 1), LASTLOGIN = CURRENT_TIMESTAMP where PROFILE_USERID = ?";
-	private static final String SQL_SELECT_CUSTOMER_LOGIN = "SELECT account.ACCOUNTID, account.CREATIONDATE, account.OPENBALANCE, account.LOGOUTCOUNT, account.BALANCE, account.LASTLOGIN, account.LOGINCOUNT FROM dbo.account WITH (ROWLOCK) WHERE account.PROFILE_USERID = ?";
-	private static final String SQL_UPDATE_LOGOUT = "UPDATE dbo.account WITH (ROWLOCK) SET LOGOUTCOUNT = (LOGOUTCOUNT + 1) where PROFILE_USERID= ?";
-	private static final String SQL_SELECT_GET_CUSTOMER_BY_USERID = "Set NOCOUNT ON; 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 dbo.orders o where o.account_accountid = (select a.accountid from dbo.account a WITH (NOLOCK)  where a.profile_userid = ?) ORDER BY o.ORDERID DESC";
-	private static final String SQL_SELECT_CLOSED_ORDERS = "Set NOCOUNT ON; SELECT ORDERID, ORDERTYPE, ORDERSTATUS, COMPLETIONDATE, OPENDATE, QUANTITY, PRICE, ORDERFEE, QUOTE_SYMBOL FROM dbo.orders WHERE ACCOUNT_ACCOUNTID = (select accountid from dbo.account WITH(NOLOCK) where profile_userid = ?) AND ORDERSTATUS = 'closed'";
-	private static final String SQL_UPDATE_CLOSED_ORDERS = "UPDATE dbo.orders SET ORDERSTATUS = 'completed' where ORDERSTATUS = 'closed' AND ACCOUNT_ACCOUNTID = (select accountid from dbo.account WITH (NOLOCK) where profile_userid = ?)";
-	private static final String SQL_INSERT_ACCOUNT_PROFILE = "INSERT INTO dbo.accountprofile VALUES (?, ?, ?, ?, ?, ?)";
-	private static final String SQL_INSERT_ACCOUNT = "INSERT INTO dbo.account (CREATIONDATE, OPENBALANCE, LOGOUTCOUNT, BALANCE, LASTLOGIN, LOGINCOUNT, PROFILE_USERID) VALUES (GetDate(), ?, ?, ?, ?, ?, ?); SELECT ID=@@IDENTITY";
-	private static final String SQL_UPDATE_ACCOUNT_PROFILE = "UPDATE dbo.accountprofile WITH (ROWLOCK) SET ADDRESS=?, PASSWORD=?, EMAIL=?, CREDITCARD=?, FULLNAME=? WHERE USERID=?";
-	private static final String SQL_SELECT_HOLDINGS = "SELECT HOLDING.HOLDINGID, HOLDING.QUANTITY, HOLDING.PURCHASEPRICE, HOLDING.PURCHASEDATE, HOLDING.QUOTE_SYMBOL,HOLDING.ACCOUNT_ACCOUNTID  from dbo.holding WHERE HOLDING.ACCOUNT_ACCOUNTID = (SELECT ACCOUNTID FROM ACCOUNT WHERE PROFILE_USERID = ?) ORDER BY HOLDING.HOLDINGID DESC";
-
-	public MSSQLCustomerDAO(Connection sqlConnection) throws DAOException {
-		super(sqlConnection);
-	}
-
-	public CustomHoldingBean getHoldingForUpdate(int orderId)
-			throws DAOException {
-		if (logger.isDebugEnabled()) {
-			logger
-					.debug("MSSQLCustomerDAO.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("MSSQLCustomerDAO.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 Top " + maxTop + SQL_SELECT_ORDERS_BY_ID;
-			} else {
-				sqlQuery = "Select Top " + maxDefault + SQL_SELECT_ORDERS_BY_ID;
-			}
-			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);
-				}
-			}
-		}
-	}
+    private static final String SQL_DEBIT_ACCOUNT = "UPDATE dbo.ACCOUNT WITH (ROWLOCK) SET BALANCE=(BALANCE-?) WHERE ACCOUNTID=?";
+    private static final String SQL_SELECT_HOLDING_LOCK = "Set NOCOUNT ON; SELECT dbo.HOLDING.ACCOUNT_ACCOUNTID, HOLDING.HOLDINGID, HOLDING.QUANTITY, HOLDING.PURCHASEPRICE, HOLDING.PURCHASEDATE, HOLDING.QUOTE_SYMBOL FROM dbo.HOLDING WITH (ROWLOCK) INNER JOIN ORDERS ON HOLDING.HOLDINGID = ORDERS.HOLDING_HOLDINGID WHERE (ORDERS.ORDERID = ?)";
+    private static final String SQL_SELECT_HOLDING_NOLOCK = "Set NOCOUNT ON; SELECT HOLDING.ACCOUNT_ACCOUNTID, HOLDING.QUANTITY, HOLDING.PURCHASEPRICE, HOLDING.PURCHASEDATE, HOLDING.QUOTE_SYMBOL FROM HOLDING WITH(NOLOCK) WHERE HOLDING.HOLDINGID=? AND HOLDING.ACCOUNT_ACCOUNTID = (SELECT ACCOUNTID FROM dbo.ACCOUNT WHERE PROFILE_USERID = ?)";
+    private static final String SQL_SELECT_CUSTOMER_PROFILE_BY_USERID = "Set NOCOUNT ON; SELECT accountprofile.USERID, accountprofile.PASSWORD, accountprofile.FULLNAME, accountprofile.ADDRESS, accountprofile.EMAIL, accountprofile.CREDITCARD FROM dbo.accountprofile WITH (NOLOCK) WHERE accountprofile.USERID = ?";
+    private static final String SQL_UPDATE_CUSTOMER_LOGIN = "UPDATE dbo.account WITH (ROWLOCK) SET LOGINCOUNT = (LOGINCOUNT + 1), LASTLOGIN = CURRENT_TIMESTAMP where PROFILE_USERID = ?";
+    private static final String SQL_SELECT_CUSTOMER_LOGIN = "SELECT account.ACCOUNTID, account.CREATIONDATE, account.OPENBALANCE, account.LOGOUTCOUNT, account.BALANCE, account.LASTLOGIN, account.LOGINCOUNT FROM dbo.account WITH (ROWLOCK) WHERE account.PROFILE_USERID = ?";
+    private static final String SQL_UPDATE_LOGOUT = "UPDATE dbo.account WITH (ROWLOCK) SET LOGOUTCOUNT = (LOGOUTCOUNT + 1) where PROFILE_USERID= ?";
+    private static final String SQL_SELECT_GET_CUSTOMER_BY_USERID = "Set NOCOUNT ON; 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 dbo.orders o where o.account_accountid = (select a.accountid from dbo.account a WITH (NOLOCK)  where a.profile_userid = ?) ORDER BY o.ORDERID DESC";
+    private static final String SQL_SELECT_CLOSED_ORDERS = "Set NOCOUNT ON; SELECT ORDERID, ORDERTYPE, ORDERSTATUS, COMPLETIONDATE, OPENDATE, QUANTITY, PRICE, ORDERFEE, QUOTE_SYMBOL FROM dbo.orders WHERE ACCOUNT_ACCOUNTID = (select accountid from dbo.account WITH(NOLOCK) where profile_userid = ?) AND ORDERSTATUS = 'closed'";
+    private static final String SQL_UPDATE_CLOSED_ORDERS = "UPDATE dbo.orders SET ORDERSTATUS = 'completed' where ORDERSTATUS = 'closed' AND ACCOUNT_ACCOUNTID = (select accountid from dbo.account WITH (NOLOCK) where profile_userid = ?)";
+    private static final String SQL_INSERT_ACCOUNT_PROFILE = "INSERT INTO dbo.accountprofile VALUES (?, ?, ?, ?, ?, ?)";
+    private static final String SQL_INSERT_ACCOUNT = "INSERT INTO dbo.account (CREATIONDATE, OPENBALANCE, LOGOUTCOUNT, BALANCE, LASTLOGIN, LOGINCOUNT, PROFILE_USERID) VALUES (GetDate(), ?, ?, ?, ?, ?, ?); SELECT ID=@@IDENTITY";
+    private static final String SQL_UPDATE_ACCOUNT_PROFILE = "UPDATE dbo.accountprofile WITH (ROWLOCK) SET ADDRESS=?, PASSWORD=?, EMAIL=?, CREDITCARD=?, FULLNAME=? WHERE USERID=?";
+    private static final String SQL_SELECT_HOLDINGS = "SELECT HOLDING.HOLDINGID, HOLDING.QUANTITY, HOLDING.PURCHASEPRICE, HOLDING.PURCHASEDATE, HOLDING.QUOTE_SYMBOL,HOLDING.ACCOUNT_ACCOUNTID  from dbo.holding WHERE HOLDING.ACCOUNT_ACCOUNTID = (SELECT ACCOUNTID FROM ACCOUNT WHERE PROFILE_USERID = ?) ORDER BY HOLDING.HOLDINGID DESC";
+
+    public MSSQLCustomerDAO(Connection sqlConnection) throws DAOException {
+        super(sqlConnection);
+    }
+
+    public CustomHoldingBean getHoldingForUpdate(int orderId) throws DAOException {
+        if (logger.isDebugEnabled()) {
+            logger.debug("MSSQLCustomerDAO.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("MSSQLCustomerDAO.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 Top " + maxTop + SQL_SELECT_ORDERS_BY_ID;
+            } else {
+                sqlQuery = "Select Top " + maxDefault + SQL_SELECT_ORDERS_BY_ID;
+            }
+            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);
+                }
+            }
+        }
+    }
 }

Modified: incubator/stonehenge/trunk/stocktrader/wsas/common/src/org/apache/stonehenge/stocktrader/mssql/MSSQLDAOFactory.java
URL: http://svn.apache.org/viewvc/incubator/stonehenge/trunk/stocktrader/wsas/common/src/org/apache/stonehenge/stocktrader/mssql/MSSQLDAOFactory.java?rev=769245&r1=769244&r2=769245&view=diff
==============================================================================
--- incubator/stonehenge/trunk/stocktrader/wsas/common/src/org/apache/stonehenge/stocktrader/mssql/MSSQLDAOFactory.java (original)
+++ incubator/stonehenge/trunk/stocktrader/wsas/common/src/org/apache/stonehenge/stocktrader/mssql/MSSQLDAOFactory.java Tue Apr 28 05:15:22 2009
@@ -36,21 +36,15 @@
 import org.apache.stonehenge.stocktrader.util.StockTraderUtility;
 
 public class MSSQLDAOFactory extends DAOFactory {
-	public static final String PROP_MSSQL_DB_HOST = "org.apache.stonehenge.stocktrader.mssql.MSSQLDAOFactory.host";
-	public static final String PROP_MSSQL_DB_PORT = "org.apache.stonehenge.stocktrader.mssql.MSSQLDAOFactory.port";
-	public static final String PROP_MSSQL_DB_NAME = "org.apache.stonehenge.stocktrader.mssql.MSSQLDAOFactory.db";
-	public static final String PROP_MSSQL_DB_USER = "org.apache.stonehenge.stocktrader.mssql.MSSQLDAOFactory.user";
-	public static final String PROP_MSSQL_PASSWORD = "org.apache.stonehenge.stocktrader.mssql.MSSQLDAOFactory.password";
 
 	private static Log logger = LogFactory.getLog(MSSQLDAOFactory.class);
 	private static MSSQLDAOFactory self = null;
 
-	private Properties prop = null;
 	private Connection sqlConnection = null;
 
 	private String connection = null;
 
-	static {
+    static {
 		try {
 			Class.forName("net.sourceforge.jtds.jdbc.Driver");
 		} catch (ClassNotFoundException e) {
@@ -75,9 +69,7 @@
 			return orderDAO;
 		} catch (SQLException e) {
 			logger.debug("", e);
-			throw new DAOException(
-					"Exception was thrown when instantiating MSSQLOrderDAO object",
-					e);
+			throw new DAOException("Exception was thrown when instantiating MSSQLOrderDAO object", e);
 		}
 	}
 
@@ -88,70 +80,41 @@
 			return customerDAO;
 		} catch (SQLException e) {
 			logger.debug("", e);
-			throw new DAOException(
-					"Exception was thrown when instantiating a MSSQLCustomerDAO",
-					e);
+			throw new DAOException("Exception was thrown when instantiating a MSSQLCustomerDAO", e);
 		}
 	}
 
 	public MarketSummaryDAO getMarketSummaryDAO() throws DAOException {
 		logger.debug("MSSQLDAOFactory.getOrderDAO");
 		try {
-			MarketSummaryDAO marketSummaryDAO = new MSSQLMarketSummaryDAO(
-					getConnection());
+			MarketSummaryDAO marketSummaryDAO = new MSSQLMarketSummaryDAO(getConnection());
 			return marketSummaryDAO;
 		} catch (SQLException e) {
 			logger.debug("", e);
-			throw new DAOException(
-					"Exception was thrown when instantiating a MarketSummaryDAO",
-					e);
+			throw new DAOException("Exception was thrown when instantiating a MarketSummaryDAO", e);
 		}
 	}
 
 	private String getConnectionString() {
 		if (connection == null) {
-			prop = new Properties();
-			MessageContext messageContext = MessageContext
-					.getCurrentMessageContext();
-			if (messageContext != null) {
-				AxisService service = messageContext.getAxisService();
-				ClassLoader serviceClassLoader = service.getClassLoader();
-				InputStream is = serviceClassLoader
-						.getResourceAsStream(StockTraderUtility.MSSQL_DB_PROPERRTIES_FILE);
-				if (is != null) {
-					try {
-						prop.load(is);
-					} catch (IOException e) {
-						logger
-								.debug(
-										"Unable to load mssql-db properties file and using [jdbc:jtds:sqlserver://highlander:1433/StockTraderDB;user=trade;password=trade;] as the default connection",
-										e);
-					}
-				} else {
-					logger
-							.debug("Unable to load mssql-db properties file and using [jdbc:jtds:sqlserver://highlander:1433/StockTraderDB;user=trade;password=trade;] as the default connection");
-
-				}
-			}
-			
+            loadProperties();
 			if (prop == null) {
 				connection = "jdbc:jtds:sqlserver://highlander:1433/StockTraderDB;user=trade;password=trade";
 			} else {
 				StringBuffer buf = new StringBuffer();
 				buf.append("jdbc:jtds:sqlserver://");
-				buf.append(prop.getProperty(PROP_MSSQL_DB_HOST));
-				buf.append(":" + prop.getProperty(PROP_MSSQL_DB_PORT));
-				buf.append("/" + prop.getProperty(PROP_MSSQL_DB_NAME));
-				buf.append(";user=" + prop.getProperty(PROP_MSSQL_DB_USER));
-				buf.append(";password=" + prop.getProperty(PROP_MSSQL_PASSWORD));
+				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));
 				buf.append(";");
 				connection = buf.toString();
 			}
 		}
 		
 		if (logger.isDebugEnabled()) {
-			logger.debug("MSSQLDAOFactory.getConnectionString()\nConnection :"
-					+ connection);
+			logger.debug("MSSQLDAOFactory.getConnectionString()\nConnection :" + connection);
 		}
 		return connection;
 	}

Modified: incubator/stonehenge/trunk/stocktrader/wsas/common/src/org/apache/stonehenge/stocktrader/mssql/MSSQLMarketSummaryDAO.java
URL: http://svn.apache.org/viewvc/incubator/stonehenge/trunk/stocktrader/wsas/common/src/org/apache/stonehenge/stocktrader/mssql/MSSQLMarketSummaryDAO.java?rev=769245&r1=769244&r2=769245&view=diff
==============================================================================
--- incubator/stonehenge/trunk/stocktrader/wsas/common/src/org/apache/stonehenge/stocktrader/mssql/MSSQLMarketSummaryDAO.java (original)
+++ incubator/stonehenge/trunk/stocktrader/wsas/common/src/org/apache/stonehenge/stocktrader/mssql/MSSQLMarketSummaryDAO.java Tue Apr 28 05:15:22 2009
@@ -37,8 +37,7 @@
 
 public class MSSQLMarketSummaryDAO extends AbstractMSSQLDAO implements
 		MarketSummaryDAO {
-	private static final Log logger = LogFactory
-			.getLog(MSSQLMarketSummaryDAO.class);
+	private static final Log logger = LogFactory.getLog(MSSQLMarketSummaryDAO.class);
 
 	private static final String SQL_SELECT_QUOTE = "Set NOCOUNT ON; SELECT symbol, companyname, volume, price, open1, low, high, change1 from dbo.quote with (ROWLOCK) where symbol = ?";
 	private static final String SQL_SELECT_QUOTE_NOLOCK = "Set NOCOUNT ON; SELECT symbol, companyname, volume, price, open1, low, high, change1 from dbo.quote with (NOLOCK) where symbol = ?";
@@ -56,24 +55,26 @@
 
 	public CustomQuoteBean getQuote(String symbol) throws DAOException {
 		if (logger.isDebugEnabled()) {
-			logger.debug("MarketSummaryDAO.getQouteForUpdate(String)\nSymbol :"
-					+ symbol);
+			logger.debug("MarketSummaryDAO.getQouteForUpdate(String)\nSymbol :" + symbol);
 		}
 		PreparedStatement selectQuote = null;
 		try {
-			selectQuote = sqlConnection
-					.prepareStatement(SQL_SELECT_QUOTE_NOLOCK);
+			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));
+					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 {
@@ -98,23 +99,26 @@
 
 	public CustomQuoteBean getQuoteForUpdate(String symbol) throws DAOException {
 		if (logger.isDebugEnabled()) {
-			logger.debug("MarketSummaryDAO.getQouteForUpdate(String)\nSymbol :"
-					+ symbol);
+			logger.debug("MarketSummaryDAO.getQouteForUpdate(String)\nSymbol :" + symbol);
 		}
 		PreparedStatement qouteForUpdateStat = null;
 		try {
-			qouteForUpdateStat = sqlConnection
-					.prepareStatement(SQL_SELECT_QUOTE);
+			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));
+				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();
@@ -138,10 +142,8 @@
 		}
 	}
 
-	public void updateStockPriceVolume(double quantity, CustomQuoteBean quote)
-			throws DAOException {
-		BigDecimal priceChangeFactor = StockTraderUtility
-				.getRandomPriceChangeFactor(quote.getPrice());
+	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) {
@@ -153,8 +155,7 @@
 
 		PreparedStatement updateStockPriceVolumeStat = null;
 		try {
-			updateStockPriceVolumeStat = sqlConnection
-					.prepareStatement(SQL_UPDATE_STOCKPRICEVOLUME);
+			updateStockPriceVolumeStat = sqlConnection.prepareStatement(SQL_UPDATE_STOCKPRICEVOLUME);
 			updateStockPriceVolumeStat.setBigDecimal(1, newPrice);
 			updateStockPriceVolumeStat.setBigDecimal(2, quote.getLow());
 			updateStockPriceVolumeStat.setBigDecimal(3, quote.getHigh());
@@ -177,28 +178,27 @@
 	}
 
 	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();
+		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);
+			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));
+							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 {
@@ -222,17 +222,20 @@
 		List<CustomQuoteBean> topLosers = new ArrayList<CustomQuoteBean>();
 		PreparedStatement losers = null;
 		try {
-			losers = sqlConnection
-					.prepareStatement(SQL_SELECT_MARKETSUMMARY_LOSERS);
+			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));
+							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 {
@@ -253,8 +256,6 @@
 				}
 			}
 		}
-		CustomMarketSummaryBean marketSummary = new CustomMarketSummaryBean(
-				tSIA, openTSIA, totalVolume, topGainers, topLosers);
-		return marketSummary;
+		return new CustomMarketSummaryBean(tSIA, openTSIA, totalVolume, topGainers, topLosers);
 	}
 }



Mime
View raw message