/[cvs]/nfo/php/libs/org.netfrag.glib/DataSource/Generic.php
ViewVC logotype

Diff of /nfo/php/libs/org.netfrag.glib/DataSource/Generic.php

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

revision 1.1 by joko, Wed Mar 5 12:04:00 2003 UTC revision 1.12 by joko, Sat Mar 29 08:00:48 2003 UTC
# Line 1  Line 1 
1  <?php  <?php
2  /**  /**
3   * This file contains the GenericDataSource child class   * This file contains the GenericDataSource child class
  * that may use arbitrary code modules as database handlers.  
  * It's aims are to get together:  
  *   o phpHtmlLibs "source-handlers"  
  *   o PEAR's database handlers  
  *   o custom ones (e.g. Data::Driver::Proxy object, which talks to a remote rpc server)  
4   *   *
5   * @author Andreas Motl <andreas.motl@ilo.de>   * @author Andreas Motl <andreas.motl@ilo.de>
6   * @package phpHtmlLib   * @package org.netfrag.glib
7   * @module GenericDataSource   * @name DataSource::Generic
8   *   *
9   */   */
10    
11  /**  /**
12     * <b>Cvs-Log:</b>
13     *
14     * <pre>
15   * $Id$   * $Id$
16   *   *
17   * $Log$   * $Log$
18     * Revision 1.12  2003/03/29 08:00:48  joko
19     * modified ErrorBoxing
20     *
21     * Revision 1.11  2003/03/28 06:45:26  joko
22     * VERBOSE mode
23     *
24     * Revision 1.10  2003/03/28 03:01:02  joko
25     * more fancy debugging-output
26     *
27     * Revision 1.9  2003/03/27 16:24:26  jonen
28     * + mugled namespace
29     * + added enhanced 'queryData'
30     *
31     * Revision 1.8  2003/03/20 07:22:14  jonen
32     * + modified case 'object' to 'objects'
33     *   (cause its loads all *objects* of a given classname)
34     *
35     * Revision 1.7  2003/03/11 01:43:00  joko
36     * + fixed metadata for phpDocumentor
37     *
38     * Revision 1.6  2003/03/11 01:22:25  joko
39     * + fixed metadata for phpDocumentor
40     *
41     * Revision 1.5  2003/03/11 00:12:49  joko
42     * + fixed metadata for phpDocumentor
43     *
44     * Revision 1.4  2003/03/10 23:25:03  joko
45     * + fixed metadata for phpDocumentor
46     *
47     * Revision 1.3  2003/03/09 15:50:36  joko
48     * + additional metadata for Autodia
49     *
50     * Revision 1.2  2003/03/05 17:28:43  joko
51     * updated docu (phpDocumentor testing....)
52     *
53   * Revision 1.1  2003/03/05 12:04:00  joko   * Revision 1.1  2003/03/05 12:04:00  joko
54   * + initial commit, from GenericDataSource   * + initial commit, from GenericDataSource
55   *   *
# Line 43  Line 76 
76   *   *
77   * Revision 1.1  2003/03/01 03:10:40  joko   * Revision 1.1  2003/03/01 03:10:40  joko
78   * + initial commit   * + initial commit
79   *   * </pre>
80   *   *
81   */   */
82    
# Line 71  Line 104 
104    // require_once("PEAR.php");   // FIXME: what about PEAR::XML::RPC?    // require_once("PEAR.php");   // FIXME: what about PEAR::XML::RPC?
105    // require_once("DB.php");    // require_once("DB.php");
106    
107    
108    loadModule('DesignPattern::Proxy');
109    loadModule('DesignPattern::TransparentProxy');
110    loadModule('DesignPattern::RemoteProxy');
111    
112    //class GenericDataSource extends MemoryDataSource {
113    //class GenericDataSource extends DesignPattern_Proxy {
114    //class GenericDataSource extends DesignPattern_RemoteProxy {
115    //class GenericDataSource extends DesignPattern_TransparentProxy {
116    
117    //class GenericDataSource extends MemoryDataSource {
118    //loadModule("DataSource::Proxy::Memory");
119    //class GenericDataSource extends DataSource_Proxy_Memory {
120    //class DataSource_GenericDataSource extends DataSource_Proxy_Memory {
121    //class DataSource_GenericDataSource extends DesignPattern_Proxy {
122    //class DataSource_GenericDataSource extends DataSource_Proxy_Memory {
123    
124    // now independent!!! new class-inheritance-tree possible now!
125    // solved by having an Adapter *and* a Proxy here!
126    //class GenericDataSource {
127    
128    loadModule('DesignPattern::AdapterProxy');
129    
130    
131    
132  /**  /**
133   * This GenericDataSource child class is *completely* independent   * This GenericDataSource child class is *completely* independent
134   * of a specific storage implementation and intended to be a wrapper   * of a specific storage implementation and intended to be a wrapper
135   * class on the way from phpHtmlLib to Xyz.   * class on the way from phpHtmlLib to Xyz. <br>
136   *    ("Yyz" gets represented by Data::Storage by now.....)   *    ("Yyz" gets represented by Data::Storage by now.....)
137   *   *
138   * GenericDataSource interacts with an intermediate "proxy" object   * GenericDataSource interacts with an intermediate "proxy" object
139   * (e.g. Data::Driver::Proxy) when doing queries.   * (e.g. Data::Driver::Proxy) when doing queries. <br>
140     * <pre>
141   *    Don't mix this up with a persistent database handle which gets   *    Don't mix this up with a persistent database handle which gets
142   *    reused each and every time for different queries.   *    reused each and every time for different queries.
143   *    Here *is* a new instance of Data::Driver::Proxy for *each* query.   *    Here *is* a new instance of Data::Driver::Proxy for *each* query.
144     * </pre>
145   *   *
146   * But the point is: Caching! The actual *data* isn't read redundant!   * But the point is: Caching! The actual *data* isn't read redundant!
147   *   *
148     * <pre>
149     * --- snipped into here from above ---
150     * that may use arbitrary code modules as database handlers.
151     * It's aims are to get together:
152     *   o phpHtmlLibs "source-handlers"
153     *   o PEAR's database handlers
154     *   o custom ones (e.g. Data::Driver::Proxy object, which talks to a remote rpc server)
155     * --- snipped into here from above ---
156     * </pre>
157   *   *
158     * <p>
159   * !!!!!!  refactor this to Data::Driver::Proxy  !!!!!!     <-----------------   * !!!!!!  refactor this to Data::Driver::Proxy  !!!!!!     <-----------------
160   *   *
161   * Data::Driver::Proxy instantiates "handlers" below itself   * Data::Driver::Proxy instantiates "handlers" below itself
# Line 95  Line 165 
165   * One worker already implemented is Data::Driver::RPC::Remote, which   * One worker already implemented is Data::Driver::RPC::Remote, which
166   * 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.
167   *   *
168     * <pre>
169   * ---  refactored here, but: redundant somehow  ---   * ---  refactored here, but: redundant somehow  ---
170   * Data::Driver::Proxy uses a PEAR XML::RPC object to actually   * Data::Driver::Proxy uses a PEAR XML::RPC object to actually
171   * talk HTTP and serialize data chunks to and from XML,   * talk HTTP and serialize data chunks to and from XML,
# Line 102  Line 173 
173   * It "proxies" arbitrary data chunks a) inside a native php4 session,   * It "proxies" arbitrary data chunks a) inside a native php4 session,
174   * b) by talking to a rdbms (single proxy-table) or c) [TODO] using PEAR::Cache.   * b) by talking to a rdbms (single proxy-table) or c) [TODO] using PEAR::Cache.
175   * ---  refactored here, but: redundant somehow  ---   * ---  refactored here, but: redundant somehow  ---
176     * </pre>
177   *   *
178   * !!!!!!  refactor this to Data::Driver::Proxy  !!!!!!     <-----------------   * !!!!!!  refactor this to Data::Driver::Proxy  !!!!!!     <-----------------
179     * </p>
180   *   *
181   *   *
182   * How to use?   * <p>
183     * <b>How to use?</b>
184   *   *
185   * Pass an array holding "locator metadata" to the constructor.   * Pass an array holding "locator metadata" to the constructor.
186   * GenericDataSource takes care of the rest.   * GenericDataSource takes care of the rest.
187   *   *
188     * <pre>
189   * Pass an array to the constructor: (e.g.)   * Pass an array to the constructor: (e.g.)
190   *   *
191   *  1. doing rpc-calls....   *  1. doing rpc-calls....
192     *    <code>
193   *    $locator = array(   *    $locator = array(
194   *      type => 'rpc',   *      type => 'rpc',
195   *      metadata => array( Host => 'localhost', Port => '8765' ),   *      metadata => array( Host => 'localhost', Port => '8765' ),
196   *    );   *    );
197   *    $source = new GenericDataSource($locator);   *    $source = ne w GenericDataSource($locator);
198   *    $this->set_data_source( &$source );   *    $this->set_data_source( &$source );
199     *    </code>
200   *   *
201   *  2. [proposal] common datahandles....   *  2. [proposal] common datahandles....
202     *    <code>
203   *    $locator = array(   *    $locator = array(
204   *      type => 'mysql',   *      type => 'mysql',
205   *      dsn => 'known dsn markup',   *      dsn => 'known dsn markup',
206   *    );   *    );
207   *    $source = new GenericDataSource($locator);   *    $source = ne w GenericDataSource($locator);
208   *    $this->set_data_source( &$source );   *    $this->set_data_source( &$source );
209     *    </code>
210     * </pre>
211     * </p>
212   *   *
213     *
214     * @link http://www.netfrag.org/~joko/
215   * @author Andreas Motl <andreas.motl@ilo.de>   * @author Andreas Motl <andreas.motl@ilo.de>
216     *
217     * @link http://www.netfrag.org/~jonen/
218   * @author Sebastian Utz <seut@tunemedia.de>   * @author Sebastian Utz <seut@tunemedia.de>
219     *
220   * @copyright (c) 2003 - All Rights reserved.   * @copyright (c) 2003 - All Rights reserved.
221     *
222     * @link http://www.gnu.org/licenses/lgpl.txt
223   * @license GNU LGPL (GNU Lesser General Public License)   * @license GNU LGPL (GNU Lesser General Public License)
224   *   *
  * @author-url http://www.netfrag.org/~joko/  
  * @author-url http://www.netfrag.org/~jonen/  
  * @license-url http://www.gnu.org/licenses/lgpl.txt  
225   *   *
226   * @package phpHtmlLib   * @package org.netfrag.glib
227   * @module GenericDataSource   * @subpackage DataSource
228     * @name DataSource::Generic
229     *
230     * @todo this:
231     * o mungle this to be able to be wrapped around phpHtmlLib's own storage-handles
232     * o implement another Data::Driver::Proxy container
233     *
234     * <pre>
235     *              !!!!!!!!          THIS IS THE PROBLEM          !!!!!!!!
236     *    !!!!!!!!   here is it where we have to break inheritance again   !!!!!!!!
237     *
238     *    THE CONFLICT: Beeing in phpHtmlLib *and* DesignPattern::TransparentProxy
239     *    inheritance trees at the same time, which is *not* possible at
240     *    declare-time. We *do* need some runtime-infrastructure to solve this!
241     *
242     *    TODO: move build- and check-locator stuff from ObjectList to this place!!!
243     *
244     *    ABOUT:
245     *      1. otherwhere: WebApp - scope:
246     *          x handles page vs. block vs. widget; dispatches MVC-View
247     *      2. here: DataSource - scope:
248     *          x handles bridge to frameworks (e.g. phpHtmlLib) vs. actual data driver libs (PEAR, etc.))
249     *          o clean implementation using a DesignPattern::AdapterProxy
250     * </pre>
251   *   *
  */  
   
 /**  
  * Todo:  
  *  
  *  o mungle this to be able to be wrapped around phpHtmlLib's own storage-handles  
  *  o implement another Data::Driver::Proxy container  
252   *   *
253   */   */
   
   
 //              !!!!!!!!          THIS IS THE PROBLEM          !!!!!!!!  
 //    !!!!!!!!   here is it where we have to break inheritance again   !!!!!!!!  
 //  
 //    THE CONFLICT: Beeing in phpHtmlLib *and* DesignPattern::TransparentProxy  
 //    inheritance trees at the same time, which is *not* possible at  
 //    declare-time. We *do* need some runtime-infrastructure to solve this!  
 //  
 //    TODO: move build- and check-locator stuff from ObjectList to this place!!!  
 //  
 //    ABOUT:  
 //      1. otherwhere: WebApp - scope:  
 //          x handles page vs. block vs. widget; dispatches MVC-View  
 //      2. here: DataSource - scope:  
 //          x handles bridge to frameworks (e.g. phpHtmlLib) vs. actual data driver libs (PEAR, etc.))  
 //          o clean implementation using a DesignPattern::AdapterProxy  
 //  
   
 loadModule('DesignPattern::Proxy');  
 loadModule('DesignPattern::TransparentProxy');  
 loadModule('DesignPattern::RemoteProxy');  
   
 //class GenericDataSource extends MemoryDataSource {  
 //class GenericDataSource extends DesignPattern_Proxy {  
 //class GenericDataSource extends DesignPattern_RemoteProxy {  
 //class GenericDataSource extends DesignPattern_TransparentProxy {  
   
 //class GenericDataSource extends MemoryDataSource {  
 //loadModule("DataSource::Proxy::Memory");  
 //class GenericDataSource extends DataSource_Proxy_Memory {  
 //class DataSource_GenericDataSource extends DataSource_Proxy_Memory {  
 //class DataSource_GenericDataSource extends DesignPattern_Proxy {  
 //class DataSource_GenericDataSource extends DataSource_Proxy_Memory {  
   
 // now independent!!! new class-inheritance-tree possible now!  
 // solved by having an Adapter *and* a Proxy here!  
 //class GenericDataSource {  
   
 loadModule('DesignPattern::AdapterProxy');  
254  class DataSource_Generic extends DesignPattern_AdapterProxy {  class DataSource_Generic extends DesignPattern_AdapterProxy {
255    
256  //    !!!!!!!!   here is it where we have to break inheritance again   !!!!!!!!  //    !!!!!!!!   here is it where we have to break inheritance again   !!!!!!!!
# Line 305  class DataSource_Generic extends DesignP Line 366  class DataSource_Generic extends DesignP
366                  //$this->_locator->_datasource_type = $query[datasource];                  //$this->_locator->_datasource_type = $query[datasource];
367                  //$locator[_datasource_type] = $query[datasource];                  //$locator[_datasource_type] = $query[datasource];
368                                    
369          /**
370           * <!-- Autodia -->
371           * can do: (this is metadata supplied for Autodia, don't delete!)
372           *  $this->_locator = new DataSource_Locator()
373           *
374           */
375    
376                  // build master locator                  // build master locator
377                  $this->_locator = php::mkComponent('DataSource::Locator', $locator, array( datasource_type => $query[datasource] ) );                  $this->_locator = php::mkComponent('DataSource::Locator', $locator, array( datasource_type => $query[datasource] ) );
378                  //exit;                  //exit;
# Line 351  class DataSource_Generic extends DesignP Line 419  class DataSource_Generic extends DesignP
419  //exit;  //exit;
420    
421    
422        /**
423         * <!-- Autodia -->
424         * can do: (this is metadata supplied for Autodia, don't delete!)
425         *  $proxy = new DesignPattern_RemoteProxy()
426         *
427         */
428    
429    
430      // --- Proxy selector/dispatcher ...      // --- Proxy selector/dispatcher ...
431            
432      switch ($this->_locator->_datasource_type) {      switch ($this->_locator->_datasource_type) {
# Line 399  class DataSource_Generic extends DesignP Line 475  class DataSource_Generic extends DesignP
475            case 'phpHtmlLib':            case 'phpHtmlLib':
476              //$adapter_arguments = $args[title];              //$adapter_arguments = $args[title];
477    
478              $this->set_adapter_module('DataSource::Adapter::phpHtmlLib::DataListSource');              $this->set_adapter_module('DataSource::Adapter::phpHtmlLib::DataSource');
479                            
480              // in order to let the Adapter communicate with the Proxy,              // in order to let the Adapter communicate with the Proxy,
481              // instantiate a wrapper method in a third namespace via              // instantiate a wrapper method in a third namespace via
# Line 446  class DataSource_Generic extends DesignP Line 522  class DataSource_Generic extends DesignP
522        // $this->create_handler();        // $this->create_handler();
523    
524    
525          /**
526           * <!-- Autodia -->
527           * can do: (this is metadata supplied for Autodia, don't delete!)
528           *  $adapter = new DataSource_Adapter_phpHtmlLib_DataListSource()
529           *
530           */
531    
532        // V1:        // V1:
533        //$this->create_adapter($adapter_module, $this->function, $this->arguments);        //$this->create_adapter($adapter_module, $this->function, $this->arguments);
534    
# Line 597  class DataSource_Generic extends DesignP Line 680  class DataSource_Generic extends DesignP
680        // FIXME: abstract this some more (e.g. via a CommandMapper|Registry)        // FIXME: abstract this some more (e.g. via a CommandMapper|Registry)
681          switch ($this->_query[metatype]) {          switch ($this->_query[metatype]) {
682            case 'data':            case 'data':
683              //$command = 'queryData';              $command = 'queryData';
684              $command = 'getObjects';   // FIXME!!!              //$command = 'getObjects';   // FIXME!!!
685              //$this->_locator->set_option('metadata.command', $command);              //$this->_locator->set_option('metadata.command', $command);
686    /*
687              $args = array();              $args = array();
688              switch ($this->_query[vartype]) {              switch ($this->_query[vartype]) {
689                case 'object':                case 'objects':
690                  if (!$this->_query[classname]) {                  if (!$this->_query[classname]) {
691                    $msg = "_query[vartype] == 'object' requires _query[classname]";                    $msg = "_query[vartype] == 'objects' requires _query[classname]";
692                    user_error("GenericDataSource::query_data() - failed: " . $msg);                    user_error("GenericDataSource::query_data() - failed: " . $msg);
693                  }                  }
694                  array_push($args, $this->_query[classname]);                  array_push($args, $this->_query[classname]);
695                  break;                  break;
696              }              }
697              break;   */
698                $query_args = array();
699                 switch ($this->_query[abstract_type]) {
700                  case 'list':
701                    if (!$this->_query[classname]) {
702                      $msg = "_query[vartype] == 'objects' requires _query[classname]";
703                      user_error("GenericDataSource::query_data() - failed: " . $msg);
704                    }
705                    //array_push($query_args, $this->_query[classname]);
706                    $query_args[classname] = $this->_query[classname];
707                    break;
708                  case 'item':
709                    if (!$this->_query[classname]) {
710                      $msg = "_query[vartype] == 'objects' requires _query[classname]";
711                      user_error("GenericDataSource::query_data() - failed: " . $msg);
712                    }
713                    $query_args[guid] = $this->_query[ident];
714                    $query_args[classname] = $this->_query[classname];
715                    break;              
716                }
717                $args = array(
718                              'data_type' => $this->_query[abstract_type],
719                              'query_args' => $query_args
720                              );
721               break;
722    
723              // querySchema
724            case 'schema':            case 'schema':
725                //print "Testing schema:" . "<br>";
726              $command = 'querySchema';              $command = 'querySchema';
727              break;              break;
728          }          }
# Line 648  class DataSource_Generic extends DesignP Line 759  class DataSource_Generic extends DesignP
759                
760    }    }
761    
762    
763    
764          function &fetch_result() {          function &fetch_result() {
765                
766        $this->datasource_handler_buildoptions();        $this->datasource_handler_buildoptions();
767    
768        $method = $this->_locator->_call[_method];        $call = $this->_locator->get_call();
769        $args = $this->_locator->_call[_arguments];        //print Dumper($call);
770          
771        // pre-flight checks        // pre-flight checks
772          if (!$method) {          if (!$call[method]) {
773            $msg = "Remote command could not be resolved, please pass in or check configuration.";            $msg = "Remote method is empty, please pass in proper metadata or check configuration.";
774                          user_error("GenericDataSource::query_data() - failed: " . $msg);                          user_error("GenericDataSource::query_data() - failed: " . $msg);
775            return;            return;
776          }          }
# Line 666  class DataSource_Generic extends DesignP Line 779  class DataSource_Generic extends DesignP
779    
780        // do remote call here and get result        // do remote call here and get result
781        // FIXME: handle synchronous/asynchronous mode here!!!        // FIXME: handle synchronous/asynchronous mode here!!!
782          $this->datasource_handler_call($method, $args);          $this->datasource_handler_call($call[method], $call[args]);
783                    
784                    
785          // TODO: ... = $this->poll_handler_result  and  $this->get_handler_result          // TODO: ... = $this->poll_handler_result  and  $this->get_handler_result
# Line 677  class DataSource_Generic extends DesignP Line 790  class DataSource_Generic extends DesignP
790          $this->_result_count = sizeof($this->_result);          $this->_result_count = sizeof($this->_result);
791    
792        // trace        // trace
793          if ($this->_debug[notice]) {          //if (constants::get('VERBOSE') && $this->_debug[notice]) {
794            if (constants::get('VERBOSE') or constants::get('ERRORS_ONLY')) {
795            //print "_result = " . Dumper($this->_result);            //print "_result = " . Dumper($this->_result);
796            print "DataSource::Generic->_result_count = " . $this->_result_count . "<br/>";            //print "<div><b><font color=\"darkgreen\">Debug:</font></b> DataSource::Generic->_result_count = <b>" . $this->_result_count . "</b></div>";
797              $this->draw_status_box();
798          }          }
799            
800          return $this->_result;          return $this->_result;
801    
802          }          }
803    
804      function draw_status_box() {
805    
806        static $boxcount;
807        
808        $boxcount++;
809    
810        $box = container();
811    
812        // box client code (javascript)
813        $code_js = "
814        <script language=\"javascript\">
815        function toggle_vis(id) {
816          elem = eval('document.all.' + id);
817          status = elem.style.getAttribute('display');
818          if (status == 'none') {
819            elem.style.setAttribute('display', 'block');
820          } else {
821            elem.style.setAttribute('display', 'none');
822          }
823        }
824        </script>
825        ";
826        //$script = html_script($code_js);
827        //print $script->render();
828        $box->add( $code_js );
829        
830        // box style
831        $style = container(
832          html_style("text/css", '.boxlabel_darkgreen { color: darkgreen; font-weight:bold; }'),
833          html_style("text/css", '.box_dsg { background: #20ab39; color: white; border: 2px black groove; width:640px; padding:10px; margin:40px; }')
834        );
835        $box->add( $style );
836        
837        // box content
838        $statusbox = html_div('box_dsg');
839        $statusbox->add( html_b("DataSource::Generic"), html_br() );
840        $locatorbox = html_div('box_dsg');
841        $locatorbox->set_id("locatorbox_$boxcount");
842        $locatorbox->add( Dumper($this->_locator) );
843        //$locatorbox->set_style('visibility:false;');
844        $locatorbox->set_style('display:none;');
845        
846        $statusbox->add( html_span('boxlabel_darkgreen', "Locator:"), html_a("javascript:toggle_vis('locatorbox_$boxcount');", '[show]'), $locatorbox, html_br() );
847        $call = $this->_locator->get_call();
848        $statusbox->add( html_span('boxlabel_darkgreen', "Method:"), $call[method], html_br() );
849        if (sizeof($call[args])) {
850          $statusbox->add( html_span('boxlabel_darkgreen', "Arguments:"), Dumper($call[args]), html_br() );
851        }
852        $statusbox->add( html_span('boxlabel_darkgreen', "Count:"), $this->get_result_count(), html_br() );
853        $box->add( $statusbox );
854    
855        print $box->render();
856    
857      }
858    
859    
860    function &query_data() {    function &query_data() {
861      //print "query!<br/>";      //print "query!<br/>";
# Line 701  class DataSource_Generic extends DesignP Line 871  class DataSource_Generic extends DesignP
871    function &get_result() {    function &get_result() {
872      return $this->_result;      return $this->_result;
873    }    }
874      
875      function get_result_count() {
876        return $this->_result_count;
877      }
878                    
879  }  }
880    

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

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