You are viewing a plain text version of this content. The canonical link for it is here.
Posted to stonehenge-commits@incubator.apache.org by sh...@apache.org on 2009/04/22 10:48:13 UTC

svn commit: r767459 - in /incubator/stonehenge/trunk/stocktrader/php: business_service/ config_service/ data_layer/ order_processor/ resources/conf/

Author: shankar
Date: Wed Apr 22 10:48:13 2009
New Revision: 767459

URL: http://svn.apache.org/viewvc?rev=767459&view=rev
Log:
MySQL support for PHP Stocktrader

Added:
    incubator/stonehenge/trunk/stocktrader/php/data_layer/
    incubator/stonehenge/trunk/stocktrader/php/data_layer/data_access_layer.php
    incubator/stonehenge/trunk/stocktrader/php/data_layer/database.php
    incubator/stonehenge/trunk/stocktrader/php/data_layer/mssql_database.php
    incubator/stonehenge/trunk/stocktrader/php/data_layer/mysql_database.php
Removed:
    incubator/stonehenge/trunk/stocktrader/php/business_service/data_access_layer.php
    incubator/stonehenge/trunk/stocktrader/php/config_service/data_access_layer.php
    incubator/stonehenge/trunk/stocktrader/php/order_processor/data_access_layer.php
Modified:
    incubator/stonehenge/trunk/stocktrader/php/business_service/business_processor.php
    incubator/stonehenge/trunk/stocktrader/php/business_service/order_processor_proxy.php
    incubator/stonehenge/trunk/stocktrader/php/config_service/config_svc.php
    incubator/stonehenge/trunk/stocktrader/php/config_service/config_svc_processor.php
    incubator/stonehenge/trunk/stocktrader/php/order_processor/order_processor.php
    incubator/stonehenge/trunk/stocktrader/php/resources/conf/database_config.xml

Modified: incubator/stonehenge/trunk/stocktrader/php/business_service/business_processor.php
URL: http://svn.apache.org/viewvc/incubator/stonehenge/trunk/stocktrader/php/business_service/business_processor.php?rev=767459&r1=767458&r2=767459&view=diff
==============================================================================
--- incubator/stonehenge/trunk/stocktrader/php/business_service/business_processor.php (original)
+++ incubator/stonehenge/trunk/stocktrader/php/business_service/business_processor.php Wed Apr 22 10:48:13 2009
@@ -19,7 +19,7 @@
 
 
 require_once("order_processor_proxy.php");
-require_once("data_access_layer.php");
+require_once("../data_layer/data_access_layer.php");
 
 define ("ORDER_TYPE_BUY", "buy");
 define ("ORDER_TYPE_SELL", "sell");
@@ -441,25 +441,25 @@
  */
 function processSellEnhanced($sellInfo)
 {
-	$dbhandle = ConnectToDatabase();
+	$db = GetDatabase();
 	$response = null;
-	if ($dbhandle)
+	if ($db)
 	{
-		$status = ExecuteQuery("BEGIN TRAN");
+		$status = $db->BeginTransaction();
 		if ($status)
 		{
 			$query = "SELECT HOLDING.HOLDINGID, HOLDING.QUANTITY, HOLDING.PURCHASEPRICE, 
 					HOLDING.PURCHASEDATE, HOLDING.QUOTE_SYMBOL,HOLDING.ACCOUNT_ACCOUNTID FROM 
-					HOLDING WITH (NOLOCK) WHERE HOLDINGID= '$sellInfo->holdingID'";
+					HOLDING WHERE HOLDINGID= '$sellInfo->holdingID'";
 			
-			$result = ExecuteQuery($query);
-			$symbol = GetMSSQLValue($result, 0, 4);
+			$result = $db->ExecuteQuery($query);
+			$symbol = $db->GetSQLValue($result, 0, 4);
 			
 			if ($symbol)
 			{
 				$order = createOrder($sellInfo->userID, 
 						$symbol, ORDER_TYPE_SELL, 
-						$sellInfo->quantity, $sellInfo->holdingID);
+						$sellInfo->quantity, $sellInfo->holdingID, $db);
 				
 				/*$order->openDate = "2008-05-30T19:27:30.78125+05:30";
 				$order->completionDate = "2008-05-30T19:27:30.890625+05:30";*/
@@ -471,19 +471,19 @@
 					$response = new sellEnhanced();
 					$response->sellEnhancedReturn = new OrderDataBean();
 					$response->sellEnhancedReturn = $order;
-					ExecuteQuery("COMMIT TRAN");
+					$db->CommitTransaction();
 				}
 				else
 				{
-					ExecuteQuery("ROLLBACK TRAN");
+					$db->RollbackTransaction();
 				}
 			}
 			else
 			{
-				ExecuteQuery("ROLLBACK TRAN");
+				$db->RollbackTransaction();
 			}
 
-			CloseDatabase($dbhandle);
+			$db->CloseDatabase();
 		}
 	}
 	return $response;
@@ -496,17 +496,17 @@
  */
 function processGetTopOrders($userID)
 {
-	$dbhandle = ConnectToDatabase();
+	$db = GetDatabase();
 	$response = null;
-	if($dbhandle)
+	if($db)
 	{
 		$query = "SELECT TOP ".TOP_ORDERS." ORDERID, ORDERTYPE, ORDERSTATUS, OPENDATE, 
 				COMPLETIONDATE, QUANTITY, PRICE, ORDERFEE, QUOTE_SYMBOL FROM 
 				ORDERS WHERE ORDERS.ACCOUNT_ACCOUNTID = (select ACCOUNT.ACCOUNTID 
-				from ACCOUNT WITH (NOLOCK)  WHERE ACCOUNT.PROFILE_USERID = 
+				from ACCOUNT  WHERE ACCOUNT.PROFILE_USERID = 
 				'$userID') ORDER BY ORDERS.ORDERID DESC";
 		
-		$result = ExecuteQuery($query);
+		$result = $db->ExecuteQuery($query);
 		
 		if($result)
 		{		
@@ -514,33 +514,33 @@
 			$response->getOrdersReturn = new ArrayOfOrderDataBean();
 			$rawNo = 0;
 			
-			while(($orderID = GetMSSQLValue($result, $rawNo, 0)))
+			while(($orderID = $db->GetSQLValue($result, $rawNo, 0)))
 			{
 				$response->getOrdersReturn->OrderDataBean[$rawNo] = 
 					new OrderDataBean();
 				$response->getOrdersReturn->OrderDataBean[$rawNo]->
 					orderID = $orderID;
 				$response->getOrdersReturn->OrderDataBean[$rawNo]->
-					orderType = GetMSSQLValue($result, $rawNo, 1);
+					orderType = $db->GetSQLValue($result, $rawNo, 1);
 				$response->getOrdersReturn->OrderDataBean[$rawNo]->
-					orderStatus = GetMSSQLValue($result, $rawNo, 2);
+					orderStatus = $db->GetSQLValue($result, $rawNo, 2);
 				$response->getOrdersReturn->OrderDataBean[$rawNo]->
-					openDate = formatDate(GetMSSQLValue($result, $rawNo, 3));
+					openDate = formatDate($db->GetSQLValue($result, $rawNo, 3));
 				$response->getOrdersReturn->OrderDataBean[$rawNo]->
-					completionDate = formatDate(GetMSSQLValue($result, $rawNo, 4));
+					completionDate = formatDate($db->GetSQLValue($result, $rawNo, 4));
 				$response->getOrdersReturn->OrderDataBean[$rawNo]->
-					quantity = GetMSSQLValue($result, $rawNo, 5);
+					quantity = $db->GetSQLValue($result, $rawNo, 5);
 				$response->getOrdersReturn->OrderDataBean[$rawNo]->
-					price = GetMSSQLValue($result, $rawNo, 6);
+					price = $db->GetSQLValue($result, $rawNo, 6);
 				$response->getOrdersReturn->OrderDataBean[$rawNo]->
-					orderFee = GetMSSQLValue($result, $rawNo, 7);
+					orderFee = $db->GetSQLValue($result, $rawNo, 7);
 				$response->getOrdersReturn->OrderDataBean[$rawNo]->
-					symbol = GetMSSQLValue($result, $rawNo, 8);
+					symbol = $db->GetSQLValue($result, $rawNo, 8);
 				
 				$rawNo = $rawNo + 1;
 			}
 		}
-		CloseDatabase($dbhandle);
+		$db->CloseDatabase();
 	}
 	return $response;
 }
@@ -552,29 +552,29 @@
  */
 function processGetHolding($holdingInfo)
 {
-	$dbhandle = ConnectToDatabase();
+	$db = GetDatabase();
 	$response = null;
-	if($dbhandle)
+	if($db)
 	{
-        $query = "Set NOCOUNT ON; SELECT HOLDING.ACCOUNT_ACCOUNTID, 
+        $query = "SELECT HOLDING.ACCOUNT_ACCOUNTID, 
 			HOLDING.QUANTITY, HOLDING.PURCHASEPRICE, HOLDING.PURCHASEDATE, 
-			HOLDING.QUOTE_SYMBOL FROM HOLDING WITH(NOLOCK) 
+			HOLDING.QUOTE_SYMBOL FROM HOLDING  
 			WHERE HOLDING.HOLDINGID='$holdingInfo->holdingID' AND 
 			HOLDING.ACCOUNT_ACCOUNTID = (SELECT ACCOUNTID FROM 
 			ACCOUNT WHERE PROFILE_USERID = '$holdingInfo->userID')";
 	
-		$result = ExecuteQuery($query);
+		$result = $db->ExecuteQuery($query);
 		if ($result)
 		{
 			$response = new getHoldingResponse();
 			$response->getHoldingReturn = new HoldingDataBean();
 			$response->getHoldingReturn->holdingID = $holdingInfo->holdingID;
-			$response->getHoldingReturn->quantity = GetMSSQLValue($result, 0, 1);
-			$response->getHoldingReturn->purchasePrice = GetMSSQLValue($result, 0, 2);
-			$response->getHoldingReturn->purchaseDate = formatDate(GetMSSQLValue($result, 0, 3));
-			$response->getHoldingReturn->quoteID = GetMSSQLValue($result, 0, 4);
+			$response->getHoldingReturn->quantity = $db->GetSQLValue($result, 0, 1);
+			$response->getHoldingReturn->purchasePrice = $db->GetSQLValue($result, 0, 2);
+			$response->getHoldingReturn->purchaseDate = formatDate($db->GetSQLValue($result, 0, 3));
+			$response->getHoldingReturn->quoteID = $db->GetSQLValue($result, 0, 4);
 		}
-		CloseDatabase($dbhandle);	
+		$db->CloseDatabase();	
 	}
 	return $response;
 }
@@ -586,26 +586,26 @@
  */
 function processRegister($userInfo)
 {
-	$dbhandle = ConnectToDatabase();
+	$db = GetDatabase();
 	$response = null;
-	if($dbhandle)
+	if($db)
 	{
         $queryAccount = "INSERT INTO account (CREATIONDATE, OPENBALANCE, LOGOUTCOUNT, 
-			BALANCE, LASTLOGIN, LOGINCOUNT, PROFILE_USERID) VALUES (GetDate(), 
-			'$userInfo->openBalance', '0', '$userInfo->openBalance', GetDate(), '0', 
-			'$userInfo->userID'); SELECT ID=@@IDENTITY";
+			BALANCE, LASTLOGIN, LOGINCOUNT, PROFILE_USERID) VALUES (CURRENT_TIMESTAMP, 
+			'$userInfo->openBalance', '0', '$userInfo->openBalance', CURRENT_TIMESTAMP, '0', 
+			'$userInfo->userID')";
 			
         $queryAccountProfile = "INSERT INTO accountprofile VALUES 
 			('$userInfo->address', '$userInfo->password', '$userInfo->userID', 
-			'$userInfo->email', '$userInfo->creditCard', '$userInfo->fullname')";
+			'$userInfo->email', '$userInfo->creditcard', '$userInfo->fullname')";
 			
-		$result = ExecuteQuery($queryAccountProfile);
+		$result = $db->ExecuteQuery($queryAccountProfile);
 		if ($result)
 		{
 			$result = null;
-			$result = ExecuteQuery($queryAccount);
-			$accountID = GetMSSQLValue($result, 0, 0);
-			if ($accountID)
+			$result = $db->ExecuteQuery($queryAccount);
+			$accountID = $db->GetInsertID();
+			if (($accountID) && ($accountID != -1))
 			{
 				$response = new registerResponse();
 				$response->registerReturn = new AccountDataBean();
@@ -617,7 +617,7 @@
 				$response->registerReturn->profileID = $accountID;
 			}
 		}
-		CloseDatabase($dbhandle);	
+		$db->CloseDatabase();	
 	}
 	return $response;
 }
@@ -628,121 +628,121 @@
  */
 function processGetMarketSummary()
 {
-	$dbhandle = ConnectToDatabase();
+	$db = GetDatabase();
 	$response = null;
-	if($dbhandle)
+	if($db)
 	{
-		$queryTSIA = "Set NOCOUNT ON; select SUM(price)/count(*) as 
+		$queryTSIA = "select SUM(price)/count(*) as 
 				TSIA from quote where symbol like 's:1__'";
-		$queryOPENTSIA = "Set NOCOUNT ON; select SUM(open1)/count(*) as 
+		$queryOPENTSIA = "select SUM(open1)/count(*) as 
 				openTSIA from quote where symbol like 's:1__'";
-		$queryVolume = "Set NOCOUNT ON; SELECT SUM(volume) from quote 
+		$queryVolume = "SELECT SUM(volume) from quote 
 				where symbol like 's:1__'";
-		$queryGainers = "Set NOCOUNT ON; SELECT symbol, companyname, volume, price, 
-				open1, low, high, change1 from quote with (NOLOCK) where symbol 
+		$queryGainers = "SELECT symbol, companyname, volume, price, 
+				open1, low, high, change1 from quote where symbol 
 				like 's:1__' order by change1 desc";
-		$queryLosers = "Set NOCOUNT ON; SELECT symbol, companyname, volume, price, 
-				open1, low, high, change1 from quote with (NOLOCK) where symbol 
+		$queryLosers = "SELECT symbol, companyname, volume, price, 
+				open1, low, high, change1 from quote where symbol 
 				like 's:1__' order by change1";
 		
 		$response = new getMarketSummaryResponse();
 		$response->getMarketSummaryReturn = new MarketSummaryDataBeanWS();
 		
-		$result = ExecuteQuery($queryTSIA);
+		$result = $db->ExecuteQuery($queryTSIA);
 		if ($result)
 		{
 			$response->getMarketSummaryReturn->TSIA = 
-				GetMSSQLValue($result, 0, 0);
+				$db->GetSQLValue($result, 0, 0);
 			$result = null;
 		}
 		
-		$result = ExecuteQuery($queryOPENTSIA);
+		$result = $db->ExecuteQuery($queryOPENTSIA);
 		if ($result)
 		{
 			$response->getMarketSummaryReturn->openTSIA = 
-				GetMSSQLValue($result, 0, 0);
+				$db->GetSQLValue($result, 0, 0);
 			$result = null;
 		}
 		
-		$result = ExecuteQuery($queryVolume);
+		$result = $db->ExecuteQuery($queryVolume);
 		if($result)
 		{
 			$response->getMarketSummaryReturn->volume = 
-				GetMSSQLValue($result, 0, 0);
+				$db->GetSQLValue($result, 0, 0);
 			$result = null;
 		}
 		
-		$result = ExecuteQuery($queryGainers);
+		$result = $db->ExecuteQuery($queryGainers);
 		if($result)
 		{
 			$response->getMarketSummaryReturn->topGainers = 
 				new ArrayOfQuoteDataBean();
 			$rawNo = 0;
-			while(($symbol = GetMSSQLValue($result, $rawNo, 0)) && $rawNo < 5)
+			while(($symbol = $db->GetSQLValue($result, $rawNo, 0)) && $rawNo < 5)
 			{
 				$response->getMarketSummaryReturn->topGainers->
 					QuoteDataBean[$rawNo] = new QuoteDataBean();
 				$response->getMarketSummaryReturn->topGainers->
 					QuoteDataBean[$rawNo]->symbol = $symbol;
 				$response->getMarketSummaryReturn->topGainers->
-					QuoteDataBean[$rawNo]->companyName = GetMSSQLValue($result, 0, 1);
+					QuoteDataBean[$rawNo]->companyName = $db->GetSQLValue($result, 0, 1);
 				$response->getMarketSummaryReturn->topGainers->
-					QuoteDataBean[$rawNo]->volume = GetMSSQLValue($result, 0, 2);
+					QuoteDataBean[$rawNo]->volume = $db->GetSQLValue($result, 0, 2);
 				$response->getMarketSummaryReturn->topGainers->
-					QuoteDataBean[$rawNo]->price = GetMSSQLValue($result, 0, 3);
+					QuoteDataBean[$rawNo]->price = $db->GetSQLValue($result, 0, 3);
 				$response->getMarketSummaryReturn->topGainers->
-					QuoteDataBean[$rawNo]->open = GetMSSQLValue($result, 0, 4);
+					QuoteDataBean[$rawNo]->open = $db->GetSQLValue($result, 0, 4);
 				$response->getMarketSummaryReturn->topGainers->
-					QuoteDataBean[$rawNo]->low = GetMSSQLValue($result, 0, 5);
+					QuoteDataBean[$rawNo]->low = $db->GetSQLValue($result, 0, 5);
 				$response->getMarketSummaryReturn->topGainers->
-					QuoteDataBean[$rawNo]->high = GetMSSQLValue($result, 0, 6);
+					QuoteDataBean[$rawNo]->high = $db->GetSQLValue($result, 0, 6);
 				$response->getMarketSummaryReturn->topGainers->
-					QuoteDataBean[$rawNo]->change = GetMSSQLValue($result, 0, 7);
+					QuoteDataBean[$rawNo]->change = $db->GetSQLValue($result, 0, 7);
 				$rawNo = $rawNo + 1;
 			}
 			$result = null;
 		}
 		
-		$result = ExecuteQuery($queryLosers);
+		$result = $db->ExecuteQuery($queryLosers);
 		if($result)
 		{
 			$response->getMarketSummaryReturn->topLosers = 
 				new ArrayOfQuoteDataBean();
 			$rawNo = 0;
-			while(($symbol = GetMSSQLValue($result, $rawNo, 0)) && $rawNo < 5)
+			while(($symbol = $db->GetSQLValue($result, $rawNo, 0)) && $rawNo < 5)
 			{
 				$response->getMarketSummaryReturn->topLosers->
 					QuoteDataBean[$rawNo] = new QuoteDataBean();
 				$response->getMarketSummaryReturn->topLosers->
 					QuoteDataBean[$rawNo]->symbol = $symbol;
 				$response->getMarketSummaryReturn->topLosers->
-					QuoteDataBean[$rawNo]->companyName = GetMSSQLValue($result, 0, 1);
+					QuoteDataBean[$rawNo]->companyName = $db->GetSQLValue($result, 0, 1);
 				$response->getMarketSummaryReturn->topLosers->
-					QuoteDataBean[$rawNo]->volume = GetMSSQLValue($result, 0, 2);
+					QuoteDataBean[$rawNo]->volume = $db->GetSQLValue($result, 0, 2);
 				$response->getMarketSummaryReturn->topLosers->
-					QuoteDataBean[$rawNo]->price = GetMSSQLValue($result, 0, 3);
+					QuoteDataBean[$rawNo]->price = $db->GetSQLValue($result, 0, 3);
 				$response->getMarketSummaryReturn->topLosers->
-					QuoteDataBean[$rawNo]->open = GetMSSQLValue($result, 0, 4);
+					QuoteDataBean[$rawNo]->open = $db->GetSQLValue($result, 0, 4);
 				$response->getMarketSummaryReturn->topLosers->
-					QuoteDataBean[$rawNo]->low = GetMSSQLValue($result, 0, 5);
+					QuoteDataBean[$rawNo]->low = $db->GetSQLValue($result, 0, 5);
 				$response->getMarketSummaryReturn->topLosers->
-					QuoteDataBean[$rawNo]->high = GetMSSQLValue($result, 0, 6);
+					QuoteDataBean[$rawNo]->high = $db->GetSQLValue($result, 0, 6);
 				$response->getMarketSummaryReturn->topLosers->
-					QuoteDataBean[$rawNo]->change = GetMSSQLValue($result, 0, 7);
+					QuoteDataBean[$rawNo]->change = $db->GetSQLValue($result, 0, 7);
 				$rawNo = $rawNo + 1;
 			}
 			$result = null;
 		}
 		
-		/*$result = ExecuteQuery($querySummaryDate);
+		/*$result = $db->ExecuteQuery($querySummaryDate);
 		if($result)
 		{
 			$response->getMarketSummaryReturn->summaryDate = 
-				GetMSSQLValue($result, 0, 0);
+				$db->GetSQLValue($result, 0, 0);
 			$result = null;
 		}*/
 		
-		CloseDatabase($dbhandle);	
+		$db->CloseDatabase();	
 	}
 	return $response;
 }
@@ -751,22 +751,18 @@
 /**
  * This utility method is used to get accountID corresond to a particular userID.
  * @param userID userID.
+ * @param db database object
  * @return the accountID of the user.
  */
-function getAccountID($userID)
+function getAccountID($userID, $db)
 {
-	$dbhandle = ConnectToDatabase();
 	$response = null;
-	if($dbhandle)
+	$query = "SELECT ACCOUNTID FROM ACCOUNT  
+		WHERE PROFILE_USERID = '$userID'";
+	$result = $db->ExecuteQuery($query);
+	if($result)
 	{
-		$query = "Set NOCOUNT ON; SELECT ACCOUNTID FROM dbo.ACCOUNT  
-			WITH (NOLOCK) WHERE PROFILE_USERID = '$userID'";
-		$result = ExecuteQuery($query);
-		if($result)
-		{
-			$response = GetMSSQLValue($result, 0, 0);	
-		}
-		CloseDatabase($dbhandle);	
+		$response = $db->GetSQLValue($result, 0, 0);	
 	}
 	return $response;
 }
@@ -778,9 +774,10 @@
  * @param orderType type of the order (buy|sell)
  * @param quantity amount (buy|sell)
  * @param holdingID holdingID of the order (apply for sell)
+ * @param db database object
  * @return an OrderDataBean object.
  */
-function createOrder($userID, $symbol, $orderType, $quantity, $holdingID)
+function createOrder($userID, $symbol, $orderType, $quantity, $holdingID, $db)
 {
 	$order = null;
 	$order = new OrderDataBean();
@@ -801,17 +798,12 @@
 	
 	$query = "INSERT INTO ORDERS (OPENDATE, ORDERFEE, PRICE, QUOTE_SYMBOL, QUANTITY, 
 			ORDERTYPE, ORDERSTATUS, ACCOUNT_ACCOUNTID, HOLDING_HOLDINGID) 
-			VALUES (GETDATE(),  '$order->orderFee', '$order->price', 
+			VALUES (CURRENT_TIMESTAMP,  '$order->orderFee', '$order->price', 
 			'$order->symbol', '$order->quantity', '$orderType', 'open', 
-			'".getAccountID($userID)."', '$holdingID'); 
-			SELECT ID=@@IDENTITY";
-	
-	$result = ExecuteQuery($query);
-	
-	if ($result)
-	{
-		$order->orderID = GetMSSQLValue($result, 0, 0);
-	}
+			'".getAccountID($userID, $db)."', '$holdingID')"; 
+
+	$result = $db->ExecuteQuery($query);
+	$order->orderID = $db->GetInsertID();
 	return $order;
 }
 
@@ -824,13 +816,13 @@
  */
 function processBuy($buyInfo)
 {
-	$dbhandle = ConnectToDatabase();
+	$db = GetDatabase();
 	$response = null;
-	if ($dbhandle)
+	if ($db)
 	{
-		$status = ExecuteQuery("BEGIN TRAN");
+		$status = $db->BeginTransaction();
 		$order = createOrder($buyInfo->userID, $buyInfo->symbol, 
-				ORDER_TYPE_BUY, $buyInfo->quantity, INITIAL_HOLDING_ID);
+				ORDER_TYPE_BUY, $buyInfo->quantity, INITIAL_HOLDING_ID, $db);
 		
 		/*$order->openDate = "2008-05-30T19:27:30.78125+05:30";
 		$order->completionDate = "2008-05-30T19:27:30.890625+05:30";*/
@@ -842,13 +834,13 @@
 			$response = new buyResponse();
 			$response->buyReturn = new OrderDataBean();
 			$response->buyReturn = $order;
-			ExecuteQuery("COMMIT TRAN");
+			$db->CommitTransaction();
 		}
 		else
 		{
-			ExecuteQuery("ROLLBACK TRAN");
+			$db->RollbackTransaction();
 		}
-		CloseDatabase($dbhandle);
+		$db->CloseDatabase();
 	}
 	return $response;
 }
@@ -873,30 +865,30 @@
 {
 	if ($symbol)
 	{
-		$dbhandle = ConnectToDatabase();
+		$db = GetDatabase();
 		$response = null;
-		if($dbhandle)
+		if($db)
 		{
-			$query = "Set NOCOUNT ON; SELECT symbol, companyname, volume, price, 
-					open1, low, high, change1 from quote with (ROWLOCK) where 
+			$query = "SELECT symbol, companyname, volume, price, 
+					open1, low, high, change1 from quote where 
 					symbol = '$symbol'";
 			
-			$result = ExecuteQuery($query);
+			$result = $db->ExecuteQuery($query);
 			if ($result)
 			{
 				$response = new getQuoteResponse();
 				$response->getQuoteReturn = new QuoteDataBean();
-				$response->getQuoteReturn->symbol = GetMSSQLValue($result, 0, 0);
-				$response->getQuoteReturn->companyName = GetMSSQLValue($result, 0, 1);
-				$response->getQuoteReturn->volume = GetMSSQLValue($result, 0, 2);
-				$response->getQuoteReturn->price = GetMSSQLValue($result, 0, 3);
-				$response->getQuoteReturn->open = GetMSSQLValue($result, 0, 4);
-				$response->getQuoteReturn->low = GetMSSQLValue($result, 0, 5);
-				$response->getQuoteReturn->high = GetMSSQLValue($result, 0, 6);
-				$response->getQuoteReturn->change = GetMSSQLValue($result, 0, 7);			
+				$response->getQuoteReturn->symbol = $db->GetSQLValue($result, 0, 0);
+				$response->getQuoteReturn->companyName = $db->GetSQLValue($result, 0, 1);
+				$response->getQuoteReturn->volume = $db->GetSQLValue($result, 0, 2);
+				$response->getQuoteReturn->price = $db->GetSQLValue($result, 0, 3);
+				$response->getQuoteReturn->open = $db->GetSQLValue($result, 0, 4);
+				$response->getQuoteReturn->low = $db->GetSQLValue($result, 0, 5);
+				$response->getQuoteReturn->high = $db->GetSQLValue($result, 0, 6);
+				$response->getQuoteReturn->change = $db->GetSQLValue($result, 0, 7);			
 				
 			}
-			CloseDatabase($dbhandle);	
+			$db->CloseDatabase();	
 		}
 	}
 	else
@@ -913,16 +905,16 @@
  */
 function processUpdateAccountProfile($profileInfo)
 {
-	$dbhandle = ConnectToDatabase();
+	$db = GetDatabase();
 	$response = null;
-	if($dbhandle)
+	if($db)
 	{
-		$query = "UPDATE accountprofile WITH (ROWLOCK) SET ADDRESS='$profileInfo->address', 
+		$query = "UPDATE accountprofile SET ADDRESS='$profileInfo->address', 
 				PASSWORD='$profileInfo->password', EMAIL='$profileInfo->email', CREDITCARD = 
 				'$profileInfo->creditCard', FULLNAME='$profileInfo->fullName' WHERE 
 				USERID= '$profileInfo->userID'";
 				
-		$result = ExecuteQuery($query);
+		$result = $db->ExecuteQuery($query);
 		if($result)
 		{
 			$response = new updateAccountProfileResponse();
@@ -937,7 +929,7 @@
 		else
 		{	
 		}
-		CloseDatabase($dbhandle);	
+		$db->CloseDatabase();	
 	}
 	return $response;
 }
@@ -949,19 +941,19 @@
  */
 function processLogout($userID)
 {
-	$dbhandle = ConnectToDatabase();
+	$db = GetDatabase();
 	$response = null;
-	if($dbhandle)
+	if($db)
 	{
-        $query = "UPDATE dbo.account WITH (ROWLOCK) SET LOGOUTCOUNT = 
+        $query = "UPDATE account SET LOGOUTCOUNT = 
 			(LOGOUTCOUNT + 1) where PROFILE_USERID= '$userID'";
 		
-		$result = ExecuteQuery($query);
+		$result = $db->ExecuteQuery($query);
 		if($result)
 		{
 			$response = new logoutResponse();
 		}
-		CloseDatabase($dbhandle);	
+		$db->CloseDatabase();	
 	}
 	return $response;
 }
@@ -973,40 +965,40 @@
  */
 function processGetHoldings($userID)
 {
-	$dbhandle = ConnectToDatabase();
+	$db = GetDatabase();
 	$response = null;
-	if($dbhandle)
+	if($db)
 	{
         $query = "SELECT HOLDING.HOLDINGID, HOLDING.QUANTITY, HOLDING.PURCHASEPRICE, 
 			HOLDING.PURCHASEDATE, HOLDING.QUOTE_SYMBOL,HOLDING.ACCOUNT_ACCOUNTID 
 			from holding WHERE HOLDING.ACCOUNT_ACCOUNTID = (SELECT ACCOUNTID 
 			FROM ACCOUNT WHERE PROFILE_USERID = '$userID') ORDER BY HOLDING.HOLDINGID DESC";
 			
-		$result = ExecuteQuery($query);
+		$result = $db->ExecuteQuery($query);
 		if($result)
 		{
 			$response = new getHoldingsResponse();
 			$response->getHoldingsReturn = new ArrayOfHoldingDataBean();
 			
 			$rawNo = 0;
-			while(($holdingID = GetMSSQLValue($result, $rawNo, 0)))
+			while(($holdingID = $db->GetSQLValue($result, $rawNo, 0)))
 			{
 				$response->getHoldingsReturn->HoldingDataBean[$rawNo] 
 					= new HoldingDataBean();
 				$response->getHoldingsReturn->HoldingDataBean[$rawNo]->
-					holdingID = GetMSSQLValue($result, $rawNo, 0);
+					holdingID = $db->GetSQLValue($result, $rawNo, 0);
 				$response->getHoldingsReturn->HoldingDataBean[$rawNo]->
-					quantity = GetMSSQLValue($result, $rawNo, 1);
+					quantity = $db->GetSQLValue($result, $rawNo, 1);
 				$response->getHoldingsReturn->HoldingDataBean[$rawNo]->
-					purchasePrice = GetMSSQLValue($result, $rawNo, 2);
+					purchasePrice = $db->GetSQLValue($result, $rawNo, 2);
 				$response->getHoldingsReturn->HoldingDataBean[$rawNo]->
-					purchaseDate = formatDate(GetMSSQLValue($result, $rawNo, 3));
+					purchaseDate = formatDate($db->GetSQLValue($result, $rawNo, 3));
 				$response->getHoldingsReturn->HoldingDataBean[$rawNo]->
-					quoteID = GetMSSQLValue($result, $rawNo, 4);
+					quoteID = $db->GetSQLValue($result, $rawNo, 4);
 				$rawNo = $rawNo + 1;	
 			}		
 		}
-		CloseDatabase($dbhandle);	
+		$db->CloseDatabase();	
 	}
 	return $response;
 }
@@ -1018,17 +1010,17 @@
  */
 function processGetClosedOrders($userID)
 {
-	$dbhandle = ConnectToDatabase();
+	$db = GetDatabase();
 	$response = null;
-	if ($dbhandle)
+	if ($db)
 	{
-        $query = "Set NOCOUNT ON; SELECT ORDERID, ORDERTYPE, ORDERSTATUS, 
+        $query = "SELECT ORDERID, ORDERTYPE, ORDERSTATUS, 
 			COMPLETIONDATE, OPENDATE, QUANTITY, PRICE, ORDERFEE, QUOTE_SYMBOL 
 			FROM orders WHERE ACCOUNT_ACCOUNTID = (select accountid from 
-			account WITH(NOLOCK) where profile_userid = '$userID') AND 
+			account  where profile_userid = '$userID') AND 
 			ORDERSTATUS = 'closed'";
 		
-		$result = ExecuteQuery($query);
+		$result = $db->ExecuteQuery($query);
 		
 		if ($result)
 		{
@@ -1036,39 +1028,39 @@
 			$response->getClosedOrdersReturn = new ArrayOfOrderDataBean();
 			$rawNo = 0;
 			
-			while(($orderID = GetMSSQLValue($result, $rawNo, 0)))
+			while(($orderID = $db->GetSQLValue($result, $rawNo, 0)))
 			{
 				$response->getClosedOrdersReturn->OrderDataBean[$rawNo] = 
 					new OrderDataBean();
 				$response->getClosedOrdersReturn->OrderDataBean[$rawNo]->
 					orderID = $orderID;
 				$response->getClosedOrdersReturn->OrderDataBean[$rawNo]->
-					orderType = GetMSSQLValue($result, 0, 1);
+					orderType = $db->GetSQLValue($result, 0, 1);
 				$response->getClosedOrdersReturn->OrderDataBean[$rawNo]->
-					orderStatus = GetMSSQLValue($result, $rawNo, 2);
+					orderStatus = $db->GetSQLValue($result, $rawNo, 2);
 				$response->getClosedOrdersReturn->OrderDataBean[$rawNo]->
-					completionDate = formatDate(GetMSSQLValue($result, $rawNo, 3));
+					completionDate = formatDate($db->GetSQLValue($result, $rawNo, 3));
 				$response->getClosedOrdersReturn->OrderDataBean[$rawNo]->
-					openDate = formatDate(GetMSSQLValue($result, $rawNo, 4));
+					openDate = formatDate($db->GetSQLValue($result, $rawNo, 4));
 				$response->getClosedOrdersReturn->OrderDataBean[$rawNo]->
-					quantity = GetMSSQLValue($result, $rawNo, 5);
+					quantity = $db->GetSQLValue($result, $rawNo, 5);
 				$response->getClosedOrdersReturn->OrderDataBean[$rawNo]->
-					price = GetMSSQLValue($result, $rawNo, 6);
+					price = $db->GetSQLValue($result, $rawNo, 6);
 				$response->getClosedOrdersReturn->OrderDataBean[$rawNo]->
-					orderFee = GetMSSQLValue($result, $rawNo, 7);
+					orderFee = $db->GetSQLValue($result, $rawNo, 7);
 				$response->getClosedOrdersReturn->OrderDataBean[$rawNo]->
-					symbol = GetMSSQLValue($result, $rawNo, 8);
+					symbol = $db->GetSQLValue($result, $rawNo, 8);
 				
 				$rawNo = $rawNo + 1;
 			}
 			
 			$query = "UPDATE orders SET ORDERSTATUS = 'completed' where 
 				ORDERSTATUS = 'closed' AND ACCOUNT_ACCOUNTID = (select accountid 
-				from account WITH (NOLOCK) where profile_userid = '$userID')";
+				from account where profile_userid = '$userID')";
 				
-			ExecuteQuery($query);
+			$db->ExecuteQuery($query);
 		}
-		CloseDatabase($dbhandle);
+		$db->CloseDatabase();
 	}
 	return $response;	
 }
@@ -1081,29 +1073,29 @@
  */
 function processGetAccountProfileData($userID)
 {
-	$dbhandle = ConnectToDatabase();
+	$db = GetDatabase();
 	$response = null;
-	if($dbhandle)
+	if($db)
 	{
-        $query = "Set NOCOUNT ON; SELECT accountprofile.USERID, accountprofile.PASSWORD, 
+        $query = "SELECT accountprofile.USERID, accountprofile.PASSWORD, 
 		accountprofile.FULLNAME, accountprofile.ADDRESS, accountprofile.EMAIL, 
-		accountprofile.CREDITCARD FROM accountprofile WITH (NOLOCK) WHERE 
+		accountprofile.CREDITCARD FROM accountprofile WHERE 
 		accountprofile.USERID = '$userID'";
 		
-		$result = ExecuteQuery($query);
+		$result = $db->ExecuteQuery($query);
 		
 		if($result)
 		{
 			$response = new getAccountProfileDataResponse();
 			$response->getAccountProfileDataReturn = new AccountProfileDataBean();
 			$response->getAccountProfileDataReturn->userID = $userID;
-			$response->getAccountProfileDataReturn->password = GetMSSQLValue($result, 0, 1);
-			$response->getAccountProfileDataReturn->fullName = GetMSSQLValue($result, 0, 2);
-			$response->getAccountProfileDataReturn->address = GetMSSQLValue($result, 0, 3);
-			$response->getAccountProfileDataReturn->email = GetMSSQLValue($result, 0, 4);
-			$response->getAccountProfileDataReturn->creditCard = GetMSSQLValue($result, 0, 5);
+			$response->getAccountProfileDataReturn->password = $db->GetSQLValue($result, 0, 1);
+			$response->getAccountProfileDataReturn->fullName = $db->GetSQLValue($result, 0, 2);
+			$response->getAccountProfileDataReturn->address = $db->GetSQLValue($result, 0, 3);
+			$response->getAccountProfileDataReturn->email = $db->GetSQLValue($result, 0, 4);
+			$response->getAccountProfileDataReturn->creditCard = $db->GetSQLValue($result, 0, 5);
 		}
-		CloseDatabase($dbhandle);
+		$db->CloseDatabase();
 	}
 	return $response;
 }
@@ -1115,31 +1107,31 @@
  */
 function processGetAccountData($userID)
 {
-	$dbhandle = ConnectToDatabase();
+	$db = GetDatabase();
 	$response = null;
-	if($dbhandle)
+	if($db)
 	{
-		$query = "Set NOCOUNT ON; SELECT account.ACCOUNTID, account.PROFILE_USERID, 
+		$query = "SELECT account.ACCOUNTID, account.PROFILE_USERID, 
 				account.CREATIONDATE, account.OPENBALANCE, account.LOGOUTCOUNT, 
 				account.BALANCE, account.LASTLOGIN, account.LOGINCOUNT FROM account 
 				WHERE account.PROFILE_USERID = '$userID'";
 				
-		$result = ExecuteQuery($query);
+		$result = $db->ExecuteQuery($query);
 	
 		if ($result)
 		{
 			$response = new getAccountDataResponse();
 			$response->getAccountDataReturn = new AccountDataBean();
-			$response->getAccountDataReturn->accountID = GetMSSQLValue($result, 0, 0);
-			$response->getAccountDataReturn->profileID = GetMSSQLValue($result, 0, 1);
-			$response->getAccountDataReturn->creationDate = formatDate(GetMSSQLValue($result, 0, 2));
-			$response->getAccountDataReturn->openBalance = GetMSSQLValue($result, 0, 3);
-			$response->getAccountDataReturn->logoutCount = GetMSSQLValue($result, 0, 4);
-			$response->getAccountDataReturn->balance = GetMSSQLValue($result, 0, 5);
-			$response->getAccountDataReturn->lastLogin = formatDate(GetMSSQLValue($result, 0, 6));
-			$response->getAccountDataReturn->loginCount = GetMSSQLValue($result, 0, 7);
+			$response->getAccountDataReturn->accountID = $db->GetSQLValue($result, 0, 0);
+			$response->getAccountDataReturn->profileID = $db->GetSQLValue($result, 0, 1);
+			$response->getAccountDataReturn->creationDate = formatDate($db->GetSQLValue($result, 0, 2));
+			$response->getAccountDataReturn->openBalance = $db->GetSQLValue($result, 0, 3);
+			$response->getAccountDataReturn->logoutCount = $db->GetSQLValue($result, 0, 4);
+			$response->getAccountDataReturn->balance = $db->GetSQLValue($result, 0, 5);
+			$response->getAccountDataReturn->lastLogin = formatDate($db->GetSQLValue($result, 0, 6));
+			$response->getAccountDataReturn->loginCount = $db->GetSQLValue($result, 0, 7);
 		}
-		CloseDatabase($dbhandle);
+		$db->CloseDatabase();
 	}
 	return $response;
 }
@@ -1151,18 +1143,18 @@
  */
 function processGetOrders($userID)
 {
-	$dbhandle = ConnectToDatabase();
+	$db = GetDatabase();
 	$response = null;
-	if($dbhandle)
+	if($db)
 	{
 		$query = "SELECT ORDERID, ORDERTYPE, ORDERSTATUS, OPENDATE, 
 			COMPLETIONDATE, QUANTITY, PRICE, ORDERFEE, QUOTE_SYMBOL FROM 
 			ORDERS WHERE ORDERS.ACCOUNT_ACCOUNTID = (select ACCOUNT.ACCOUNTID 
-			from ACCOUNT WITH (NOLOCK)  WHERE ACCOUNT.PROFILE_USERID = 
+			from ACCOUNT  WHERE ACCOUNT.PROFILE_USERID = 
 			'$userID') ORDER BY ORDERS.ORDERID DESC";
 		
 								
-		$result = ExecuteQuery($query);
+		$result = $db->ExecuteQuery($query);
 		
 		if($result)
 		{		
@@ -1170,33 +1162,33 @@
 			$response->getOrdersReturn = new ArrayOfOrderDataBean();
 			$rawNo = 0;
 			
-			while(($orderID = GetMSSQLValue($result, $rawNo, 0)))
+			while(($orderID = $db->GetSQLValue($result, $rawNo, 0)))
 			{
 				$response->getOrdersReturn->OrderDataBean[$rawNo] = 
 					new OrderDataBean();
 				$response->getOrdersReturn->OrderDataBean[$rawNo]->
 					orderID = $orderID;
 				$response->getOrdersReturn->OrderDataBean[$rawNo]->
-					orderType = GetMSSQLValue($result, $rawNo, 1);
+					orderType = $db->GetSQLValue($result, $rawNo, 1);
 				$response->getOrdersReturn->OrderDataBean[$rawNo]->
-					orderStatus = GetMSSQLValue($result, $rawNo, 2);
+					orderStatus = $db->GetSQLValue($result, $rawNo, 2);
 				$response->getOrdersReturn->OrderDataBean[$rawNo]->
-					openDate = formatDate(GetMSSQLValue($result, $rawNo, 3));
+					openDate = formatDate($db->GetSQLValue($result, $rawNo, 3));
 				$response->getOrdersReturn->OrderDataBean[$rawNo]->
-					completionDate = formatDate(GetMSSQLValue($result, $rawNo, 4));
+					completionDate = formatDate($db->GetSQLValue($result, $rawNo, 4));
 				$response->getOrdersReturn->OrderDataBean[$rawNo]->
-					quantity = GetMSSQLValue($result, $rawNo, 5);
+					quantity = $db->GetSQLValue($result, $rawNo, 5);
 				$response->getOrdersReturn->OrderDataBean[$rawNo]->
-					price = GetMSSQLValue($result, $rawNo, 6);
+					price = $db->GetSQLValue($result, $rawNo, 6);
 				$response->getOrdersReturn->OrderDataBean[$rawNo]->
-					orderFee = GetMSSQLValue($result, $rawNo, 7);
+					orderFee = $db->GetSQLValue($result, $rawNo, 7);
 				$response->getOrdersReturn->OrderDataBean[$rawNo]->
-					symbol = GetMSSQLValue($result, $rawNo, 8);
+					symbol = $db->GetSQLValue($result, $rawNo, 8);
 				
 				$rawNo = $rawNo + 1;
 			}
 		}
-		CloseDatabase($dbhandle);
+		$db->CloseDatabase();
 	}
 	return $response;
 }
@@ -1209,46 +1201,48 @@
  */
 function processLogin($userID, $password)
 {
-	$dbhandle = ConnectToDatabase();
+	$db = GetDatabase();
 	$response = null;
-	if ($dbhandle)
+	if ($db)
 	{
-		$query = "Set NOCOUNT ON; SELECT ACCOUNTPROFILE.USERID, 
+		$query = "SELECT ACCOUNTPROFILE.USERID, 
 			ACCOUNTPROFILE.PASSWORD, ACCOUNTPROFILE.FULLNAME, 
 			ACCOUNTPROFILE.ADDRESS, ACCOUNTPROFILE.EMAIL, 
-			ACCOUNTPROFILE.CREDITCARD FROM ACCOUNTPROFILE WITH (NOLOCK) 
+			ACCOUNTPROFILE.CREDITCARD FROM ACCOUNTPROFILE 
 			WHERE ACCOUNTPROFILE.USERID = '$userID'";
 		
-		$result = ExecuteQuery($query);
+		$result = $db->ExecuteQuery($query);
 		
-		if ($password == GetMSSQLValue($result, 0, 1))
+		if ($password == $db->GetSQLValue($result, 0, 1))
 		{
-			$query = "UPDATE ACCOUNT WITH (ROWLOCK) SET LOGINCOUNT 
+			$query = "UPDATE ACCOUNT SET LOGINCOUNT 
 				= (LOGINCOUNT + 1), LASTLOGIN = CURRENT_TIMESTAMP where 
-				PROFILE_USERID = '$userID'; 
-				SELECT ACCOUNT.ACCOUNTID, ACCOUNT.CREATIONDATE, 
+				PROFILE_USERID = '$userID'"; 
+			$result = $db->ExecuteQuery($query);
+			
+			$query = "SELECT ACCOUNT.ACCOUNTID, ACCOUNT.CREATIONDATE, 
 				ACCOUNT.OPENBALANCE, ACCOUNT.LOGOUTCOUNT, 
 				ACCOUNT.BALANCE, ACCOUNT.LASTLOGIN, ACCOUNT.LOGINCOUNT 
-				FROM ACCOUNT WITH (ROWLOCK) WHERE 
+				FROM ACCOUNT WHERE 
 				ACCOUNT.PROFILE_USERID = '$userID'";
 			
 			$result = null;
-			$result = ExecuteQuery($query);
+			$result = $db->ExecuteQuery($query);
 			if ($result)
 			{
 				$response = new loginResponse();
 				$response->loginReturn = new AccountDataBean();
-				$response->loginReturn->accountID = GetMSSQLValue($result, 0, 0);
-				$response->loginReturn->creationDate = formatDate(GetMSSQLValue($result, 0, 1));
-				$response->loginReturn->openBalance = GetMSSQLValue($result, 0, 2);
-				$response->loginReturn->logoutCount = GetMSSQLValue($result, 0, 3);
-				$response->loginReturn->balance = GetMSSQLValue($result, 0, 4);
-				$response->loginReturn->lastLogin = formatDate(GetMSSQLValue($result, 0, 5));
-				$response->loginReturn->loginCount = GetMSSQLValue($result, 0, 6);
+				$response->loginReturn->accountID = $db->GetSQLValue($result, 0, 0);
+				$response->loginReturn->creationDate = formatDate($db->GetSQLValue($result, 0, 1));
+				$response->loginReturn->openBalance = $db->GetSQLValue($result, 0, 2);
+				$response->loginReturn->logoutCount = $db->GetSQLValue($result, 0, 3);
+				$response->loginReturn->balance = $db->GetSQLValue($result, 0, 4);
+				$response->loginReturn->lastLogin = formatDate($db->GetSQLValue($result, 0, 5));
+				$response->loginReturn->loginCount = $db->GetSQLValue($result, 0, 6);
 				$response->loginReturn->profileID = $userID;
 			}
 		}
-		CloseDatabase($dbhandle);
+		$db->CloseDatabase();
 	}
 	return $response;
 }

Modified: incubator/stonehenge/trunk/stocktrader/php/business_service/order_processor_proxy.php
URL: http://svn.apache.org/viewvc/incubator/stonehenge/trunk/stocktrader/php/business_service/order_processor_proxy.php?rev=767459&r1=767458&r2=767459&view=diff
==============================================================================
--- incubator/stonehenge/trunk/stocktrader/php/business_service/order_processor_proxy.php (original)
+++ incubator/stonehenge/trunk/stocktrader/php/business_service/order_processor_proxy.php Wed Apr 22 10:48:13 2009
@@ -154,7 +154,7 @@
 	if (!($service))
 	{
 		$service = 
-			"http://localhost:8080/config_service/config_svc.php";
+			"http://localhost:8080/php_stocktrader/config_service/config_svc.php";
 	}
 	return $service;
 }

Modified: incubator/stonehenge/trunk/stocktrader/php/config_service/config_svc.php
URL: http://svn.apache.org/viewvc/incubator/stonehenge/trunk/stocktrader/php/config_service/config_svc.php?rev=767459&r1=767458&r2=767459&view=diff
==============================================================================
--- incubator/stonehenge/trunk/stocktrader/php/config_service/config_svc.php (original)
+++ incubator/stonehenge/trunk/stocktrader/php/config_service/config_svc.php Wed Apr 22 10:48:13 2009
@@ -29,37 +29,37 @@
 		/* we support MSSQL and MySQL only. If DBName is something else, we should not process anything */
 		if(($DBConfig->DBName == DBNAME_MSSQL) || ($DBConfig->DBName == DBNAME_MYSQL))
 		{
-			$dbhandle = ConnectToDatabase();
+			$db = GetDatabase();
 
 			/* "BEGIN TRAN" initialize a transaction; which privides control so that later we can cancel 
 			 * the transaction, if something goes wrong. */
-			if(ExecuteQuery("BEGIN TRAN"))
+			if($db->ExecuteQuery("BEGIN TRAN"))
 			{
-				$result = getDBConfig($DBConfig->DBName);
+				$result = getDBConfig($DBConfig->DBName, $db);
 				if($result)
 				{
 					/* this detail is already available. So we should update the records */
 					$query = "UPDATE DBCONFIG WITH (ROWLOCK) SET HOSTNAME='$DBConfig->DBHostName', ".
 					   "PORT='$DBConfig->DBPort' WHERE DBNAME = '$DBConfig->DBName'";
-					$status = ExecuteQuery($query);
+					$status = $db->ExecuteQuery($query);
 				}
 				else
 				{
 					/* details related to this database is not stored. So we have to insert a new record */
 					$query = "INSERT INTO DBCONFIG (DBNAME, HOSTNAME, PORT, ACTIVE) VALUES (".
 						"'$DBConfig->DBName', '$DBConfig->DBHostName', '$DBConfig->DBPort', 'N');";
-					$status = ExecuteQuery($query);
+					$status = $db->ExecuteQuery($query);
 				}
 
 				if($status)
 				{
 					/* Transaction is successfull, we can safely commit the transaction into the database. */
-					ExecuteQuery("COMMIT TRAN");
+					$db->ExecuteQuery("COMMIT TRAN");
 				}
 				else
 				{
 					/* Transaction is not successfull, we have to rollback the transaction */
-					ExecuteQuery("ROLLBACK TRAN");
+					$db->ExecuteQuery("ROLLBACK TRAN");
 					error_log("Storing DBConfig failed. \n");
 				}
 			}
@@ -68,7 +68,7 @@
 				error_log("Cannot initialise a transaction using BEGIN TRAN. \n");
 			}
 
-			CloseDatabase($dbhandle);
+			$db->CloseDatabase();
 		}
 		else
 		{
@@ -85,27 +85,27 @@
  */
 function getDBConfigs($GetDBConfigs)
 {
-	$dbhandle = ConnectToDatabase();
+	$db = GetDatabase();
 
 	$query = "Set NOCOUNT ON; SELECT DBNAME, HOSTNAME, PORT FROM DBCONFIG";
 
-	$result =  ExecuteQuery($query);
+	$result =  $db->ExecuteQuery($query);
 	if ($result)
 	{
 		$rowNum = 0;
 		$DBConfigs = new DBConfigs();
-		while($DBName = GetMSSQLValue($result, $rowNum, 0))
+		while($DBName = $db->GetSQLValue($result, $rowNum, 0))
 		{
 			$config = new DBConfig();
 			$config->DBName =  $DBName;	//Get the DB Name
-			$config->DBHostName = GetMSSQLValue($result, $rowNum, 1); //Get the host name.
-			$config->DBPort = GetMSSQLValue($result, $rowNum, 2); 	//Get the port
+			$config->DBHostName = $db->GetSQLValue($result, $rowNum, 1); //Get the host name.
+			$config->DBPort = $db->GetSQLValue($result, $rowNum, 2); 	//Get the port
 			$DBConfigs->DBConfig[$rowNum] = $config;
 			$rowNum = $rowNum + 1;
 		}
 	}
 
-	CloseDatabase($dbhandle);
+	$db->CloseDatabase();
 	return $DBConfigs;
 }
 
@@ -122,28 +122,28 @@
 		if(($DBName == DBNAME_MSSQL) || ($DBName == DBNAME_MYSQL))
 		{
 			
-			$dbhandle = ConnectToDatabase();
+			$db = GetDatabase();
 
 			/* check whether DBConfig related to this database is already there. If not there, we can't 
 			 * set it as active */
-			if(getDBConfig($DBName))
+			if(getDBConfig($DBName, $db))
 			{
 				/* "BEGIN TRAN" initialize a transaction; which privides control so that later we can cancel 
 				 * the transaction, if something goes wrong. */
-				if(ExecuteQuery("BEGIN TRAN"))
+				if($db->ExecuteQuery("BEGIN TRAN"))
 				{
 					$query = "UPDATE DBCONFIG WITH (ROWLOCK) SET ACTIVE='Y' WHERE DBNAME='$DBName'";
-					$status = ExecuteQuery($query);
+					$status = $db->ExecuteQuery($query);
 
 					if($status)
 					{
 						/* Transaction is successfull, we can safely commit the transaction into the database. */
-						ExecuteQuery("COMMIT TRAN");
+						$db->ExecuteQuery("COMMIT TRAN");
 					}
 					else
 					{
 						/* Transaction is not successfull, we have to rollback the transaction */
-						ExecuteQuery("ROLLBACK TRAN");
+						$db->ExecuteQuery("ROLLBACK TRAN");
 						error_log("Storing Active DB failed. \n");
 					}
 				}
@@ -156,7 +156,7 @@
 			{
 				error_log("Cannot find DBConfig related to $DBName. Could not be able to set active \n");
 			}
-			CloseDatabase($dbhandle);
+			$db->CloseDatabase();
 		}
 		else
 		{
@@ -173,9 +173,9 @@
  */
 function getActiveDB($GetActiveDB)
 {
-	$dbhandle = ConnectToDatabase();
+	$db = GetDatabase();
 
-	$DBConfig = getActiveDBConfig();
+	$DBConfig = getActiveDBConfig($db);
 	if($DBConfig)
 	{
 		$config = new ActiveDB();
@@ -186,7 +186,7 @@
 		error_log("Cannot find details about active database \n");
 	}
 
-	CloseDatabase($dbhandle);
+	$db->CloseDatabase();
 	return $config;
 }
 
@@ -202,38 +202,38 @@
 			|| isOrderProcessorServiceDefined($ServiceLocation->ServiceName)
 			|| isOrderProcessorSecDefined($ServiceLocation->ServiceName))
 		{
-			$dbhandle = ConnectToDatabase();
+			$db = GetDatabase();
 
 			/* "BEGIN TRAN" initialize a transaction; which privides control so that later we can cancel 
 			 * the transaction, if something goes wrong. */
-			if(ExecuteQuery("BEGIN TRAN"))
+			if($db->ExecuteQuery("BEGIN TRAN"))
 			{
-				$result = getServiceLocation($ServiceLocation->ServiceName);
+				$result = getServiceLocation($ServiceLocation->ServiceName, $db);
 				if($result)
 				{
 					/* this detail is already available. So we should update the records */
 					$query = "UPDATE SERVICE WITH (ROWLOCK) SET URL='$ServiceLocation->ServiceURL' ".
 					   "WHERE SERVICENAME = '$ServiceLocation->ServiceName'";
-					$status = ExecuteQuery($query);
+					$status = $db->ExecuteQuery($query);
 				}
 				else
 				{
 					/* details related to this database is not stored. So we have to insert a new record */
 					$query = "INSERT INTO SERVICE (SERVICENAME, URL) VALUES (".
 						"'$ServiceLocation->ServiceName', '$ServiceLocation->ServiceURL')";
-					$status = ExecuteQuery($query);
+					$status = $db->ExecuteQuery($query);
 				}
 				
 
 				if($status)
 				{
 					/* Transaction is successfull, we can safely commit the transaction into the database. */
-					ExecuteQuery("COMMIT TRAN");
+					$db->ExecuteQuery("COMMIT TRAN");
 				}
 				else
 				{
 					/* Transaction is not successfull, we have to rollback the transaction */
-					ExecuteQuery("ROLLBACK TRAN");
+					$db->ExecuteQuery("ROLLBACK TRAN");
 					error_log("Storing service location configuration failed. \n");
 				}
 			}
@@ -242,7 +242,7 @@
 				error_log("Cannot initialise a transaction using BEGIN TRAN. \n");
 			}
 
-			CloseDatabase($dbhandle);
+			$db->CloseDatabase();
 		}
 		else
 		{
@@ -258,26 +258,26 @@
  */
 function getServiceLocations($GetServiceLocations)
 {
-	$dbhandle = ConnectToDatabase();
+	$db = GetDatabase();
 
 	$query = "Set NOCOUNT ON; SELECT SERVICENAME, URL FROM SERVICE";
 
-	$result =  ExecuteQuery($query);
+	$result =  $db->ExecuteQuery($query);
 	if ($result)
 	{
 		$rowNum = 0;
 		$ServiceLocations = new ServiceLocations();
-		while($ServiceName = GetMSSQLValue($result, $rowNum, 0))
+		while($ServiceName = $db->GetSQLValue($result, $rowNum, 0))
 		{
 			$config = new ServiceLocation();
 			$config->ServiceName =  $ServiceName;	//Get the service name 
-			$config->ServiceURL = GetMSSQLValue($result, $rowNum, 1); //Get the URL
+			$config->ServiceURL = $db->GetSQLValue($result, $rowNum, 1); //Get the URL
 			$ServiceLocations->ServiceLocation[$rowNum] = $config;
 			$rowNum = $rowNum + 1;
 		}
 	}
 
-	CloseDatabase($dbhandle);
+	$db->CloseDatabase();
 	return $ServiceLocations;
 }
 
@@ -295,37 +295,37 @@
 			if(isClientDefined($ClientToBS->Client))
 			{
 				/* both client name and business service are valid. we can store it */
-				$dbhandle = ConnectToDatabase();
+				$db = GetDatabase();
 
 				/* "BEGIN TRAN" initialize a transaction; which privides control so that later we can cancel 
 				 * the transaction, if something goes wrong. */
-				if(ExecuteQuery("BEGIN TRAN"))
+				if($db->ExecuteQuery("BEGIN TRAN"))
 				{
-					$result = getClientToBS($ClientToBS->Client);
+					$result = getClientToBS($ClientToBS->Client, $db);
 					if($result)
 					{
 						/* this detail is already available. So we should update the records */
 						$query = "UPDATE CLIENTTOBS WITH (ROWLOCK) SET BS='$ClientToBS->BS' ".
 						   "WHERE CLIENT = '$ClientToBS->Client'";
-						$status = ExecuteQuery($query);
+						$status = $db->ExecuteQuery($query);
 					}
 					else
 					{
 						/* details related to this database is not stored. So we have to insert a new record */
 						$query = "INSERT INTO CLIENTTOBS (CLIENT, BS) VALUES (".
 							"'$ClientToBS->Client', '$ClientToBS->BS')";
-						$status = ExecuteQuery($query);
+						$status = $db->ExecuteQuery($query);
 					}
 
 					if($status)
 					{
 						/* Transaction is successfull, we can safely commit the transaction into the database. */
-						ExecuteQuery("COMMIT TRAN");
+						$db->ExecuteQuery("COMMIT TRAN");
 					}
 					else
 					{
 						/* Transaction is not successfull, we have to rollback the transaction */
-						ExecuteQuery("ROLLBACK TRAN");
+						$db->ExecuteQuery("ROLLBACK TRAN");
 						error_log("Storing service location configuration failed. \n");
 					}
 				}
@@ -334,7 +334,7 @@
 					error_log("Cannot initialise a transaction using BEGIN TRAN. \n");
 				}
 
-				CloseDatabase($dbhandle);
+				$db->CloseDatabase();
 			}
 			else
 			{
@@ -355,26 +355,26 @@
  */
 function getClientToBSConnections($GetClientToBSConnections)
 {
-	$dbhandle = ConnectToDatabase();
+	$db = GetDatabase();
 
 	$query = "Set NOCOUNT ON; SELECT CLIENT, BS FROM CLIENTTOBS";
 
-	$result =  ExecuteQuery($query);
+	$result =  $db->ExecuteQuery($query);
 	if ($result)
 	{
 		$rowNum = 0;
 		$ClientToBSConnections = new ClientToBSConnections();
-		while($ClientName = GetMSSQLValue($result, $rowNum, 0))
+		while($ClientName = $db->GetSQLValue($result, $rowNum, 0))
 		{
 			$config = new ClientToBS();
 			$config->Client =  $ClientName;	//Get the client name 
-			$config->BS = GetMSSQLValue($result, $rowNum, 1); //Get the BS Name
+			$config->BS = $db->GetSQLValue($result, $rowNum, 1); //Get the BS Name
 			$ClientToBSConnections->ClientToBS[$rowNum] = $config;
 			$rowNum = $rowNum + 1;
 		}
 	}
 
-	CloseDatabase($dbhandle);
+	$db->CloseDatabase();
 	return $ClientToBSConnections;
 }
 
@@ -392,36 +392,36 @@
 			if(isOrderProcessorServiceDefined($BSToOPS->OPS) || isOrderProcessorSecDefined($BSToOPS->OPS))
 			{
 				/* both order processor and business service are valid. we can store it */
-				$dbhandle = ConnectToDatabase();
+				$db = GetDatabase();
 
 				/* "BEGIN TRAN" initialize a transaction; which privides control so that later we can cancel 
 				 * the transaction, if something goes wrong. */
-				if(ExecuteQuery("BEGIN TRAN"))
+				if($db->ExecuteQuery("BEGIN TRAN"))
 				{
-					$result = getBSToOPS($BSToOPS->BS);
+					$result = getBSToOPS($BSToOPS->BS, $db);
 					if($result)
 					{
 						/* this detail is already available. So we should update the records */
 						$query = "UPDATE BSTOOPS WITH (ROWLOCK) SET OPS='$BSToOPS->OPS' ".
 						   "WHERE BS = '$BSToOPS->BS'";
-						$status = ExecuteQuery($query);
+						$status = $db->ExecuteQuery($query);
 					}
 					else
 					{
 						/* details related to this database is not stored. So we have to insert a new record */
 						$query = "INSERT INTO BSTOOPS (BS, OPS) VALUES ('$BSToOPS->BS', '$BSToOPS->OPS')";
-						$status = ExecuteQuery($query);
+						$status = $db->ExecuteQuery($query);
 					}
 
 					if($status)
 					{
 						/* Transaction is successfull, we can safely commit the transaction into the database. */
-						ExecuteQuery("COMMIT TRAN");
+						$db->ExecuteQuery("COMMIT TRAN");
 					}
 					else
 					{
 						/* Transaction is not successfull, we have to rollback the transaction */
-						ExecuteQuery("ROLLBACK TRAN");
+						$db->ExecuteQuery("ROLLBACK TRAN");
 						error_log("Storing service location configuration failed. \n");
 					}
 				}
@@ -430,7 +430,7 @@
 					error_log("Cannot initialise a transaction using BEGIN TRAN. \n");
 				}
 
-				CloseDatabase($dbhandle);
+				$db->CloseDatabase();
 			}
 			else
 			{
@@ -451,26 +451,26 @@
  */
 function getBSToOPSConnections($GetBSToOPSConnections)
 {
-	$dbhandle = ConnectToDatabase();
+	$db = GetDatabase();
 
 	$query = "Set NOCOUNT ON; SELECT BS, OPS FROM BSTOOPS";
 
-	$result =  ExecuteQuery($query);
+	$result =  $db->ExecuteQuery($query);
 	if ($result)
 	{
 		$rowNum = 0;
 		$BSToOPSConnections = new BSToOPSConnections();
-		while($BSName = GetMSSQLValue($result, $rowNum, 0))
+		while($BSName = $db->GetSQLValue($result, $rowNum, 0))
 		{
 			$config = new BSToOPS();
 			$config->BS =  $BSName;	//Get the BS name 
-			$config->OPS = GetMSSQLValue($result, $rowNum, 1); //Get the OPS Name
+			$config->OPS = $db->GetSQLValue($result, $rowNum, 1); //Get the OPS Name
 			$BSToOPSConnections->BSToOPS[$rowNum] = $config;
 			$rowNum = $rowNum + 1;
 		}
 	}
 
-	CloseDatabase($dbhandle);
+	$db->CloseDatabase();
 	return $BSToOPSConnections;
 }
 
@@ -483,12 +483,12 @@
 {
 	if($ClientConfigRequest)
 	{
-		$dbhandle = ConnectToDatabase();
+		$db = GetDatabase();
 
-		$ClientToBS = getClientToBS($ClientConfigRequest->Client);
+		$ClientToBS = getClientToBS($ClientConfigRequest->Client, $db);
 		if($ClientToBS)
 		{
-			$serviceLocation = getServiceLocation($ClientToBS->BS);
+			$serviceLocation = getServiceLocation($ClientToBS->BS, $db);
 			if($serviceLocation)
 			{
 				$config = new ClientConfigResponse();
@@ -505,7 +505,7 @@
 				"[$ClientConfigRequest->Client]. \n");
 		}
 
-		CloseDatabase($dbhandle);
+		$db->CloseDatabase();
 	}
 
 	return $config;
@@ -520,16 +520,16 @@
 {
 	if($BSConfigRequest)
 	{
-		$dbhandle = ConnectToDatabase();
+		$db = GetDatabase();
 
-		$BSToOPS = getBSToOPS($BSConfigRequest->BS);
+		$BSToOPS = getBSToOPS($BSConfigRequest->BS, $db);
 		if($BSToOPS)
 		{
-			$serviceLocation = getServiceLocation($BSToOPS->OPS);
+			$serviceLocation = getServiceLocation($BSToOPS->OPS, $db);
 			if($serviceLocation)
 			{
 				/* found the end point url of order processor service. Now check for active database settings */
-				$DBConfig = getActiveDBConfig();
+				$DBConfig = getActiveDBConfig($db);
 				if($DBConfig)
 				{
 					$config = new BSConfigResponse();
@@ -562,7 +562,7 @@
 			   " [$BSConfigRequest->BS]. \n");
 		}
 
-		CloseDatabase($dbhandle);
+		$db->CloseDatabase();
 	}
 	return $config;
 }
@@ -574,9 +574,9 @@
  */
 function getOPSConfig($OPS)
 {
-	$dbhandle = ConnectToDatabase();
+	$db = GetDatabase();
 
-	$DBConfig = getActiveDBConfig();
+	$DBConfig = getActiveDBConfig($db);
 	if($DBConfig)
 	{
 		$config = new OPSConfigResponse();
@@ -589,7 +589,7 @@
 		error_log("Cannot find details about active database \n");
 	}
 
-	CloseDatabase($dbhandle);
+	$db->CloseDatabase();
 	return $config;
 }
 

Modified: incubator/stonehenge/trunk/stocktrader/php/config_service/config_svc_processor.php
URL: http://svn.apache.org/viewvc/incubator/stonehenge/trunk/stocktrader/php/config_service/config_svc_processor.php?rev=767459&r1=767458&r2=767459&view=diff
==============================================================================
--- incubator/stonehenge/trunk/stocktrader/php/config_service/config_svc_processor.php (original)
+++ incubator/stonehenge/trunk/stocktrader/php/config_service/config_svc_processor.php Wed Apr 22 10:48:13 2009
@@ -17,7 +17,7 @@
  */
 
  
-require_once ("data_access_layer.php");
+require_once ("../data_layer/data_access_layer.php");
 require_once ("class_info.php");
 
 define ("DBNAME_MSSQL", "MSSQL");
@@ -133,18 +133,19 @@
 /**
  * gets Service Location of given service
  * @param $serviceName service name for which we have to find config details
+ * @param $db database object
  * @return if successful, ServiceLocation object filled with information. NULL otherwise
  */
-function getServiceLocation($serviceName)
+function getServiceLocation($serviceName, $db)
 {
-	$query = "Set NOCOUNT ON; SELECT SERVICENAME, URL FROM SERVICE WHERE SERVICENAME = '$serviceName'";
+	$query = "SELECT SERVICENAME, URL FROM SERVICE WHERE SERVICENAME = '$serviceName'";
 
-	$result =  ExecuteQuery($query);
-	if (($result) && (GetMSSQLValue($result, 0, 0)))	//return value is having atleast one row
+	$result =  $db->ExecuteQuery($query);
+	if (($result) && ($db->GetSQLValue($result, 0, 0)))	//return value is having atleast one row
 	{
 		$config = new ServiceLocation();
 		$config->ServiceName =  $serviceName;
-		$config->ServiceURL = GetMSSQLValue($result, 0, 1); //Get the url of the service
+		$config->ServiceURL = $db->GetSQLValue($result, 0, 1); //Get the url of the service
 	}
 	return $config;
 }
@@ -152,18 +153,19 @@
 /**
  * gets connection between client and BS
  * @param $client client name for which we have to find config details
+ * @param $db database object
  * @return if successful, ClientToBS object filled with information. NULL otherwise
  */
-function getClientToBS($client)
+function getClientToBS($client, $db)
 {
-	$query = "Set NOCOUNT ON; SELECT CLIENT, BS FROM CLIENTTOBS WHERE CLIENT = '$client'";
+	$query = "SELECT CLIENT, BS FROM CLIENTTOBS WHERE CLIENT = '$client'";
 
-	$result =  ExecuteQuery($query);
-	if (($result) && (GetMSSQLValue($result, 0, 0)))	//return value is having atleast one row
+	$result =  $db->ExecuteQuery($query);
+	if (($result) && ($db->GetSQLValue($result, 0, 0)))	//return value is having atleast one row
 	{
 		$config = new ClientToBS();
 		$config->Client =  $client;
-		$config->BS = GetMSSQLValue($result, 0, 1); //Get the BS name connected to client
+		$config->BS = $db->GetSQLValue($result, 0, 1); //Get the BS name connected to client
 	}
 	return $config;
 }
@@ -171,18 +173,19 @@
 /**
  * gets connection between BS and OPS
  * @param $BS business service name for which we have to find config details
+ * @param $db database object
  * @return if successful, BSToOPS object filled with information. NULL otherwise
  */
-function getBSToOPS($BS)
+function getBSToOPS($BS, $db)
 {
-	$query = "Set NOCOUNT ON; SELECT BS, OPS FROM BSTOOPS WHERE BS = '$BS'";
+	$query = "SELECT BS, OPS FROM BSTOOPS WHERE BS = '$BS'";
 
-	$result =  ExecuteQuery($query);
-	if (($result) && (GetMSSQLValue($result, 0, 0)))		//return value is having atleast one row
+	$result =  $db->ExecuteQuery($query);
+	if (($result) && ($db->GetSQLValue($result, 0, 0)))		//return value is having atleast one row
 	{
 		$config = new BSToOPS();
 		$config->BS =  $BS;
-		$config->OPS = GetMSSQLValue($result, 0, 1); //Get the OPS name connected to BS
+		$config->OPS = $db->GetSQLValue($result, 0, 1); //Get the OPS name connected to BS
 	}
 	return $config;
 }
@@ -190,38 +193,40 @@
 /**
  * gets DBConfig of given database
  * @param $DBName database name for which we have to find config details
+ * @param $db database object
  * @return if successful, DBConfig object filled with information. NULL otherwise
  */
-function getDBConfig($DBName)
+function getDBConfig($DBName, $db)
 {
-	$query = "Set NOCOUNT ON; SELECT DBNAME, HOSTNAME, PORT FROM DBCONFIG WHERE DBNAME = '$DBName'";
+	$query = "SELECT DBNAME, HOSTNAME, PORT FROM DBCONFIG WHERE DBNAME = '$DBName'";
 
-	$result =  ExecuteQuery($query);
-	if (($result) && (GetMSSQLValue($result, 0, 0))) 		//return value is having atleast one row
+	$result =  $db->ExecuteQuery($query);
+	if (($result) && ($db->GetSQLValue($result, 0, 0))) 		//return value is having atleast one row
 	{
 		$config = new DBConfig();
 		$config->DBName =  $DBName;
-		$config->DBHostName = GetMSSQLValue($result, 0, 1); //Get the host name.
-		$config->DBPort = GetMSSQLValue($result, 0, 2); 	//Get the port
+		$config->DBHostName = $db->GetSQLValue($result, 0, 1); //Get the host name.
+		$config->DBPort = $db->GetSQLValue($result, 0, 2); 	//Get the port
 	}
 	return $config;
 }
 
 /**
  * gets DBConfig of active database
+ * @param $db database object
  * @return if successful, DBConfig object filled with information. NULL otherwise
  */
-function getActiveDBConfig()
+function getActiveDBConfig($db)
 {
-	$query = "Set NOCOUNT ON; SELECT DBNAME, HOSTNAME, PORT FROM DBCONFIG WHERE ACTIVE = 'Y'";
+	$query = "SELECT DBNAME, HOSTNAME, PORT FROM DBCONFIG WHERE ACTIVE = 'Y'";
 
-	$result =  ExecuteQuery($query);
-	if (($result) && (GetMSSQLValue($result, 0, 0)))		//return value is having atleast one row
+	$result =  $db->ExecuteQuery($query);
+	if (($result) && ($db->GetSQLValue($result, 0, 0)))		//return value is having atleast one row
 	{
 		$config = new DBConfig();
-		$config->DBName =  GetMSSQLValue($result, 0, 0);	//Get the db name.
-		$config->DBHostName = GetMSSQLValue($result, 0, 1); //Get the host name.
-		$config->DBPort = GetMSSQLValue($result, 0, 2); 	//Get the port
+		$config->DBName =  $db->GetSQLValue($result, 0, 0);	//Get the db name.
+		$config->DBHostName = $db->GetSQLValue($result, 0, 1); //Get the host name.
+		$config->DBPort = $db->GetSQLValue($result, 0, 2); 	//Get the port
 	}
 	return $config;
 }

Added: incubator/stonehenge/trunk/stocktrader/php/data_layer/data_access_layer.php
URL: http://svn.apache.org/viewvc/incubator/stonehenge/trunk/stocktrader/php/data_layer/data_access_layer.php?rev=767459&view=auto
==============================================================================
--- incubator/stonehenge/trunk/stocktrader/php/data_layer/data_access_layer.php (added)
+++ incubator/stonehenge/trunk/stocktrader/php/data_layer/data_access_layer.php Wed Apr 22 10:48:13 2009
@@ -0,0 +1,84 @@
+<?php 
+/*
+ * 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.
+ */
+
+require_once ("mssql_database.php");
+require_once ("mysql_database.php");
+
+/**
+ * The method retrieves information for the database connection
+ * from a configuration file. The name of the config file should
+ * be, database_config.xml, and it should be in the same directory
+ * as this file.
+ * @return non NULL value (ConnectionInfo object), upon successfull 
+ * execution, and NULL if some information regarding the 
+ * connection is not available.
+ */
+
+define ("RDBMS_TYPE_MSSQL", "mssql");
+define ("RDBMS_TYPE_MYSQL", "mysql");
+
+function GetConnectionInfo()
+{
+	$doc = new DOMDocument();
+	$result = $doc->load('../resources/conf/database_config.xml');
+
+	$server = $doc->getElementsByTagName("server")->item(0)->nodeValue;
+	$user = $doc->getElementsByTagName("user")->item(0)->nodeValue;
+	$password = $doc->getElementsByTagName("password")->item(0)->nodeValue;
+	$database = $doc->getElementsByTagName("database")->item(0)->nodeValue;
+	$type = $doc->getElementsByTagName("type")->item(0)->nodeValue;
+
+	if ($server == NULL || $user == NULL || $password == NULL || $database == NULL || $type == NULL)
+	{
+		error_log ("SERVER, USER, PASSWORD OR DATABASE IS NULL\n");
+	}
+	else
+	{
+		$ConnInfo = new ConnectionInfo();
+		$ConnInfo->server = $server;
+		$ConnInfo->user = $user;
+		$ConnInfo->password = $password;
+		$ConnInfo->database = $database;
+		$ConnInfo->type = $type;
+	}
+	return $ConnInfo;
+}
+
+/**
+ * This method will load the configurations using GetConnectionInfo method and then creates 
+ * correct database connection using the configurations 
+ */
+function GetDatabase()
+{
+	$connInfo = GetConnectionInfo();
+	if($connInfo != NULL)
+	{
+		if($connInfo->type == RDBMS_TYPE_MSSQL)
+		{	
+			$db = new MSSQLDatabase($connInfo);
+		}
+		else
+		{
+			$db = new MySQLDatabase($connInfo);
+		}
+		$db->ConnectToDatabase();
+		return $db;
+	}
+}
+
+?>

Added: incubator/stonehenge/trunk/stocktrader/php/data_layer/database.php
URL: http://svn.apache.org/viewvc/incubator/stonehenge/trunk/stocktrader/php/data_layer/database.php?rev=767459&view=auto
==============================================================================
--- incubator/stonehenge/trunk/stocktrader/php/data_layer/database.php (added)
+++ incubator/stonehenge/trunk/stocktrader/php/data_layer/database.php Wed Apr 22 10:48:13 2009
@@ -0,0 +1,88 @@
+<?php 
+/*
+ * 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.
+ */
+
+/**
+ * This class encapsulates information regarding the establishment
+ * of database connection.
+ */
+class ConnectionInfo
+{
+	public $server; 	//The database server (eg: 127.0.0.1:1433)
+	public $user;		//User name 
+	public $password;	//Password
+	public $database;	//Database name
+	public $type;		//RDBMS type (eg: mssql, mysql)
+}
+
+/** 
+ * This class gives an abstract interfaces to generic database
+ */
+abstract class Database
+{
+	/**
+	 * This method establishes a connection to the database. 
+	 * @return boolean, upon successfull execution true is returned. 
+	 * Otherwise false will be returned. 
+	 */
+	abstract public function ConnectToDatabase();
+
+	/**
+	 * This method close the connection that is established to the
+	 * database.
+	 */
+	abstract public function CloseDatabase();
+
+	/**
+	 * This method executes a query that it receives.
+	 * @param query the query to execute
+	 * @return non-NULL upon success and NULL otherwise.
+	 */
+	abstract public function ExecuteQuery($query);
+
+	/**
+	 * This method returns the a value from a sql result set (a tuple
+	 * returned after execution of ExecuteQuery method.
+	 * @param result, the result obtained from ExecuteQuery method.
+	 * @param raw, the raw number
+	 * @param column, the column number
+	 * @return the value at (raw, column) of the tuple.
+	 */
+	abstract public function GetSQLValue($result, $raw, $column);
+
+	/**
+	 * Gets the ID of the last inserted record. returns -1 if error
+	 */
+	abstract public function GetInsertID();
+
+	/**
+	 * Begin a transaction. return status will be not null if success
+	 */
+	abstract public function BeginTransaction();
+
+	/**
+	 * Commit a transaction. return status will be not null if success
+	 */
+	abstract public function CommitTransaction();
+
+	/**
+	 * Rollback a transaction.return status will be not null if success
+	 */
+	abstract public function RollbackTransaction();
+}
+
+?>

Added: incubator/stonehenge/trunk/stocktrader/php/data_layer/mssql_database.php
URL: http://svn.apache.org/viewvc/incubator/stonehenge/trunk/stocktrader/php/data_layer/mssql_database.php?rev=767459&view=auto
==============================================================================
--- incubator/stonehenge/trunk/stocktrader/php/data_layer/mssql_database.php (added)
+++ incubator/stonehenge/trunk/stocktrader/php/data_layer/mssql_database.php Wed Apr 22 10:48:13 2009
@@ -0,0 +1,134 @@
+<?php 
+/*
+ * 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.
+ */
+
+require_once ("database.php");
+
+/** 
+ * This class gives implementation of MSSQL database
+ */
+class MSSQLDatabase extends Database
+{
+	/**
+	 * handle to the database
+	 */
+	protected $dbhandle;
+
+	/**
+	 * Connection informations
+	 */
+	protected $connectionInfo;
+
+	/**
+	 * Constructor
+	 * @param connectioninfo
+	 */
+	public function MSSQLDatabase($connInfo)
+	{
+		$this->connectionInfo = $connInfo;	
+	}
+
+	/**
+	 * This method establishes a connection to the database. 
+	 * @return boolean, upon successfull execution true is returned. 
+	 * Otherwise false will be returned. 
+	 */
+	public function ConnectToDatabase()
+	{
+		if ($this->connectionInfo != NULL)
+		{
+			$this->dbhandle = mssql_connect($this->connectionInfo->server, $this->connectionInfo->user, $this->connectionInfo->password)
+				or die ("Couldn't connect to the server!!!");
+			$selected = mssql_select_db($this->connectionInfo->database, $this->dbhandle) 
+				or die ("Couldn't open the database!!!");
+		}
+		return true;
+	}
+
+	/**
+	 * This method close the connection that is established to the
+	 * database.
+	 */
+	public function CloseDatabase()
+	{
+		mssql_close($this->dbhandle);
+	}
+
+	/**
+	 * This method executes a query that it receives.
+	 * @param query the query to execute
+	 * @return non-NULL upon success and NULL otherwise.
+	 */
+	public function ExecuteQuery($query)
+	{
+		return mssql_query($query, $this->dbhandle);
+	}
+
+	/**
+	 * This method returns the a value from a sql result set (a tuple
+	 * returned after execution of ExecuteQuery method.
+	 * @param result, the result obtained from ExecuteQuery method.
+	 * @param raw, the raw number
+	 * @param column, the column number
+	 * @return the value at (raw, column) of the tuple.
+	 */
+	public function GetSQLValue($result, $raw, $column)
+	{
+		return mssql_result($result, $raw, $column);
+	}
+
+	/**
+	 * Gets the ID of the last inserted record. returns -1 if error. 
+	 */
+	public function GetInsertID()
+	{
+		$result = $this->ExecuteQuery("SELECT @@identity");
+		if(!$result)
+		{
+			return -1;
+		}
+		else
+		{
+			return $this->GetSQLValue($result, 0, 0);
+		}
+	}
+
+	/**
+	 * Begin a transaction. return status will be not null if success
+	 */
+	public function BeginTransaction()
+	{
+		return $this->ExecuteQuery("BEGIN TRAN");
+	}
+
+	/**
+	 * Commit a transaction.  return status will be not null if success
+	 */
+	public function CommitTransaction()
+	{
+		return $this->ExecuteQuery("COMMIT TRAN");
+	}
+
+	/**
+	 * Rollback a transaction. return status will be not null if success
+	 */
+	public function RollbackTransaction()
+	{
+		return $this->ExecuteQuery("COMMIT TRAN");
+	}
+}
+?>

Added: incubator/stonehenge/trunk/stocktrader/php/data_layer/mysql_database.php
URL: http://svn.apache.org/viewvc/incubator/stonehenge/trunk/stocktrader/php/data_layer/mysql_database.php?rev=767459&view=auto
==============================================================================
--- incubator/stonehenge/trunk/stocktrader/php/data_layer/mysql_database.php (added)
+++ incubator/stonehenge/trunk/stocktrader/php/data_layer/mysql_database.php Wed Apr 22 10:48:13 2009
@@ -0,0 +1,134 @@
+<?php 
+/*
+ * 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.
+ */
+
+require_once ("database.php");
+
+/** 
+ * This class gives implementation of MySQL database
+ */
+class MySQLDatabase extends Database
+{
+	/**
+	 * handle to the database
+	 */
+	protected $dbhandle;
+
+	/**
+	 * Connection informations
+	 */
+	protected $connectionInfo;
+
+	/**
+	 * Constructor
+	 * @param connectioninfo
+	 */
+	public function MySQLDatabase($connInfo)
+	{
+		$this->connectionInfo = $connInfo;	
+	}
+
+	/**
+	 * This method establishes a connection to the database. 
+	 * @return boolean, upon successfull execution true is returned. 
+	 * Otherwise false will be returned. 
+	 */
+	public function ConnectToDatabase()
+	{
+		if ($this->connectionInfo != NULL)
+		{
+			$this->dbhandle = mysql_connect($this->connectionInfo->server, $this->connectionInfo->user, $this->connectionInfo->password)
+				or die ("Couldn't connect to the server!!!");
+			$selected = mysql_select_db($this->connectionInfo->database, $this->dbhandle) 
+				or die ("Couldn't open the database!!!");
+		}
+		return true;
+	}
+
+	/**
+	 * This method close the connection that is established to the
+	 * database.
+	 */
+	public function CloseDatabase()
+	{
+		mysql_close($this->dbhandle);
+	}
+
+	/**
+	 * This method executes a query that it receives.
+	 * @param query the query to execute
+	 * @return non-NULL upon success and NULL otherwise.
+	 */
+	public function ExecuteQuery($query)
+	{
+		return mysql_query($query, $this->dbhandle);
+	}
+
+	/**
+	 * This method returns the a value from a sql result set (a tuple
+	 * returned after execution of ExecuteQuery method.
+	 * @param result, the result obtained from ExecuteQuery method.
+	 * @param raw, the raw number
+	 * @param column, the column number
+	 * @return the value at (raw, column) of the tuple.
+	 */
+	public function GetSQLValue($result, $raw, $column)
+	{
+		return mysql_result($result, $raw, $column);
+	}
+
+	/**
+	 * Gets the ID of the last inserted record. returns -1 if error. 
+	 */
+	public function GetInsertID()
+	{
+		$insertID = mysql_insert_id($this->dbhandle);
+		if($insertID == NULL)
+		{
+			return -1;
+		}
+		else
+		{
+			return $insertID;
+		}
+	}
+
+	/**
+	 * Begin a transaction. return status will be not null if success
+	 */
+	public function BeginTransaction()
+	{
+		return $this->ExecuteQuery("START TRANSACTION");
+	}
+
+	/**
+	 * Commit a transaction.  return status will be not null if success
+	 */
+	public function CommitTransaction()
+	{
+		return $this->ExecuteQuery("COMMIT");
+	}
+
+	/**
+	 * Rollback a transaction. return status will be not null if success
+	 */
+	public function RollbackTransaction()
+	{
+		return $this->ExecuteQuery("ROLLBACK");
+	}
+}
+?>

Modified: incubator/stonehenge/trunk/stocktrader/php/order_processor/order_processor.php
URL: http://svn.apache.org/viewvc/incubator/stonehenge/trunk/stocktrader/php/order_processor/order_processor.php?rev=767459&r1=767458&r2=767459&view=diff
==============================================================================
--- incubator/stonehenge/trunk/stocktrader/php/order_processor/order_processor.php (original)
+++ incubator/stonehenge/trunk/stocktrader/php/order_processor/order_processor.php Wed Apr 22 10:48:13 2009
@@ -17,7 +17,7 @@
  */
 
  
-require_once ("data_access_layer.php");
+require_once ("../data_layer/data_access_layer.php");
 
 define ("ORDER_TYPE_BUY", "buy");
 define ("ORDER_TYPE_SELL", "sell");
@@ -95,16 +95,16 @@
 function ProcessOrder($order)
 {
 	$status = STATUS_SUCCESS;
-	$dbhandle = ConnectToDatabase();
+	$db = GetDatabase();
 
-	/*This method with "BEGIN TRAN" initialize a transaction; which privides 
+	/*This method with initialize a transaction; which privides 
 	control so that later we can cancel a the transaction, if something 
 	goes wrong.*/
 
-	$status = ExecuteQuery("BEGIN TRAN"); 
+	$status = $db->BeginTransaction();
 	if ($status)
 	{
-		$quote = GetQuoteForUpdate($order->symbol);
+		$quote = GetQuoteForUpdate($order->symbol, $db);
 		if ($quote)
 		{
 			$order->price = $quote->price;
@@ -121,7 +121,7 @@
 
 			if ($order->orderType == ORDER_TYPE_BUY)
 			{
-				$holdingID = CreateHolding($order);
+				$holdingID = CreateHolding($order, $db);
 				if ($holdingID != INVALID_ID)
 				{
 					$totalPrice = 
@@ -130,7 +130,7 @@
 			}
 			if ($order->orderType == ORDER_TYPE_SELL)
 			{
-				$holdingID = SellHolding($order);
+				$holdingID = SellHolding($order, $db);
 				if ($holdingID != INVALID_ID)
 				{
 					$totalPrice = -1 * $order->quantity * $order->price + 
@@ -141,7 +141,7 @@
 			if ($holdingID != INVALID_ID)
 			{
 				$status = UpdateSystemStatus($order, 
-					$quote, $holdingID, $totalPrice);
+					$quote, $holdingID, $totalPrice, $db);
 			}
 			else
 			{
@@ -161,16 +161,16 @@
 		/*Transaction is successfull, we can safely commit the transaction
 		into the database.*/
 
-		ExecuteQuery("COMMIT TRAN");
+		$db->CommitTransaction();
 	}
 	else
 	{
 		/*Transaction is not successfull, we can safely rollback the 
 		transaction without commiting to the database.*/
 
-		ExecuteQuery("ROLLBACK TRAN");
+		$db->RollbackTransaction();
 	}
-	CloseDatabase($dbhandle);
+	$db->CloseDatabase();
 }
 
 /**
@@ -181,22 +181,22 @@
  * NULL is returned.
  */
 
-function GetQuoteForUpdate($symbol)
+function GetQuoteForUpdate($symbol, $db)
 {
-	$query = "Set NOCOUNT ON; SELECT SYMBOL, COMPANYNAME, VOLUME, PRICE, ".
-		"OPEN1, LOW, HIGH, CHANGE1 FROM QUOTE WITH (NOLOCK) WHERE SYMBOL ".
+	$query = "SELECT SYMBOL, COMPANYNAME, VOLUME, PRICE, ".
+		"OPEN1, LOW, HIGH, CHANGE1 FROM QUOTE WHERE SYMBOL ".
 		"= '$symbol'";
 
 	/*Get the tuple corresponding to the particular symbol*/
 
-	$result =  ExecuteQuery($query);
+	$result =  $db->ExecuteQuery($query);
 	if ($result)
 	{
 		$quote = new Quote();
-		$quote->symbol =  GetMSSQLValue($result, 0, 0);	//Get the symbol.
-		$quote->price = GetMSSQLValue($result, 0, 3); //Get the price.
-		$quote->low = GetMSSQLValue($result, 0, 5); //Get the low value.
-		$quote->high =  GetMSSQLValue($result, 0, 6); //Get the high value.
+		$quote->symbol =  $db->GetSQLValue($result, 0, 0);	//Get the symbol.
+		$quote->price = $db->GetSQLValue($result, 0, 3); //Get the price.
+		$quote->low = $db->GetSQLValue($result, 0, 5); //Get the low value.
+		$quote->high =  $db->GetSQLValue($result, 0, 6); //Get the high value.
 	}
 	return $quote;
 }
@@ -212,17 +212,17 @@
  * @return STATUS_SUCCESS upon success and STATUS_FAILURE otherwise.
  */
 
-function UpdateSystemStatus($order, $quote, $holdingID, $totalPrice)
+function UpdateSystemStatus($order, $quote, $holdingID, $totalPrice, $db)
 {
 	$status = STATUS_SUCCESS;
-	$accountID = GetAccountIDFromOrder($order);
+	$accountID = GetAccountIDFromOrder($order, $db);
 	if ($accountID != INVALID_ID)
 	{
-		if(UpdateAccountBalance($accountID, $totalPrice))
+		if(UpdateAccountBalance($accountID, $totalPrice, $db))
 		{
-			if(UpdateStockPriceVolume($order->quantity, $quote))
+			if(UpdateStockPriceVolume($order->quantity, $quote, $db))
 			{
-				if(!CloseOrder($order, $holdingID))
+				if(!CloseOrder($order, $holdingID, $db))
 				{
 					error_log ("Cannot close order for order id ". $order->orderID. " \n");
 					$status = STATUS_FAILURE;
@@ -255,9 +255,9 @@
  * @return a non NULL holdingID upon success and NULL otherwise.
  */
 
-function SellHolding($order)
+function SellHolding($order, $db)
 {
-	$holding = GetHoldingForUpdate($order);
+	$holding = GetHoldingForUpdate($order, $db);
 	if ($holding)
 	{
 		$accountID = $holding->accountID;
@@ -266,7 +266,7 @@
 
 		if ($order->quantity < $holding->quantity)
 		{
-			if(!UpdateHolding($holding, $order->quantity))
+			if(!UpdateHolding($holding, $order->quantity, $db))
 			{
 				error_log ("Cannot update holding with holding id ".$holding->holdingID. " \n");
 				$holding->holdingID = INVALID_ID;
@@ -274,7 +274,7 @@
 		}
 		else if ($order->quantity == $holding->quantity)
 		{
-			if(!DeleteHolding($holding))
+			if(!DeleteHolding($holding, $db))
 			{
 				error_log ("Cannot delete holding with holding id ".$holding->holdingID. " \n");
 				$holding->holdingID = INVALID_ID;
@@ -282,7 +282,7 @@
 		}
 		else
 		{
-			if(!DeleteHolding($holding))
+			if(!DeleteHolding($holding, $db))
 			{
 				error_log ("Cannot delete holding with holding id ".$holding->holdingID. " \n");
 				$holding->holdingID = INVALID_ID;
@@ -290,7 +290,7 @@
 			else
 			{
 				$order->quantity = $holding->quantity;
-				if(!UpdateOrder($order))
+				if(!UpdateOrder($order, $db))
 				{
 					error_log ("Cannot update order with order id ".$order->orderID. " \n");
 					$holding->holdingID = INVALID_ID;
@@ -313,11 +313,11 @@
  * @return NON-NULL on success and NULL on failure.
  */
 
-function UpdateOrder($order)
+function UpdateOrder($order, $db)
 {
-	$query = "UPDATE ORDERS WITH (ROWLOCK) SET QUANTITY='$order->quantity' WHERE".
+	$query = "UPDATE ORDERS SET QUANTITY='$order->quantity' WHERE".
 		" ORDERID='$order->orderID'";
-	return ExecuteQuery($query);
+	return $db->ExecuteQuery($query);
 }
 
 /**
@@ -327,11 +327,11 @@
  * $return NON-NULL on success or NULL otherwise.
  */
 
-function UpdateHolding($holding, $quantity)
+function UpdateHolding($holding, $quantity, $db)
 {
-	$query = "UPDATE HOLDING WITH (ROWLOCK) SET QUANTITY=QUANTITY-'$quantity'".
+	$query = "UPDATE HOLDING SET QUANTITY=QUANTITY-'$quantity'".
 		" WHERE HOLDINGID='$holding->holdingID'";
-	return ExecuteQuery($query);
+	return $db->ExecuteQuery($query);
 }
 
 /**
@@ -340,11 +340,11 @@
  * @return NON-NULL value on success and NULL otherwise.
  */
 
-function DeleteHolding($holding)
+function DeleteHolding($holding, $db)
 {
-	$query = "DELETE FROM HOLDING WITH (ROWLOCK) WHERE ".
+	$query = "DELETE FROM HOLDING WHERE ".
 		"HOLDINGID='$holding->holdingID'";
-	return ExecuteQuery($query);
+	return $db->ExecuteQuery($query);
 }
 
 /**
@@ -354,28 +354,28 @@
  * @return a Holding object upon success and NULL otherwise.
  */
 
-function GetHoldingForUpdate($order)
+function GetHoldingForUpdate($order, $db)
 {
-	$query = "Set NOCOUNT ON; SELECT HOLDING.HOLDINGID, HOLDING.ACCOUNT_ACCOUNTID,".
+	$query = "SELECT HOLDING.HOLDINGID, HOLDING.ACCOUNT_ACCOUNTID,".
 		" HOLDING.QUANTITY, HOLDING.PURCHASEPRICE, HOLDING.PURCHASEDATE,".
-		" HOLDING.QUOTE_SYMBOL FROM HOLDING WITH (ROWLOCK) INNER JOIN ORDERS".
+		" HOLDING.QUOTE_SYMBOL FROM HOLDING INNER JOIN ORDERS".
 		" ON HOLDING.HOLDINGID = ORDERS.HOLDING_HOLDINGID WHERE ".
 		"(ORDERS.ORDERID = '$order->orderID')";
 
 	/*Get the machining tuple from HOLDING table, that corresponds to the 
 	current sell operation.*/
 
-	$result = ExecuteQuery($query);
+	$result = $db->ExecuteQuery($query);
 	
 	if ($result)
 	{
 		$holding = new Holding();	
-		$holding->holdingID = GetMSSQLValue($result, 0, 0); //Get the holdingID.
-		$holding->accountID = GetMSSQLValue($result, 0, 1); //Get the accountID.
-		$holding->quantity = GetMSSQLValue($result, 0, 2); //Get the quantity.
-		$holding->purchasePrice = GetMSSQLValue($result, 0, 3); //Get the price.
-		$holding->purchaseDate = GetMSSQLValue($result, 0, 4); //Get the date.
-		$holding->quoteSymbol = GetMSSQLValue($result, 0, 5); //Get the symbol.
+		$holding->holdingID = $db->GetSQLValue($result, 0, 0); //Get the holdingID.
+		$holding->accountID = $db->GetSQLValue($result, 0, 1); //Get the accountID.
+		$holding->quantity = $db->GetSQLValue($result, 0, 2); //Get the quantity.
+		$holding->purchasePrice = $db->GetSQLValue($result, 0, 3); //Get the price.
+		$holding->purchaseDate = $db->GetSQLValue($result, 0, 4); //Get the date.
+		$holding->quoteSymbol = $db->GetSQLValue($result, 0, 5); //Get the symbol.
 	}
 	else
 	{
@@ -392,18 +392,18 @@
  * @return NON-NULL on success and NULL on failure.
  */
 
-function CloseOrder($order, $holdingID)
+function CloseOrder($order, $holdingID, $db)
 {
 	$order->orderStatus = ORDER_STATUS_CLOSED;
 	if ($order->orderType == ORDER_TYPE_SELL)
 	{
-		$holdingID = NULL;
+		$holdingID = "NULL";
 	}
-	$query = "UPDATE ORDERS WITH (ROWLOCK) SET ".
+	$query = "UPDATE ORDERS SET ".
 		"ORDERSTATUS='".ORDER_STATUS_CLOSED."',".
-		" COMPLETIONDATE=GetDate(), HOLDING_HOLDINGID='$holdingID',".
+		" COMPLETIONDATE=CURRENT_TIMESTAMP, HOLDING_HOLDINGID=$holdingID,".
 		" PRICE='$order->price' WHERE ORDERID='$order->orderID'";
-	return ExecuteQuery($query);
+	return $db->ExecuteQuery($query);
 }
 
 /**
@@ -413,21 +413,18 @@
  * returns NULL 
  */
 
-function CreateHolding($order)
+function CreateHolding($order, $db)
 {
-	$accountID = GetAccountIDFromOrder($order);
+	$accountID = GetAccountIDFromOrder($order, $db);
 	if ($accountID != INVALID_ID)
 	{
 		$query = "INSERT INTO HOLDING (PURCHASEPRICE, QUANTITY, PURCHASEDATE,".
 			" ACCOUNT_ACCOUNTID, QUOTE_SYMBOL) VALUES ('$order->price',".
-			" '$order->quantity', GetDate(), '$accountID', '$order->symbol');".
-			" SELECT ID=@@IDENTITY";
-		$result = ExecuteQuery($query);
-		if ($result)
-		{
-			$holdingID = GetMSSQLValue($result, 0, 0); 
-		}
-		else
+			" '$order->quantity', CURRENT_TIMESTAMP, '$accountID', '$order->symbol')";
+
+		$result = $db->ExecuteQuery($query);
+		$holdingID = $db->GetInsertID();
+		if ($holdingID == -1)
 		{
 			error_log ("Cannot create holding for order id ". $order->orderID . "\n");
 			$holdingID = INVALID_ID;
@@ -447,17 +444,17 @@
  * @return NON-NULL accountID upon success and NULL otherwise. 
  */
 
-function GetAccountIDFromOrder($order)
+function GetAccountIDFromOrder($order, $db)
 {
-	$query = "Set NOCOUNT ON; SELECT ACCOUNT_ACCOUNTID FROM ORDERS WITH ".
-		"(NOLOCK) WHERE ORDERID='$order->orderID'";
+	$query = "SELECT ACCOUNT_ACCOUNTID FROM ORDERS ".
+		" WHERE ORDERID='$order->orderID'";
 
 	/*Get a tuple including accountID for a particular order*/
 
-	$result = ExecuteQuery($query);
+	$result = $db->ExecuteQuery($query);
 	if ($result != NULL)
 	{
-		$accountID = GetMSSQLValue($result, 0, 0); //Get accountID.
+		$accountID = $db->GetSQLValue($result, 0, 0); //Get accountID.
 	}
 	else
 	{
@@ -475,11 +472,11 @@
  * @return NON-NULL upon success and NULL on failure.
  */
 
-function UpdateAccountBalance($accountID, $amount)
+function UpdateAccountBalance($accountID, $amount, $db)
 {
-	$query = "UPDATE ACCOUNT WITH (ROWLOCK) SET BALANCE=(BALANCE - '$amount')".
+	$query = "UPDATE ACCOUNT SET BALANCE=(BALANCE - '$amount')".
 		" WHERE ACCOUNTID = '$accountID'";
-	return ExecuteQuery($query);
+	return $db->ExecuteQuery($query);
 }
 
 /**
@@ -490,7 +487,7 @@
  * @return STATUS_SUCCESS upon success and STATUS_FAILURE upon failure.
  */
 
-function UpdateStockPriceVolume($quantity, $quote)
+function UpdateStockPriceVolume($quantity, $quote, $db)
 {
 	if ($quote)
 	{
@@ -512,11 +509,11 @@
 			$quote->high = $quote->price;
 		}
 
-		$query = "UPDATE QUOTE WITH (ROWLOCK) SET PRICE='$quote->price', ".
+		$query = "UPDATE QUOTE SET PRICE='$quote->price', ".
 			"LOW='$quote->low', HIGH='$quote->high', CHANGE1='$quote->price' - ".
 			"OPEN1, VOLUME=VOLUME+'$quantity' WHERE SYMBOL='$quote->symbol'";
 
-		$status = ExecuteQuery($query);
+		$status = $db->ExecuteQuery($query);
 	}
 	return $status;
 }

Modified: incubator/stonehenge/trunk/stocktrader/php/resources/conf/database_config.xml
URL: http://svn.apache.org/viewvc/incubator/stonehenge/trunk/stocktrader/php/resources/conf/database_config.xml?rev=767459&r1=767458&r2=767459&view=diff
==============================================================================
--- incubator/stonehenge/trunk/stocktrader/php/resources/conf/database_config.xml (original)
+++ incubator/stonehenge/trunk/stocktrader/php/resources/conf/database_config.xml Wed Apr 22 10:48:13 2009
@@ -21,4 +21,23 @@
 	<user>trade</user>
 	<password>trade</password>
 	<database>StockTraderDB</database>
+	<type>mssql</type>
 </config>
+
+<!--config for MSSQL 
+<config>
+	<server>127.0.0.1,1433</server>
+	<user>trade</user>
+	<password>trade</password>
+	<database>StockTraderDB</database>
+	<type>mssql</type>
+</config>-->
+
+<!--config for MySQL 
+<config>
+	<server>127.0.0.1:3306</server>
+	<user>trade</user>
+	<password>trade</password>
+	<database>StockTraderDB</database>
+	<type>mysql</type>
+</config>-->