DBName == DBNAME_MSSQL) || ($DBConfig->DBName == DBNAME_MYSQL)) { $db = GetDatabase(); /* "BEGIN TRAN" initialize a transaction; which privides control so that later we can cancel * the transaction, if something goes wrong. */ if($db->ExecuteQuery("BEGIN TRAN")) { $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 = $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 = $db->ExecuteQuery($query); } if($status) { /* Transaction is successfull, we can safely commit the transaction into the database. */ $db->ExecuteQuery("COMMIT TRAN"); } else { /* Transaction is not successfull, we have to rollback the transaction */ $db->ExecuteQuery("ROLLBACK TRAN"); error_log("Storing DBConfig failed. \n"); } } else { error_log("Cannot initialise a transaction using BEGIN TRAN. \n"); } $db->CloseDatabase(); } else { error_log("Cannot support database $DBConfig->DBName. Supported databases are ". DBNAME_MSSQL." and ".DBNAME_MYSQL.".\n"); } } } /** Get database configuration for all DBs * @namespace http://apache.org/stonehenge/stocktrader * @param object GetDBConfigs $GetDBConfigs * @return object DBConfigs $DBConfigs */ function getDBConfigs($GetDBConfigs) { $db = GetDatabase(); $query = "Set NOCOUNT ON; SELECT dbname, hostname, port FROM dbconfig"; $result = $db->ExecuteQuery($query); if ($result) { $rowNum = 0; $DBConfigs = new DBConfigs(); while($DBName = $db->GetSQLValue($result, $rowNum, 0)) { $config = new DBConfig(); $config->DBName = $DBName; //Get the DB Name $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; } } $db->CloseDatabase(); return $DBConfigs; } /** Sets active database. * @namespace http://apache.org/stonehenge/stocktrader * @param object ActiveDB $ActiveDB Name of the active database */ function setActiveDB($ActiveDB) { if($ActiveDB) { $DBName = $ActiveDB->DBName; /* we support MSSQL and MySQL only. If DBName is something else, we should not process anything */ if(($DBName == DBNAME_MSSQL) || ($DBName == DBNAME_MYSQL)) { $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, $db)) { /* "BEGIN TRAN" initialize a transaction; which privides control so that later we can cancel * the transaction, if something goes wrong. */ if($db->ExecuteQuery("BEGIN TRAN")) { $query = "UPDATE dbconfig WITH (ROWLOCK) SET active='Y' WHERE dbname='$DBName'"; $status = $db->ExecuteQuery($query); if($status) { /* Transaction is successfull, we can safely commit the transaction into the database. */ $db->ExecuteQuery("COMMIT TRAN"); } else { /* Transaction is not successfull, we have to rollback the transaction */ $db->ExecuteQuery("ROLLBACK TRAN"); error_log("Storing Active DB failed. \n"); } } else { error_log("Cannot initialise a transaction using BEGIN TRAN. \n"); } } else { error_log("Cannot find DBConfig related to $DBName. Could not be able to set active \n"); } $db->CloseDatabase(); } else { error_log("Cannot set database $DBName as active. Supported databases are ". DBNAME_MSSQL." and ".DBNAME_MYSQL.".\n"); } } } /** Get active database. * @namespace http://apache.org/stonehenge/stocktrader * @param object GetActiveDB $GetActiveDB * @return object ActiveDB $CurrentActiveDB Name of the active database */ function getActiveDB($GetActiveDB) { $db = GetDatabase(); $DBConfig = getActiveDBConfig($db); if($DBConfig) { $config = new ActiveDB(); $config->DBName = $DBConfig->DBName; } else { error_log("Cannot find details about active database \n"); } $db->CloseDatabase(); return $config; } /** Sets service location (End point URL) of a given service. * @namespace http://apache.org/stonehenge/stocktrader * @param object ServiceLocation $ServiceLocation */ function setServiceLocation($ServiceLocation) { if($ServiceLocation) { if(isBusinessServiceDefined($ServiceLocation->ServiceName) || isOrderProcessorServiceDefined($ServiceLocation->ServiceName) || isOrderProcessorSecDefined($ServiceLocation->ServiceName)) { $db = GetDatabase(); /* "BEGIN TRAN" initialize a transaction; which privides control so that later we can cancel * the transaction, if something goes wrong. */ if($db->ExecuteQuery("BEGIN TRAN")) { $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 = $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 = $db->ExecuteQuery($query); } if($status) { /* Transaction is successfull, we can safely commit the transaction into the database. */ $db->ExecuteQuery("COMMIT TRAN"); } else { /* Transaction is not successfull, we have to rollback the transaction */ $db->ExecuteQuery("ROLLBACK TRAN"); error_log("Storing service location configuration failed. \n"); } } else { error_log("Cannot initialise a transaction using BEGIN TRAN. \n"); } $db->CloseDatabase(); } else { error_log("Service name $ServiceLocation->ServiceName is not supported by the system.\n"); } } } /** Gets all service locations * @namespace http://apache.org/stonehenge/stocktrader * @param object GetServiceLocations $GetServiceLocations * @return object ServiceLocations $ServiceLocations */ function getServiceLocations($GetServiceLocations) { $db = GetDatabase(); $query = "SET NOCOUNT ON; SELECT servicename, url FROM service"; $result = $db->ExecuteQuery($query); if ($result) { $rowNum = 0; $ServiceLocations = new ServiceLocations(); while($ServiceName = $db->GetSQLValue($result, $rowNum, 0)) { $config = new ServiceLocation(); $config->ServiceName = $ServiceName; //Get the service name $config->ServiceURL = $db->GetSQLValue($result, $rowNum, 1); //Get the URL $ServiceLocations->ServiceLocation[$rowNum] = $config; $rowNum = $rowNum + 1; } } $db->CloseDatabase(); return $ServiceLocations; } /** Sets connection from client to business service * @namespace http://apache.org/stonehenge/stocktrader * @param object ClientToBS $ClientToBS */ function setConnectionFromClientToBS($ClientToBS) { if($ClientToBS) { /* check whether given business service and client name are valid */ if(isBusinessServiceDefined($ClientToBS->BS)) { if(isClientDefined($ClientToBS->Client)) { /* both client name and business service are valid. we can store it */ $db = GetDatabase(); /* "BEGIN TRAN" initialize a transaction; which privides control so that later we can cancel * the transaction, if something goes wrong. */ if($db->ExecuteQuery("BEGIN TRAN")) { $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 = $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 = $db->ExecuteQuery($query); } if($status) { /* Transaction is successfull, we can safely commit the transaction into the database. */ $db->ExecuteQuery("COMMIT TRAN"); } else { /* Transaction is not successfull, we have to rollback the transaction */ $db->ExecuteQuery("ROLLBACK TRAN"); error_log("Storing service location configuration failed. \n"); } } else { error_log("Cannot initialise a transaction using BEGIN TRAN. \n"); } $db->CloseDatabase(); } else { error_log("Client with name $ClientToBS->Client is not supported by the system. \n"); } } else { error_log("Business service with name $ClientToBS->BS is not supported by the system. \n"); } } } /** Get all connections from client to business service * @namespace http://apache.org/stonehenge/stocktrader * @param object GetClientToBSConnections $GetClientToBSConnections * @return object ClientToBSConnections $ClientToBSConnections */ function getClientToBSConnections($GetClientToBSConnections) { $db = GetDatabase(); $query = "SET NOCOUNT ON; SELECT client, bs FROM clienttobs"; $result = $db->ExecuteQuery($query); if ($result) { $rowNum = 0; $ClientToBSConnections = new ClientToBSConnections(); while($ClientName = $db->GetSQLValue($result, $rowNum, 0)) { $config = new ClientToBS(); $config->Client = $ClientName; //Get the client name $config->BS = $db->GetSQLValue($result, $rowNum, 1); //Get the BS Name $ClientToBSConnections->ClientToBS[$rowNum] = $config; $rowNum = $rowNum + 1; } } $db->CloseDatabase(); return $ClientToBSConnections; } /** Sets connection from business service to order processor service * @namespace http://apache.org/stonehenge/stocktrader * @param object BSToOPS $BSToOPS */ function setConnectionFromBSToOPS($BSToOPS) { if($BSToOPS) { /* check whether given business service and order processor service are valid */ if(isBusinessServiceDefined($BSToOPS->BS)) { if(isOrderProcessorServiceDefined($BSToOPS->OPS) || isOrderProcessorSecDefined($BSToOPS->OPS)) { /* both order processor and business service are valid. we can store it */ $db = GetDatabase(); /* "BEGIN TRAN" initialize a transaction; which privides control so that later we can cancel * the transaction, if something goes wrong. */ if($db->ExecuteQuery("BEGIN TRAN")) { $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 = $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 = $db->ExecuteQuery($query); } if($status) { /* Transaction is successfull, we can safely commit the transaction into the database. */ $db->ExecuteQuery("COMMIT TRAN"); } else { /* Transaction is not successfull, we have to rollback the transaction */ $db->ExecuteQuery("ROLLBACK TRAN"); error_log("Storing service location configuration failed. \n"); } } else { error_log("Cannot initialise a transaction using BEGIN TRAN. \n"); } $db->CloseDatabase(); } else { error_log("Order processor with name $BSToOPS->OPS is not supported by the system. \n"); } } else { error_log("Business service with name $BSToOPS->BS is not supported by the system. \n"); } } } /** Get all connections from business service to order processor service * @namespace http://apache.org/stonehenge/stocktrader * @param object GetBSToOPSConnections $GetBSToOPSConnections * @return object BSToOPSConnections $BSToOPSConnections */ function getBSToOPSConnections($GetBSToOPSConnections) { $db = GetDatabase(); $query = "SET NOCOUNT ON; SELECT bs, ops FROM bstoops"; $result = $db->ExecuteQuery($query); if ($result) { $rowNum = 0; $BSToOPSConnections = new BSToOPSConnections(); while($BSName = $db->GetSQLValue($result, $rowNum, 0)) { $config = new BSToOPS(); $config->BS = $BSName; //Get the BS name $config->OPS = $db->GetSQLValue($result, $rowNum, 1); //Get the OPS Name $BSToOPSConnections->BSToOPS[$rowNum] = $config; $rowNum = $rowNum + 1; } } $db->CloseDatabase(); return $BSToOPSConnections; } /** Get configurations of a client * @namespace http://apache.org/stonehenge/stocktrader * @param object ClientConfigRequest $ClientConfigRequest * @return object ClientConfigResponse $ClientConfigResponse End point url of business service */ function getClientConfig($ClientConfigRequest) { if($ClientConfigRequest) { $db = GetDatabase(); $ClientToBS = getClientToBS($ClientConfigRequest->Client, $db); if($ClientToBS) { $serviceLocation = getServiceLocation($ClientToBS->BS, $db); if($serviceLocation) { $config = new ClientConfigResponse(); $config->BS = $serviceLocation->ServiceURL; } else { error_log("Cannot find service location for business service $ClientToBS->BS \n"); } } else { error_log("Cannot find details about business service connected to clinet ". "[$ClientConfigRequest->Client]. \n"); } $db->CloseDatabase(); } return $config; } /** Get configurations of a business service * @namespace http://apache.org/stonehenge/stocktrader * @param object BSConfigRequest $BSConfigRequest Name of the business service * @return object BSConfigResponse $BSConfigResponse */ function getBSConfig($BSConfigRequest) { if($BSConfigRequest) { $db = GetDatabase(); $BSToOPS = getBSToOPS($BSConfigRequest->BS, $db); if($BSToOPS) { $serviceLocation = getServiceLocation($BSToOPS->OPS, $db); if($serviceLocation) { /* found the end point url of order processor service. Now check for active database settings */ $DBConfig = getActiveDBConfig($db); if($DBConfig) { $config = new BSConfigResponse(); $config->DBName = $DBConfig->DBName; $config->DBHostName = $DBConfig->DBHostName; $config->DBPort = $DBConfig->DBPort; $config->OPS = $serviceLocation->ServiceURL; if(isOrderProcessorSecDefined($BSToOPS->OPS)) { $config->Sec = true; } else { $config->Sec = false; } } else { error_log("Cannot find details about active database \n"); } } else { error_log("Cannot find service location for order processor service $BSToOPS->OPS \n"); } } else { error_log("Cannot find details about order processor service connected to business service ". " [$BSConfigRequest->BS]. \n"); } $db->CloseDatabase(); } return $config; } /** Get configurations of a order processor service * @namespace http://apache.org/stonehenge/stocktrader * @param object OPSConfigRequest $OPSConfigRequest * @return object OPSConfigResponse $OPSConfigResponse */ function getOPSConfig($OPS) { $db = GetDatabase(); $DBConfig = getActiveDBConfig($db); if($DBConfig) { $config = new OPSConfigResponse(); $config->DBName = $DBConfig->DBName; $config->DBHostName = $DBConfig->DBHostName; $config->DBPort = $DBConfig->DBPort; } else { error_log("Cannot find details about active database \n"); } $db->CloseDatabase(); return $config; } $operations = array( "DBConfig"=>"storeDBConfig", "GetDBConfigs" => "getDBConfigs", "ActiveDB" => "setActiveDB", "GetActiveDB" => "getActiveDB", "ServiceLocation" => "setServiceLocation", "GetServiceLocations" => "getServiceLocations", "ClientToBS" => "setConnectionFromClientToBS", "GetClientToBSConnections" => "getClientToBSConnections", "BSToOPS" => "setConnectionFromBSToOPS", "GetBSToOPSConnections" => "getBSToOPSConnections", "ClientConfigRequest" => "getClientConfig", "BSConfigRequest" => "getBSConfig", "OPSConfigRequest" => "getOPSConfig" ); $opParams = array( "storeDBConfig"=>"MIXED", "getDBConfigs" => "MIXED", "setActiveDB" => "MIXED", "getActiveDB" => "MIXED", "setServiceLocation" => "MIXED", "getServiceLocations" => "MIXED", "setConnectionFromClientToBS" => "MIXED", "getClientToBSConnections" => "MIXED", "setConnectionFromBSToOPS" => "MIXED", "getBSToOPSConnections" => "MIXED", "getClientConfig" => "MIXED", "getBSConfig" => "MIXED", "getOPSConfig" => "MIXED" ); $classmap = array( "DBConfig" => "DBConfig", "GetDBConfigs" => "GetDBConfigs", "DBConfigs" => "DBConfigs", "ActiveDB" => "ActiveDB", "GetActiveDB" => "GetActiveDB", "ServiceLocation" => "ServiceLocation", "GetServiceLocations" => "GetServiceLocations", "ServiceLocations" => "ServiceLocations", "ClientToBS" => "ClientToBS", "GetClientToBSConnections" => "GetClientToBSConnections", "BSToOPS" => "BSToOPS", "GetBSToOPSConnections" => "GetBSToOPSConnections", "ClientConfigRequest" => "ClientConfigRequest", "ClientConfigResponse" => "ClientConfigResponse", "BSConfigRequest" => "BSConfigRequest", "BSConfigResponse" => "BSConfigResponse", "OPSConfigRequest" => "OPSConfigRequest", "OPSConfigResponse" => "OPSConfigResponse"); $svr = new WSService(array( "operations"=>$operations, "bindingStyle"=>"doclit", "opParams" => $opParams, "serviceName" => "config_svc", "wsdl" => "../resources/wsdl/config_svc.wsdl", "classmap" => $classmap)); $svr->reply(); ?>