/[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.10 by joko, Fri Mar 28 03:01:02 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.10  2003/03/28 03:01:02  joko
19     * more fancy debugging-output
20     *
21     * Revision 1.9  2003/03/27 16:24:26  jonen
22     * + mugled namespace
23     * + added enhanced 'queryData'
24     *
25     * Revision 1.8  2003/03/20 07:22:14  jonen
26     * + modified case 'object' to 'objects'
27     *   (cause its loads all *objects* of a given classname)
28     *
29     * Revision 1.7  2003/03/11 01:43:00  joko
30     * + fixed metadata for phpDocumentor
31     *
32     * Revision 1.6  2003/03/11 01:22:25  joko
33     * + fixed metadata for phpDocumentor
34     *
35     * Revision 1.5  2003/03/11 00:12:49  joko
36     * + fixed metadata for phpDocumentor
37     *
38     * Revision 1.4  2003/03/10 23:25:03  joko
39     * + fixed metadata for phpDocumentor
40     *
41     * Revision 1.3  2003/03/09 15:50:36  joko
42     * + additional metadata for Autodia
43     *
44     * Revision 1.2  2003/03/05 17:28:43  joko
45     * updated docu (phpDocumentor testing....)
46     *
47   * Revision 1.1  2003/03/05 12:04:00  joko   * Revision 1.1  2003/03/05 12:04:00  joko
48   * + initial commit, from GenericDataSource   * + initial commit, from GenericDataSource
49   *   *
# Line 43  Line 70 
70   *   *
71   * Revision 1.1  2003/03/01 03:10:40  joko   * Revision 1.1  2003/03/01 03:10:40  joko
72   * + initial commit   * + initial commit
73   *   * </pre>
74   *   *
75   */   */
76    
# Line 71  Line 98 
98    // require_once("PEAR.php");   // FIXME: what about PEAR::XML::RPC?    // require_once("PEAR.php");   // FIXME: what about PEAR::XML::RPC?
99    // require_once("DB.php");    // require_once("DB.php");
100    
101    
102    loadModule('DesignPattern::Proxy');
103    loadModule('DesignPattern::TransparentProxy');
104    loadModule('DesignPattern::RemoteProxy');
105    
106    //class GenericDataSource extends MemoryDataSource {
107    //class GenericDataSource extends DesignPattern_Proxy {
108    //class GenericDataSource extends DesignPattern_RemoteProxy {
109    //class GenericDataSource extends DesignPattern_TransparentProxy {
110    
111    //class GenericDataSource extends MemoryDataSource {
112    //loadModule("DataSource::Proxy::Memory");
113    //class GenericDataSource extends DataSource_Proxy_Memory {
114    //class DataSource_GenericDataSource extends DataSource_Proxy_Memory {
115    //class DataSource_GenericDataSource extends DesignPattern_Proxy {
116    //class DataSource_GenericDataSource extends DataSource_Proxy_Memory {
117    
118    // now independent!!! new class-inheritance-tree possible now!
119    // solved by having an Adapter *and* a Proxy here!
120    //class GenericDataSource {
121    
122    loadModule('DesignPattern::AdapterProxy');
123    
124    
125    
126  /**  /**
127   * This GenericDataSource child class is *completely* independent   * This GenericDataSource child class is *completely* independent
128   * of a specific storage implementation and intended to be a wrapper   * of a specific storage implementation and intended to be a wrapper
129   * class on the way from phpHtmlLib to Xyz.   * class on the way from phpHtmlLib to Xyz. <br>
130   *    ("Yyz" gets represented by Data::Storage by now.....)   *    ("Yyz" gets represented by Data::Storage by now.....)
131   *   *
132   * GenericDataSource interacts with an intermediate "proxy" object   * GenericDataSource interacts with an intermediate "proxy" object
133   * (e.g. Data::Driver::Proxy) when doing queries.   * (e.g. Data::Driver::Proxy) when doing queries. <br>
134     * <pre>
135   *    Don't mix this up with a persistent database handle which gets   *    Don't mix this up with a persistent database handle which gets
136   *    reused each and every time for different queries.   *    reused each and every time for different queries.
137   *    Here *is* a new instance of Data::Driver::Proxy for *each* query.   *    Here *is* a new instance of Data::Driver::Proxy for *each* query.
138     * </pre>
139   *   *
140   * But the point is: Caching! The actual *data* isn't read redundant!   * But the point is: Caching! The actual *data* isn't read redundant!
141   *   *
142     * <pre>
143     * --- snipped into here from above ---
144     * that may use arbitrary code modules as database handlers.
145     * It's aims are to get together:
146     *   o phpHtmlLibs "source-handlers"
147     *   o PEAR's database handlers
148     *   o custom ones (e.g. Data::Driver::Proxy object, which talks to a remote rpc server)
149     * --- snipped into here from above ---
150     * </pre>
151   *   *
152     * <p>
153   * !!!!!!  refactor this to Data::Driver::Proxy  !!!!!!     <-----------------   * !!!!!!  refactor this to Data::Driver::Proxy  !!!!!!     <-----------------
154   *   *
155   * Data::Driver::Proxy instantiates "handlers" below itself   * Data::Driver::Proxy instantiates "handlers" below itself
# Line 95  Line 159 
159   * One worker already implemented is Data::Driver::RPC::Remote, which   * One worker already implemented is Data::Driver::RPC::Remote, which
160   * 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.
161   *   *
162     * <pre>
163   * ---  refactored here, but: redundant somehow  ---   * ---  refactored here, but: redundant somehow  ---
164   * Data::Driver::Proxy uses a PEAR XML::RPC object to actually   * Data::Driver::Proxy uses a PEAR XML::RPC object to actually
165   * talk HTTP and serialize data chunks to and from XML,   * talk HTTP and serialize data chunks to and from XML,
# Line 102  Line 167 
167   * It "proxies" arbitrary data chunks a) inside a native php4 session,   * It "proxies" arbitrary data chunks a) inside a native php4 session,
168   * 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.
169   * ---  refactored here, but: redundant somehow  ---   * ---  refactored here, but: redundant somehow  ---
170     * </pre>
171   *   *
172   * !!!!!!  refactor this to Data::Driver::Proxy  !!!!!!     <-----------------   * !!!!!!  refactor this to Data::Driver::Proxy  !!!!!!     <-----------------
173     * </p>
174   *   *
175   *   *
176   * How to use?   * <p>
177     * <b>How to use?</b>
178   *   *
179   * Pass an array holding "locator metadata" to the constructor.   * Pass an array holding "locator metadata" to the constructor.
180   * GenericDataSource takes care of the rest.   * GenericDataSource takes care of the rest.
181   *   *
182     * <pre>
183   * Pass an array to the constructor: (e.g.)   * Pass an array to the constructor: (e.g.)
184   *   *
185   *  1. doing rpc-calls....   *  1. doing rpc-calls....
186     *    <code>
187   *    $locator = array(   *    $locator = array(
188   *      type => 'rpc',   *      type => 'rpc',
189   *      metadata => array( Host => 'localhost', Port => '8765' ),   *      metadata => array( Host => 'localhost', Port => '8765' ),
190   *    );   *    );
191   *    $source = new GenericDataSource($locator);   *    $source = ne w GenericDataSource($locator);
192   *    $this->set_data_source( &$source );   *    $this->set_data_source( &$source );
193     *    </code>
194   *   *
195   *  2. [proposal] common datahandles....   *  2. [proposal] common datahandles....
196     *    <code>
197   *    $locator = array(   *    $locator = array(
198   *      type => 'mysql',   *      type => 'mysql',
199   *      dsn => 'known dsn markup',   *      dsn => 'known dsn markup',
200   *    );   *    );
201   *    $source = new GenericDataSource($locator);   *    $source = ne w GenericDataSource($locator);
202   *    $this->set_data_source( &$source );   *    $this->set_data_source( &$source );
203     *    </code>
204     * </pre>
205     * </p>
206   *   *
207     *
208     * @link http://www.netfrag.org/~joko/
209   * @author Andreas Motl <andreas.motl@ilo.de>   * @author Andreas Motl <andreas.motl@ilo.de>
210     *
211     * @link http://www.netfrag.org/~jonen/
212   * @author Sebastian Utz <seut@tunemedia.de>   * @author Sebastian Utz <seut@tunemedia.de>
213     *
214   * @copyright (c) 2003 - All Rights reserved.   * @copyright (c) 2003 - All Rights reserved.
  * @license GNU LGPL (GNU Lesser General Public License)  
215   *   *
216   * @author-url http://www.netfrag.org/~joko/   * @link http://www.gnu.org/licenses/lgpl.txt
217   * @author-url http://www.netfrag.org/~jonen/   * @license GNU LGPL (GNU Lesser General Public License)
  * @license-url http://www.gnu.org/licenses/lgpl.txt  
218   *   *
  * @package phpHtmlLib  
  * @module GenericDataSource  
219   *   *
220   */   * @package org.netfrag.glib
221     * @subpackage DataSource
222  /**   * @name DataSource::Generic
223   * Todo:   *
224     * @todo this:
225     * o mungle this to be able to be wrapped around phpHtmlLib's own storage-handles
226     * o implement another Data::Driver::Proxy container
227     *
228     * <pre>
229     *              !!!!!!!!          THIS IS THE PROBLEM          !!!!!!!!
230     *    !!!!!!!!   here is it where we have to break inheritance again   !!!!!!!!
231     *
232     *    THE CONFLICT: Beeing in phpHtmlLib *and* DesignPattern::TransparentProxy
233     *    inheritance trees at the same time, which is *not* possible at
234     *    declare-time. We *do* need some runtime-infrastructure to solve this!
235     *
236     *    TODO: move build- and check-locator stuff from ObjectList to this place!!!
237     *
238     *    ABOUT:
239     *      1. otherwhere: WebApp - scope:
240     *          x handles page vs. block vs. widget; dispatches MVC-View
241     *      2. here: DataSource - scope:
242     *          x handles bridge to frameworks (e.g. phpHtmlLib) vs. actual data driver libs (PEAR, etc.))
243     *          o clean implementation using a DesignPattern::AdapterProxy
244     * </pre>
245   *   *
  *  o mungle this to be able to be wrapped around phpHtmlLib's own storage-handles  
  *  o implement another Data::Driver::Proxy container  
246   *   *
247   */   */
   
   
 //              !!!!!!!!          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');  
248  class DataSource_Generic extends DesignPattern_AdapterProxy {  class DataSource_Generic extends DesignPattern_AdapterProxy {
249    
250  //    !!!!!!!!   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 360  class DataSource_Generic extends DesignP
360                  //$this->_locator->_datasource_type = $query[datasource];                  //$this->_locator->_datasource_type = $query[datasource];
361                  //$locator[_datasource_type] = $query[datasource];                  //$locator[_datasource_type] = $query[datasource];
362                                    
363          /**
364           * <!-- Autodia -->
365           * can do: (this is metadata supplied for Autodia, don't delete!)
366           *  $this->_locator = new DataSource_Locator()
367           *
368           */
369    
370                  // build master locator                  // build master locator
371                  $this->_locator = php::mkComponent('DataSource::Locator', $locator, array( datasource_type => $query[datasource] ) );                  $this->_locator = php::mkComponent('DataSource::Locator', $locator, array( datasource_type => $query[datasource] ) );
372                  //exit;                  //exit;
# Line 351  class DataSource_Generic extends DesignP Line 413  class DataSource_Generic extends DesignP
413  //exit;  //exit;
414    
415    
416        /**
417         * <!-- Autodia -->
418         * can do: (this is metadata supplied for Autodia, don't delete!)
419         *  $proxy = new DesignPattern_RemoteProxy()
420         *
421         */
422    
423    
424      // --- Proxy selector/dispatcher ...      // --- Proxy selector/dispatcher ...
425            
426      switch ($this->_locator->_datasource_type) {      switch ($this->_locator->_datasource_type) {
# Line 399  class DataSource_Generic extends DesignP Line 469  class DataSource_Generic extends DesignP
469            case 'phpHtmlLib':            case 'phpHtmlLib':
470              //$adapter_arguments = $args[title];              //$adapter_arguments = $args[title];
471    
472              $this->set_adapter_module('DataSource::Adapter::phpHtmlLib::DataListSource');              $this->set_adapter_module('DataSource::Adapter::phpHtmlLib::DataSource');
473                            
474              // in order to let the Adapter communicate with the Proxy,              // in order to let the Adapter communicate with the Proxy,
475              // 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 516  class DataSource_Generic extends DesignP
516        // $this->create_handler();        // $this->create_handler();
517    
518    
519          /**
520           * <!-- Autodia -->
521           * can do: (this is metadata supplied for Autodia, don't delete!)
522           *  $adapter = new DataSource_Adapter_phpHtmlLib_DataListSource()
523           *
524           */
525    
526        // V1:        // V1:
527        //$this->create_adapter($adapter_module, $this->function, $this->arguments);        //$this->create_adapter($adapter_module, $this->function, $this->arguments);
528    
# Line 597  class DataSource_Generic extends DesignP Line 674  class DataSource_Generic extends DesignP
674        // FIXME: abstract this some more (e.g. via a CommandMapper|Registry)        // FIXME: abstract this some more (e.g. via a CommandMapper|Registry)
675          switch ($this->_query[metatype]) {          switch ($this->_query[metatype]) {
676            case 'data':            case 'data':
677              //$command = 'queryData';              $command = 'queryData';
678              $command = 'getObjects';   // FIXME!!!              //$command = 'getObjects';   // FIXME!!!
679              //$this->_locator->set_option('metadata.command', $command);              //$this->_locator->set_option('metadata.command', $command);
680    /*
681              $args = array();              $args = array();
682              switch ($this->_query[vartype]) {              switch ($this->_query[vartype]) {
683                case 'object':                case 'objects':
684                  if (!$this->_query[classname]) {                  if (!$this->_query[classname]) {
685                    $msg = "_query[vartype] == 'object' requires _query[classname]";                    $msg = "_query[vartype] == 'objects' requires _query[classname]";
686                    user_error("GenericDataSource::query_data() - failed: " . $msg);                    user_error("GenericDataSource::query_data() - failed: " . $msg);
687                  }                  }
688                  array_push($args, $this->_query[classname]);                  array_push($args, $this->_query[classname]);
689                  break;                  break;
690              }              }
691              break;   */
692                $query_args = array();
693                 switch ($this->_query[abstract_type]) {
694                  case 'list':
695                    if (!$this->_query[classname]) {
696                      $msg = "_query[vartype] == 'objects' requires _query[classname]";
697                      user_error("GenericDataSource::query_data() - failed: " . $msg);
698                    }
699                    //array_push($query_args, $this->_query[classname]);
700                    $query_args[classname] = $this->_query[classname];
701                    break;
702                  case 'item':
703                    if (!$this->_query[classname]) {
704                      $msg = "_query[vartype] == 'objects' requires _query[classname]";
705                      user_error("GenericDataSource::query_data() - failed: " . $msg);
706                    }
707                    $query_args[guid] = $this->_query[ident];
708                    $query_args[classname] = $this->_query[classname];
709                    break;              
710                }
711                $args = array(
712                              'data_type' => $this->_query[abstract_type],
713                              'query_args' => $query_args
714                              );
715               break;
716    
717              // querySchema
718            case 'schema':            case 'schema':
719                //print "Testing schema:" . "<br>";
720              $command = 'querySchema';              $command = 'querySchema';
721              break;              break;
722          }          }
# Line 679  class DataSource_Generic extends DesignP Line 784  class DataSource_Generic extends DesignP
784        // trace        // trace
785          if ($this->_debug[notice]) {          if ($this->_debug[notice]) {
786            //print "_result = " . Dumper($this->_result);            //print "_result = " . Dumper($this->_result);
787            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>";
788          }          }
789                    
790          return $this->_result;          return $this->_result;

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

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