/[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.15 by joko, Sun Apr 6 04:46:33 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.15  2003/04/06 04:46:33  joko
19     * renamed linking function
20     * mozilla fixes
21     *
22     * Revision 1.14  2003/04/04 21:19:21  joko
23     * modified exception handling (enhanced, purged redundant code)
24     *
25     * Revision 1.13  2003/04/04 02:37:14  jonen
26     * _query[action] == write
27     *
28     * Revision 1.12  2003/03/29 08:00:48  joko
29     * modified ErrorBoxing
30     *
31     * Revision 1.11  2003/03/28 06:45:26  joko
32     * VERBOSE mode
33     *
34     * Revision 1.10  2003/03/28 03:01:02  joko
35     * more fancy debugging-output
36     *
37     * Revision 1.9  2003/03/27 16:24:26  jonen
38     * + mugled namespace
39     * + added enhanced 'queryData'
40     *
41     * Revision 1.8  2003/03/20 07:22:14  jonen
42     * + modified case 'object' to 'objects'
43     *   (cause its loads all *objects* of a given classname)
44     *
45     * Revision 1.7  2003/03/11 01:43:00  joko
46     * + fixed metadata for phpDocumentor
47     *
48     * Revision 1.6  2003/03/11 01:22:25  joko
49     * + fixed metadata for phpDocumentor
50     *
51     * Revision 1.5  2003/03/11 00:12:49  joko
52     * + fixed metadata for phpDocumentor
53     *
54     * Revision 1.4  2003/03/10 23:25:03  joko
55     * + fixed metadata for phpDocumentor
56     *
57     * Revision 1.3  2003/03/09 15:50:36  joko
58     * + additional metadata for Autodia
59     *
60     * Revision 1.2  2003/03/05 17:28:43  joko
61     * updated docu (phpDocumentor testing....)
62     *
63   * Revision 1.1  2003/03/05 12:04:00  joko   * Revision 1.1  2003/03/05 12:04:00  joko
64   * + initial commit, from GenericDataSource   * + initial commit, from GenericDataSource
65   *   *
# Line 43  Line 86 
86   *   *
87   * Revision 1.1  2003/03/01 03:10:40  joko   * Revision 1.1  2003/03/01 03:10:40  joko
88   * + initial commit   * + initial commit
89   *   * </pre>
90   *   *
91   */   */
92    
# Line 71  Line 114 
114    // require_once("PEAR.php");   // FIXME: what about PEAR::XML::RPC?    // require_once("PEAR.php");   // FIXME: what about PEAR::XML::RPC?
115    // require_once("DB.php");    // require_once("DB.php");
116    
117    
118    loadModule('DesignPattern::Proxy');
119    loadModule('DesignPattern::TransparentProxy');
120    loadModule('DesignPattern::RemoteProxy');
121    
122    //class GenericDataSource extends MemoryDataSource {
123    //class GenericDataSource extends DesignPattern_Proxy {
124    //class GenericDataSource extends DesignPattern_RemoteProxy {
125    //class GenericDataSource extends DesignPattern_TransparentProxy {
126    
127    //class GenericDataSource extends MemoryDataSource {
128    //loadModule("DataSource::Proxy::Memory");
129    //class GenericDataSource extends DataSource_Proxy_Memory {
130    //class DataSource_GenericDataSource extends DataSource_Proxy_Memory {
131    //class DataSource_GenericDataSource extends DesignPattern_Proxy {
132    //class DataSource_GenericDataSource extends DataSource_Proxy_Memory {
133    
134    // now independent!!! new class-inheritance-tree possible now!
135    // solved by having an Adapter *and* a Proxy here!
136    //class GenericDataSource {
137    
138    loadModule('DesignPattern::AdapterProxy');
139    
140    
141    
142  /**  /**
143   * This GenericDataSource child class is *completely* independent   * This GenericDataSource child class is *completely* independent
144   * of a specific storage implementation and intended to be a wrapper   * of a specific storage implementation and intended to be a wrapper
145   * class on the way from phpHtmlLib to Xyz.   * class on the way from phpHtmlLib to Xyz. <br>
146   *    ("Yyz" gets represented by Data::Storage by now.....)   *    ("Yyz" gets represented by Data::Storage by now.....)
147   *   *
148   * GenericDataSource interacts with an intermediate "proxy" object   * GenericDataSource interacts with an intermediate "proxy" object
149   * (e.g. Data::Driver::Proxy) when doing queries.   * (e.g. Data::Driver::Proxy) when doing queries. <br>
150     * <pre>
151   *    Don't mix this up with a persistent database handle which gets   *    Don't mix this up with a persistent database handle which gets
152   *    reused each and every time for different queries.   *    reused each and every time for different queries.
153   *    Here *is* a new instance of Data::Driver::Proxy for *each* query.   *    Here *is* a new instance of Data::Driver::Proxy for *each* query.
154     * </pre>
155   *   *
156   * But the point is: Caching! The actual *data* isn't read redundant!   * But the point is: Caching! The actual *data* isn't read redundant!
157   *   *
158     * <pre>
159     * --- snipped into here from above ---
160     * that may use arbitrary code modules as database handlers.
161     * It's aims are to get together:
162     *   o phpHtmlLibs "source-handlers"
163     *   o PEAR's database handlers
164     *   o custom ones (e.g. Data::Driver::Proxy object, which talks to a remote rpc server)
165     * --- snipped into here from above ---
166     * </pre>
167   *   *
168     * <p>
169   * !!!!!!  refactor this to Data::Driver::Proxy  !!!!!!     <-----------------   * !!!!!!  refactor this to Data::Driver::Proxy  !!!!!!     <-----------------
170   *   *
171   * Data::Driver::Proxy instantiates "handlers" below itself   * Data::Driver::Proxy instantiates "handlers" below itself
# Line 95  Line 175 
175   * One worker already implemented is Data::Driver::RPC::Remote, which   * One worker already implemented is Data::Driver::RPC::Remote, which
176   * 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.
177   *   *
178     * <pre>
179   * ---  refactored here, but: redundant somehow  ---   * ---  refactored here, but: redundant somehow  ---
180   * Data::Driver::Proxy uses a PEAR XML::RPC object to actually   * Data::Driver::Proxy uses a PEAR XML::RPC object to actually
181   * talk HTTP and serialize data chunks to and from XML,   * talk HTTP and serialize data chunks to and from XML,
# Line 102  Line 183 
183   * It "proxies" arbitrary data chunks a) inside a native php4 session,   * It "proxies" arbitrary data chunks a) inside a native php4 session,
184   * 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.
185   * ---  refactored here, but: redundant somehow  ---   * ---  refactored here, but: redundant somehow  ---
186     * </pre>
187   *   *
188   * !!!!!!  refactor this to Data::Driver::Proxy  !!!!!!     <-----------------   * !!!!!!  refactor this to Data::Driver::Proxy  !!!!!!     <-----------------
189     * </p>
190   *   *
191   *   *
192   * How to use?   * <p>
193     * <b>How to use?</b>
194   *   *
195   * Pass an array holding "locator metadata" to the constructor.   * Pass an array holding "locator metadata" to the constructor.
196   * GenericDataSource takes care of the rest.   * GenericDataSource takes care of the rest.
197   *   *
198     * <pre>
199   * Pass an array to the constructor: (e.g.)   * Pass an array to the constructor: (e.g.)
200   *   *
201   *  1. doing rpc-calls....   *  1. doing rpc-calls....
202     *    <code>
203   *    $locator = array(   *    $locator = array(
204   *      type => 'rpc',   *      type => 'rpc',
205   *      metadata => array( Host => 'localhost', Port => '8765' ),   *      metadata => array( Host => 'localhost', Port => '8765' ),
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   *   *
211   *  2. [proposal] common datahandles....   *  2. [proposal] common datahandles....
212     *    <code>
213   *    $locator = array(   *    $locator = array(
214   *      type => 'mysql',   *      type => 'mysql',
215   *      dsn => 'known dsn markup',   *      dsn => 'known dsn markup',
216   *    );   *    );
217   *    $source = new GenericDataSource($locator);   *    $source = ne w GenericDataSource($locator);
218   *    $this->set_data_source( &$source );   *    $this->set_data_source( &$source );
219     *    </code>
220     * </pre>
221     * </p>
222     *
223   *   *
224     * @link http://www.netfrag.org/~joko/
225   * @author Andreas Motl <andreas.motl@ilo.de>   * @author Andreas Motl <andreas.motl@ilo.de>
226     *
227     * @link http://www.netfrag.org/~jonen/
228   * @author Sebastian Utz <seut@tunemedia.de>   * @author Sebastian Utz <seut@tunemedia.de>
229     *
230   * @copyright (c) 2003 - All Rights reserved.   * @copyright (c) 2003 - All Rights reserved.
231     *
232     * @link http://www.gnu.org/licenses/lgpl.txt
233   * @license GNU LGPL (GNU Lesser General Public License)   * @license GNU LGPL (GNU Lesser General Public License)
234   *   *
  * @author-url http://www.netfrag.org/~joko/  
  * @author-url http://www.netfrag.org/~jonen/  
  * @license-url http://www.gnu.org/licenses/lgpl.txt  
235   *   *
236   * @package phpHtmlLib   * @package org.netfrag.glib
237   * @module GenericDataSource   * @subpackage DataSource
238     * @name DataSource::Generic
239     *
240     * @todo this:
241     * o mungle this to be able to be wrapped around phpHtmlLib's own storage-handles
242     * o implement another Data::Driver::Proxy container
243     *
244     * <pre>
245     *              !!!!!!!!          THIS IS THE PROBLEM          !!!!!!!!
246     *    !!!!!!!!   here is it where we have to break inheritance again   !!!!!!!!
247     *
248     *    THE CONFLICT: Beeing in phpHtmlLib *and* DesignPattern::TransparentProxy
249     *    inheritance trees at the same time, which is *not* possible at
250     *    declare-time. We *do* need some runtime-infrastructure to solve this!
251     *
252     *    TODO: move build- and check-locator stuff from ObjectList to this place!!!
253     *
254     *    ABOUT:
255     *      1. otherwhere: WebApp - scope:
256     *          x handles page vs. block vs. widget; dispatches MVC-View
257     *      2. here: DataSource - scope:
258     *          x handles bridge to frameworks (e.g. phpHtmlLib) vs. actual data driver libs (PEAR, etc.))
259     *          o clean implementation using a DesignPattern::AdapterProxy
260     * </pre>
261   *   *
  */  
   
 /**  
  * Todo:  
  *  
  *  o mungle this to be able to be wrapped around phpHtmlLib's own storage-handles  
  *  o implement another Data::Driver::Proxy container  
262   *   *
263   */   */
   
   
 //              !!!!!!!!          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');  
264  class DataSource_Generic extends DesignPattern_AdapterProxy {  class DataSource_Generic extends DesignPattern_AdapterProxy {
265    
266  //    !!!!!!!!   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 376  class DataSource_Generic extends DesignP
376                  //$this->_locator->_datasource_type = $query[datasource];                  //$this->_locator->_datasource_type = $query[datasource];
377                  //$locator[_datasource_type] = $query[datasource];                  //$locator[_datasource_type] = $query[datasource];
378                                    
379          /**
380           * <!-- Autodia -->
381           * can do: (this is metadata supplied for Autodia, don't delete!)
382           *  $this->_locator = new DataSource_Locator()
383           *
384           */
385    
386                  // build master locator                  // build master locator
387                  $this->_locator = php::mkComponent('DataSource::Locator', $locator, array( datasource_type => $query[datasource] ) );                  $this->_locator = php::mkComponent('DataSource::Locator', $locator, array( datasource_type => $query[datasource] ) );
388                  //exit;                  //exit;
# Line 351  class DataSource_Generic extends DesignP Line 429  class DataSource_Generic extends DesignP
429  //exit;  //exit;
430    
431    
432        /**
433         * <!-- Autodia -->
434         * can do: (this is metadata supplied for Autodia, don't delete!)
435         *  $proxy = new DesignPattern_RemoteProxy()
436         *
437         */
438    
439    
440      // --- Proxy selector/dispatcher ...      // --- Proxy selector/dispatcher ...
441            
442      switch ($this->_locator->_datasource_type) {      switch ($this->_locator->_datasource_type) {
# Line 399  class DataSource_Generic extends DesignP Line 485  class DataSource_Generic extends DesignP
485            case 'phpHtmlLib':            case 'phpHtmlLib':
486              //$adapter_arguments = $args[title];              //$adapter_arguments = $args[title];
487    
488              $this->set_adapter_module('DataSource::Adapter::phpHtmlLib::DataListSource');              $this->set_adapter_module('DataSource::Adapter::phpHtmlLib::DataSource');
489                            
490              // in order to let the Adapter communicate with the Proxy,              // in order to let the Adapter communicate with the Proxy,
491              // 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 532  class DataSource_Generic extends DesignP
532        // $this->create_handler();        // $this->create_handler();
533    
534    
535          /**
536           * <!-- Autodia -->
537           * can do: (this is metadata supplied for Autodia, don't delete!)
538           *  $adapter = new DataSource_Adapter_phpHtmlLib_DataListSource()
539           *
540           */
541    
542        // V1:        // V1:
543        //$this->create_adapter($adapter_module, $this->function, $this->arguments);        //$this->create_adapter($adapter_module, $this->function, $this->arguments);
544    
# Line 597  class DataSource_Generic extends DesignP Line 690  class DataSource_Generic extends DesignP
690        // FIXME: abstract this some more (e.g. via a CommandMapper|Registry)        // FIXME: abstract this some more (e.g. via a CommandMapper|Registry)
691          switch ($this->_query[metatype]) {          switch ($this->_query[metatype]) {
692            case 'data':            case 'data':
693              //$command = 'queryData';              $command = 'queryData';
694              $command = 'getObjects';   // FIXME!!!              
695                //$command = 'getObjects';   // FIXME!!!
696              //$this->_locator->set_option('metadata.command', $command);              //$this->_locator->set_option('metadata.command', $command);
697    /*
698              $args = array();              $args = array();
699              switch ($this->_query[vartype]) {              switch ($this->_query[vartype]) {
700                case 'object':                case 'objects':
701                  if (!$this->_query[classname]) {                  if (!$this->_query[classname]) {
702                    $msg = "_query[vartype] == 'object' requires _query[classname]";                    $msg = "_query[vartype] == 'objects' requires _query[classname]";
703                    user_error("GenericDataSource::query_data() - failed: " . $msg);                    user_error("GenericDataSource::query_data() - failed: " . $msg);
704                  }                  }
705                  array_push($args, $this->_query[classname]);                  array_push($args, $this->_query[classname]);
706                  break;                  break;
707              }              }
708              break;   */
709                $query_args = array();
710                 switch ($this->_query[abstract_type]) {
711                  case 'list':
712                    if (!$this->_query[classname]) {
713                      $msg = "_query[vartype] == 'objects' requires _query[classname]";
714                      user_error("GenericDataSource::query_data() - failed: " . $msg);
715                    }
716                    //array_push($query_args, $this->_query[classname]);
717                    $query_args[classname] = $this->_query[classname];
718                    break;
719                  case 'item':
720                    if (!$this->_query[classname]) {
721                      $msg = "_query[vartype] == 'objects' requires _query[classname]";
722                      user_error("GenericDataSource::query_data() - failed: " . $msg);
723                    }
724                    $query_args[guid] = $this->_query[ident];
725                    $query_args[classname] = $this->_query[classname];
726                    break;              
727                }
728                if($this->_query[action] == 'write') {
729                 $query_args[action] = $this->_query[action];
730                 $query_args[data] = $this->_query[data];
731                }
732                $args = array(
733                              'data_type' => $this->_query[abstract_type],
734                              'query_args' => $query_args
735                              );
736               break;
737    
738              // querySchema
739            case 'schema':            case 'schema':
740                //print "Testing schema:" . "<br>";
741              $command = 'querySchema';              $command = 'querySchema';
742                $args = array( $this->_query[filter] );
743              break;              break;
744          }          }
745                
# Line 648  class DataSource_Generic extends DesignP Line 775  class DataSource_Generic extends DesignP
775                
776    }    }
777    
778    
779    
780          function &fetch_result() {          function &fetch_result() {
781                
782        $this->datasource_handler_buildoptions();        $this->datasource_handler_buildoptions();
783    
784        $method = $this->_locator->_call[_method];        $call = $this->_locator->get_call();
785        $args = $this->_locator->_call[_arguments];        //print Dumper($call);
786          
787        // pre-flight checks        // pre-flight checks
788          if (!$method) {          if (!$call[method]) {
789            $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.";
790                          user_error("GenericDataSource::query_data() - failed: " . $msg);                          user_error("GenericDataSource::query_data() - failed: " . $msg);
791            return;            return;
792          }          }
# Line 666  class DataSource_Generic extends DesignP Line 795  class DataSource_Generic extends DesignP
795    
796        // do remote call here and get result        // do remote call here and get result
797        // FIXME: handle synchronous/asynchronous mode here!!!        // FIXME: handle synchronous/asynchronous mode here!!!
798          $this->datasource_handler_call($method, $args);          $this->datasource_handler_call($call[method], $call[args]);
799                    
800                    
801          // 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 806  class DataSource_Generic extends DesignP
806          $this->_result_count = sizeof($this->_result);          $this->_result_count = sizeof($this->_result);
807    
808        // trace        // trace
809          if ($this->_debug[notice]) {          //if (constants::get('VERBOSE') && $this->_debug[notice]) {
810            if (constants::get('VERBOSE') or constants::get('ERRORS_ONLY')) {
811            //print "_result = " . Dumper($this->_result);            //print "_result = " . Dumper($this->_result);
812            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>";
813              $this->draw_status_box();
814          }          }
815            
816          return $this->_result;          return $this->_result;
817    
818          }          }
819    
820      function draw_status_box() {
821    
822        static $boxcount;
823        
824        $boxcount++;
825    
826        $box = container();
827    
828        // box style
829        $style = container(
830          html_style("text/css", '.boxlabel_darkgreen { color: darkgreen; font-weight:bold; }'),
831          html_style("text/css", '.box_dsg { background: #20ab39; color: white; border: 2px black groove; width:640px; padding:10px; margin:40px; }')
832        );
833        $box->add( $style );
834        
835        // box content
836        $statusbox = html_div('box_dsg');
837        $statusbox->add( html_b("DataSource::Generic"), html_br() );
838        $locatorbox = html_div('box_dsg');
839        $locatorbox->set_id("locatorbox_$boxcount");
840        $locatorbox->add( Dumper($this->_locator) );
841        
842        // FIXME: ie/mozilla?
843        //$locatorbox->set_style('display:none;');
844        //$locatorbox->set_style('visibility:hidden;');
845        // already duplicate inside Tracer!!!
846        $locatorbox->set_style('visibility:hidden; position:absolute; z-index:1; margin-top:30px; padding:5px;');
847        
848        $statusbox->add( html_span('boxlabel_darkgreen', "Locator:"), link::js_function( 'toggleVisibility', array("locatorbox_$boxcount"), '[show]'), $locatorbox, html_br() );
849        $call = $this->_locator->get_call();
850        $statusbox->add( html_span('boxlabel_darkgreen', "Method:"), $call[method], html_br() );
851        if (sizeof($call[args])) {
852          $statusbox->add( html_span('boxlabel_darkgreen', "Arguments:"), Dumper($call[args]), html_br() );
853        }
854        $statusbox->add( html_span('boxlabel_darkgreen', "Count:"), $this->get_result_count(), html_br() );
855        $box->add( $statusbox );
856    
857        //print $box->render();
858        trace( $box );
859    
860      }
861    
862    
863    function &query_data() {    function &query_data() {
864      //print "query!<br/>";      //print "query!<br/>";
# Line 701  class DataSource_Generic extends DesignP Line 874  class DataSource_Generic extends DesignP
874    function &get_result() {    function &get_result() {
875      return $this->_result;      return $this->_result;
876    }    }
877      
878      function get_result_count() {
879        return $this->_result_count;
880      }
881                    
882  }  }
883    

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

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