DDMS
[ class tree: DDMS ] [ index: DDMS ] [ all elements ]

Source for file externalDataServerConnection.php

Documentation is available at externalDataServerConnection.php

  1. <?php
  2. /**
  3.  * <b>Class Description</b>: The overarching class in the Distributed Data Management Client package
  4.  * (see {@link package.php} for documentation
  5.  * of the DDMS package.).  This  is the only class in the system that is directly used by the business application that uses the DDMS.
  6.  * During its construction the DDMS client's configuration settings are loaded into the class variables.  The configuration settings
  7.  * are stored the DDMSs database tables (???) and its config file (??????.ini).
  8.  *@see package.php
  9.  * @since : 29/04/2009
  10.  * @author Jan van der Breggen
  11.  * @package DDMS
  12.  * @subpackage DDMSClient
  13.  ***/
  14.  
  15. class ExternalDataServerConnection extends DB
  16. {
  17.  
  18.     private $urlConnection;
  19.     private $localDataObjects = array();
  20.  
  21.  
  22.     function __construct()
  23.     {
  24.         //DB::__construct();
  25.         $x new db('rigregversiontwo');
  26.         $this->urlConnection = new PhpUrlConnection('http://localhost/remoteDbase/index.php/dataInterface');
  27.         $x->query ('select table_name, primary_key, remote_key, local_refresh from linked_tables order by table_name desc');
  28.  
  29.         foreach ($x->rows_array(AS $row{
  30.             $table $row['table_name'];
  31.             $sql "select `column`, referenced_table, referenced_column, lt.remote_key as 'remote_referenced_column',cascading_update, cascading_insert, cascading_delete from `references`, linked_tables lt where referenced_table = lt.table_name and `table` = '$table'";
  32.             $y new db('rigregversiontwo');
  33.             $y->query($sql);
  34.  
  35.             $references $y->rows_array();
  36.             $y->close();
  37.             $this->localDataObjects[$row['table_name']]new ExternallyLinkedOrm($row$references$this);
  38.         }
  39.  
  40.         $this->localDataObjects = $this->_orderDataObjects($this->localDataObjects);
  41.  
  42.     }
  43.  
  44.     function refreshLocalData()
  45.     {
  46.         $startTime gettimeofday();
  47.         foreach($this->localDataObjects as $table)
  48.         {
  49.  
  50.             //$table->refreshLocalData('allRecords');
  51.             $table->refreshLocalData();
  52.         }
  53.         $endTime gettimeofday();
  54.         return $endTime['sec'$startTime['sec'];
  55.     }
  56.  
  57.      function getUrlConnection()
  58.     {
  59.         return $this->urlConnection;
  60.     }
  61.  
  62.   function getObject($objectName)
  63.     {
  64.         return $this->localDataObjects[$objectName];
  65.     }
  66.  
  67.     /**
  68.      * sorts the localDataObjects array to reflect referential integrity.
  69.      * When data is loaded into linked tables, either at system setup time, or during
  70.      * refresh data event, records with references to local key values of other tables
  71.      * should be loaded after the records they refer to was loaded and local key values
  72.      * what will be the foreign keys were generated
  73.      * pre: none
  74.      * post: the localDataObjects array will be sorted in such a way that for each table Y
  75.      * with references to local_key values in table X, table X will be located at a lower
  76.      * array index than table Y.  Tables that are 'select only' will be put at the beginning
  77.      * of the array (even if these tables have references to linked tables with local_key
  78.      * values, they will always have the remote_key value as their foreign key)
  79.      */
  80.     private function _orderDataObjects($dataObjects)
  81.     {
  82.         //working array
  83.         $temp array();
  84.         foreach ($dataObjects as $object)
  85.         {
  86.             if (!array_key_exists($object->getTableName()$temp)){
  87.                 if ($object->hasReferences()){
  88.                     $results $this->_orderDataObjects ($object->getReferencedObjects());
  89.                     foreach ($results as $result){
  90.                         if (!array_key_exists($result->getTableName()$temp)){
  91.                             $temp[$result->getTableName()]=$result ;
  92.                         }
  93.                     }
  94.                 }
  95.  
  96.                 if (!array_key_exists($object->getTableName()$temp)){
  97.                     $temp[$object->getTableName()]$object;
  98.                 }
  99.             }
  100.         }
  101.         return $temp;
  102.     }
  103.  
  104.     /**
  105.      * @method getObjects 
  106.      *  Description: returns a subset of the localDataObjects array
  107.      * @param array of type string $objectNames, table_name values
  108.      * @return array of type ExternallyLinkedOrm
  109.      */
  110.     function getObjects($objectNames)
  111.     {
  112.         $objects array();
  113.         foreach ($objectNames as $name)
  114.         {
  115.             array_push($objects$this->localDataObjects[$name]);
  116.         }
  117.         return $objects;
  118.     }
  119.  
  120.     function getReferringObjects($referredTableName)
  121.     {
  122.         $objects array();
  123.         foreach ($this->localDataObjects as $object)
  124.         {
  125.             if ($object->hasForeignKeyReferenceTo($referredTableName))
  126.             {
  127.                 $objects[]=$object;
  128.             }
  129.         }
  130.         return $objects;
  131.     }
  132.  
  133.  
  134.  
  135.  
  136. }
  137.  
  138.  
  139.  
  140. ?>

Documentation generated on Mon, 18 May 2009 11:21:49 +0200 by phpDocumentor 1.4.1