/[cvs]/nfo/php/libs/com.newsblob.phphtmllib/widgets/data_source/ProxyDataSource.inc
ViewVC logotype

Diff of /nfo/php/libs/com.newsblob.phphtmllib/widgets/data_source/ProxyDataSource.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by joko, Sat Mar 1 03:10:40 2003 UTC revision 1.3 by joko, Sat Mar 1 15:36:11 2003 UTC
# Line 1  Line 1 
1  <?php  <?php
   
2  /**  /**
3   * This file contains the ProxyDataSource child class   * This file contains the ProxyDataSource child class
4   * that uses the Data::Driver::Proxy object to talk to a remote rpc server.   * that uses the Data::Driver::Proxy object to talk
5   *   * to a remote rpc server.
  * Data::Driver::Proxy uses a PEAR XML::RPC object to actually  
  * talk HTTP and serialize data chunks to and from XML,  
  * but adds some caching to this "process of fetching data from a remote side".  
  * It "proxies" arbitrary data chunks a) inside a native php4 session,  
  * b) by talking to a rdbms (single proxy-table) or c) [TODO] using PEAR::Cache.  
6   *   *
7   * @author Andreas Motl <andreas.motl@ilo.de>   * @author Andreas Motl <andreas.motl@ilo.de>
  * @author Sebastian Utz <seut@tunemedia.de>  
8   * @package phpHtmlLib   * @package phpHtmlLib
9     * @module ProxyDataSource
10     *
11   */   */
12    
13  /**  /**
14   * $Id$   * $Id$
15   *   *
16   * $Log$   * $Log$
17     * Revision 1.3  2003/03/01 15:36:11  joko
18     * + debugging
19     * + renamed some methods regarding new proposal (build_proxy_options, fetch_result, etc.)
20     *
21     * Revision 1.2  2003/03/01 04:50:27  joko
22     * encapsulated all output into tracing mode
23     * disabled tracing
24     *
25   * Revision 1.1  2003/03/01 03:10:40  joko   * Revision 1.1  2003/03/01 03:10:40  joko
26   * + initial commit   * + initial commit
27   *   *
# Line 29  Line 32 
32   * This requires the MemoryDataSource base class   * This requires the MemoryDataSource base class
33   *   *
34   */   */
35  include_once($phphtmllib."/widgets/data_source/MemoryDataSource.inc");    // V1: compile-time-include, stable since years  ;-)
36      include_once($phphtmllib."/widgets/data_source/MemoryDataSource.inc");
37      // V2: runtime-load proposal, more flexible
38      // loadModule('MemoryDataSource', 'inc');   // doesn't work (would do if basepath of module is in libpath)
39      // loadModule($phphtmllib . '::widgets::data_source::MemoryDataSource', 'inc');   // works  (by accident)
40      // loadModule($phphtmllib . "/widgets/data_source/MemoryDataSource", "inc");   // works  (should be stable)
41      // loadModule($phphtmllib . "/widgets/data_source/MemoryDataSource.inc", null);   // works  (should be stable)
42      
43    
44    
45  /**  /**
46   * Have to have PEAR and DB included   * Have to have PEAR and DB included
47   * the pear dir must be in the   * the pear dir must be in the
48   * include path.   * include path.
49   */   */
50  //require_once("PEAR.php");   // FIXME: what about PEAR::XML::RPC?    // require_once("PEAR.php");   // FIXME: what about PEAR::XML::RPC?
51  //require_once("DB.php");    // require_once("DB.php");
52    
53  /**  /**
54   * This ProxyDataSource child class is *completely* independent   * This ProxyDataSource child class is *completely* independent
# Line 53  include_once($phphtmllib."/widgets/data_ Line 64  include_once($phphtmllib."/widgets/data_
64   *   *
65   * But the point is: Caching! The actual *data* isn't read redundant!   * But the point is: Caching! The actual *data* isn't read redundant!
66   *   *
67     *
68     * !!!!!!  refactor this to Data::Driver::Proxy  !!!!!!     <-----------------
69     *
70   * Data::Driver::Proxy instantiates "handlers" below itself   * Data::Driver::Proxy instantiates "handlers" below itself
71   * which act as encapsulated workers to actually do the stuff to do.   * which act as encapsulated workers to actually do the stuff to do.
72   * It can cache data for "disconnected mode" using the   * It can cache data for "disconnected mode" using the
# Line 60  include_once($phphtmllib."/widgets/data_ Line 74  include_once($phphtmllib."/widgets/data_
74   * One worker already implemented is Data::Driver::RPC::Remote, which   * One worker already implemented is Data::Driver::RPC::Remote, which
75   * talks to a RPC::XML server (todo: talk SOAP!) using PEAR::XML::RPC.   * talks to a RPC::XML server (todo: talk SOAP!) using PEAR::XML::RPC.
76   *   *
77     * ---  refactored here, but: redundant somehow  ---
78     * Data::Driver::Proxy uses a PEAR XML::RPC object to actually
79     * talk HTTP and serialize data chunks to and from XML,
80     * but adds some caching to this "process of fetching data from a remote side".
81     * It "proxies" arbitrary data chunks a) inside a native php4 session,
82     * b) by talking to a rdbms (single proxy-table) or c) [TODO] using PEAR::Cache.
83     * ---  refactored here, but: redundant somehow  ---
84     *
85     * !!!!!!  refactor this to Data::Driver::Proxy  !!!!!!     <-----------------
86     *
87     *
88   * How to use?   * How to use?
89   *   *
90   * Pass an array holding "locator metadata" to the constructor.   * Pass an array holding "locator metadata" to the constructor.
# Line 85  include_once($phphtmllib."/widgets/data_ Line 110  include_once($phphtmllib."/widgets/data_
110   *   *
111   * @author Andreas Motl <andreas.motl@ilo.de>   * @author Andreas Motl <andreas.motl@ilo.de>
112   * @author Sebastian Utz <seut@tunemedia.de>   * @author Sebastian Utz <seut@tunemedia.de>
113     * @copyright (c) 2003 - All Rights reserved.
114     * @license GNU LGPL (GNU Lesser General Public License)
115     *
116     * @author-url http://www.netfrag.org/~joko/
117     * @author-url http://www.netfrag.org/~jonen/
118     * @license-url http://www.gnu.org/licenses/lgpl.txt
119     *
120   * @package phpHtmlLib   * @package phpHtmlLib
121     * @module ProxyDataSource
122     *
123   */   */
124    
125  /**  /**
# Line 96  include_once($phphtmllib."/widgets/data_ Line 130  include_once($phphtmllib."/widgets/data_
130   *   *
131   */   */
132    
133    
134  class ProxyDataSource extends MemoryDataSource {  class ProxyDataSource extends MemoryDataSource {
135    
136          /**          /**
137           * This var holds the locator metadata hash           * This var holds the locator metadata hash
138           * that is used to feed metadata to a per-query-instance           * that is used to feed metadata to a per-query-instance
139           * of a Data::Driver::Proxy object.           * of a Data::Driver::Proxy object.
140             *
141           */           */
142          var $_locator = NULL;          var $_locator = NULL;
143    
144    
145          /**          /**
146           * This var holds the query hash           * This var holds the query hash
147           * that is used to feed as query to a per-query-instance           * that is used to feed as query to a per-query-instance
148           * of a Data::Driver::Proxy object.           * of a Data::Driver::Proxy object.
149             *
150           */           */
151          var $_query = NULL;          var $_query = NULL;
152    
# Line 121  class ProxyDataSource extends MemoryData Line 159  class ProxyDataSource extends MemoryData
159           * queryData() - execute a query against a data storage           * queryData() - execute a query against a data storage
160           * querySchema() - execute a query against underlying storage metadata           * querySchema() - execute a query against underlying storage metadata
161           * sendCommand() - send a command against an arbitrary execution engine           * sendCommand() - send a command against an arbitrary execution engine
162             *
163           */           */
164          var $_proxy = NULL;          var $_proxy = NULL;
165    
166    
167            /**
168             * This var holds options fed to the Proxy object
169             * These are built from locator metadata (_locator) and query arguments (_query)
170             * It's a simple structured hash:
171             *  $proxy_options = array(
172             *    method => '<remote-method-name>',
173             *    args => array('list', 'of', 'arguments')
174             *  );
175             *
176             */
177            var $_proxy_options = NULL;
178    
179    
180          /**          /**
181           * this holds the query result from the           * this holds the query result from the
182           * Data::Driver::Proxy->queryXyz() call           * Data::Driver::Proxy->queryXyz() call
# Line 131  class ProxyDataSource extends MemoryData Line 184  class ProxyDataSource extends MemoryData
184           */           */
185          var $_result = NULL;          var $_result = NULL;
186    
187            /**
188             * This holds some information about the tracing level.
189             *
190             */
191            var $_debug = array(
192              notice => 0,
193              trace => 0,
194              payload => 0,
195            );
196    
197    
198          /**          /**
199           * The constructor is used to pass in the           * The constructor is used to pass in the
# Line 140  class ProxyDataSource extends MemoryData Line 203  class ProxyDataSource extends MemoryData
203           * @param Query array - layout: array( type => '', metadata => '', dsn => '' )           * @param Query array - layout: array( type => '', metadata => '', dsn => '' )
204           */           */
205          function ProxyDataSource( &$locator, $query ) {          function ProxyDataSource( &$locator, $query ) {
206                    
207                  $this->set_locator( $locator );                  $this->set_locator( $locator );
208                  $this->set_query( $query );                  $this->set_query( $query );
209          }          }
# Line 188  class ProxyDataSource extends MemoryData Line 252  class ProxyDataSource extends MemoryData
252       * @param string - $proxy_name (namespaced classname - perl syntax - e.g.: Data::Driver::Proxy)       * @param string - $proxy_name (namespaced classname - perl syntax - e.g.: Data::Driver::Proxy)
253       *       *
254       */       */
255      function call_proxy_method() {      function do_proxy_call() {
256    
257    
258        // 1. read args        // 1. read args
# Line 235  class ProxyDataSource extends MemoryData Line 299  class ProxyDataSource extends MemoryData
299                  }                  }
300          }          }
301    
302          function call_proxy() {          function build_proxy_options() {
303          
304        // make up a command from metadata        // make up a command from metadata
305        // FIXME: abstract this some more (e.g. via a CommandMapper|Registry)        // FIXME: abstract this some more (e.g. via a CommandMapper|Registry)
306          switch ($this->_query[metatype]) {          switch ($this->_query[metatype]) {
# Line 260  class ProxyDataSource extends MemoryData Line 324  class ProxyDataSource extends MemoryData
324          }          }
325                
326        // trace        // trace
327        if ($this->trace) {          $this->debug(null, '<b>= = = = = = = = = = = = = = = = = = = = = =</b>');
328          print "ProxyDataSource->do_query()<br/>";          $this->trace('build_proxy_options', array(
329          print "_locator = " . Dumper($this->_locator);            "_locator" => $this->_locator,
330          print "_query = " . Dumper($this->_query);            "_query" => $this->_query,
331          print "<b>\$command = " . $command . "</b><br/>";            "command" => '<b>' . $command . "</b>",
332          print "<b>\$args = " . Dumper($args) . "</b><br/>";            "args" => $args
333        }          ));
334    
335        $this->_proxy_options = array(
336          method => $command,
337          args => $args,
338        );
339          
340      }
341    
342            function fetch_result() {
343          
344          $this->build_proxy_options();
345          $method = $this->_proxy_options[method];
346          $args = $this->_proxy_options[args];
347                
348        // pre-flight checks        // pre-flight checks
349          if (!$command) {          if (!$method) {
350            $msg = "Remote command could not be resolved, please pass in or check configuration.";            $msg = "Remote command could not be resolved, please pass in or check configuration.";
351                          user_error("ProxyDataSource::do_query() - failed: " . $msg);                          user_error("ProxyDataSource::do_query() - failed: " . $msg);
352            return;            return;
353          }          }
354          
355        // do remote call here and get result        // do remote call here and get result
356        // FIXME: handle synchronous/asynchronous mode here!!!        // FIXME: handle synchronous/asynchronous mode here!!!
357          $this->call_proxy_method($command, $args);          $this->do_proxy_call($method, $args);
358          // TODO: ... = $this->poll_proxy_result  and  $this->get_proxy_result          // TODO: ... = $this->poll_proxy_result  and  $this->get_proxy_result
359          $this->_result = $this->_proxy->getAttributes();          $this->_result = $this->_proxy->getAttributes();
360    
361        // trace        // trace
362          //print "_result = " . Dumper($this->_result);          if ($this->_debug[notice]) {
363          print "_result - count = " . sizeof($this->_result) . "<br/>";            //print "_result = " . Dumper($this->_result);
364              print "_result - count = " . sizeof($this->_result) . "<br/>";
365        // pass data to MemoryDataSource          }
366    
367          // V1 - doesn't work!          }
         //$this->_data_list = $this->_result;  
368    
         // V2 - ???  
         //$this->MemoryDataSource();  
   
         // V3 - copy & paste  
         /*  
                 foreach ($this->_result as $value) {  
                   print Dumper($value);  
                         if ($this->add_data_row($value)) {  
                                 $count++;  
                         }  
                 }  
                 $this->set_total_rows( $count );  
                 $this->sort();  
                 */  
369    
370          }    function do_query() {
371        //print "query!<br/>";
372        $this->fetch_result();
373        $this->handle_result();
374      }
375            
376      function get_header() {
377        $this->fetch_result();
378        $this->read_labels_from_result();
379        return $this->get_labels();
380      }
381    
382    
       
383      function O_do_prequery() {      function O_do_prequery() {
384                  //print "prequery!<br/>";                  //print "prequery!<br/>";
385                  // HACK!!!                  // HACK!!!
386        // modify behaviour here: for now it is needed to call for the schem        // modify behaviour here: for now it is needed to call for the schem
387        // eventually modify here to get schema from some registry component (already locally available)        // eventually modify here to get schema from some registry component (already locally available)
388        $this->call_proxy();        $this->fetch_result();
389        //print Dumper($this->_result);        //print Dumper($this->_result);
390        //print Dumper($this->_result[0]);        //print Dumper($this->_result[0]);
391        //exit;        //exit;
# Line 322  class ProxyDataSource extends MemoryData Line 393  class ProxyDataSource extends MemoryData
393        //$this->_get_header();        //$this->_get_header();
394      }      }
395    
396      function do_query() {  
397                  //print "query!<br/>";          function O_get_header() {
            $this->handle_result();  
     }        
           
         function _get_header() {  
398                    //$this->do_prequery();                    //$this->do_prequery();
399                    // FIXME: prevent multi-calls by base class                    // FIXME: prevent multi-calls by base class
400           $this->call_proxy();           $this->fetch_result();
401                    foreach($this->_result[0] as $key => $value) {                    foreach($this->_result[0] as $key => $value) {
402                                  array_push($this->_data_keys, $key);                                  array_push($this->_data_keys, $key);
403                          }                                      }            
# Line 343  class ProxyDataSource extends MemoryData Line 410  class ProxyDataSource extends MemoryData
410          }          }
411    
412    
413    
414    
415    
416    
417    
418    
419    
420    
421          /**          /**
422           * This function gets the next data row           * This function gets the next data row
423           * from the query()           * from the query()

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.3

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed