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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.26 - (hide annotations)
Sun Dec 14 01:53:42 2003 UTC (20 years, 8 months ago) by jonen
Branch: MAIN
Changes since 1.25: +18 -1 lines
implemented 'SELECT' mode for selecting existing object-refereneces as child-nodes

1 joko 1.1 <?php
2     /**
3     * This file contains the GenericDataSource child class
4     *
5     * @author Andreas Motl <andreas.motl@ilo.de>
6 joko 1.2 * @package org.netfrag.glib
7     * @name DataSource::Generic
8 joko 1.1 *
9     */
10    
11     /**
12 joko 1.19 * Cvs-Log:
13 joko 1.6 *
14 jonen 1.26 * $Id: Generic.php,v 1.25 2003/11/17 18:01:03 jonen Exp $
15 joko 1.2 *
16     * $Log: Generic.php,v $
17 jonen 1.26 * Revision 1.25 2003/11/17 18:01:03 jonen
18     * bugfix: php cannot use perl-syntax!! ;-)
19     *
20 jonen 1.24 * Revision 1.23 2003/07/14 10:02:32 jonen
21     * removed debug dumper
22     *
23 jonen 1.23 * Revision 1.22 2003/06/06 04:25:45 joko
24     * fix: query args get encapsulated once more
25     *
26 joko 1.22 * Revision 1.21 2003/05/10 18:14:50 jonen
27     * + implements 'create' of item (query mapping part)
28     *
29 jonen 1.21 * Revision 1.20 2003/04/19 16:07:15 jonen
30     * + added '_query[list_meta]' at 'queryData' needed for meta query args
31     * (e.g. at UserManagment)
32     *
33 jonen 1.20 * Revision 1.19 2003/04/18 15:40:51 joko
34     * NEW: tree data handling
35     * introduced new adapter: DataSource::Adapter::Free
36     * enhanced datasource_handler_buildoptions: now handles a) case 'tree' b) _query[filter]
37     *
38 joko 1.19 * Revision 1.18 2003/04/11 00:55:49 joko
39     * updated 'datasource_handler_buildoptions': action dispatcher now aware of 'delete'
40     *
41 joko 1.18 * Revision 1.17 2003/04/09 02:07:33 joko
42     * CHANGE: renamed key 'classname' through 'nodename'
43     *
44 joko 1.17 * Revision 1.16 2003/04/08 17:55:20 joko
45     * CHANGE: renamed property 'datasource' to 'transport'
46     * NEW: new case 'method' in 'function datasource_handler_buildoptions'
47     * minor fixes: updated logging/debugging messages
48     *
49 joko 1.16 * Revision 1.15 2003/04/06 04:46:33 joko
50     * renamed linking function
51     * mozilla fixes
52     *
53 joko 1.15 * Revision 1.14 2003/04/04 21:19:21 joko
54     * modified exception handling (enhanced, purged redundant code)
55     *
56 joko 1.14 * Revision 1.13 2003/04/04 02:37:14 jonen
57     * _query[action] == write
58     *
59 jonen 1.13 * Revision 1.12 2003/03/29 08:00:48 joko
60     * modified ErrorBoxing
61     *
62 joko 1.12 * Revision 1.11 2003/03/28 06:45:26 joko
63     * VERBOSE mode
64     *
65 joko 1.11 * Revision 1.10 2003/03/28 03:01:02 joko
66     * more fancy debugging-output
67     *
68 joko 1.10 * Revision 1.9 2003/03/27 16:24:26 jonen
69     * + mugled namespace
70     * + added enhanced 'queryData'
71     *
72 jonen 1.9 * Revision 1.8 2003/03/20 07:22:14 jonen
73     * + modified case 'object' to 'objects'
74     * (cause its loads all *objects* of a given classname)
75     *
76 jonen 1.8 * Revision 1.7 2003/03/11 01:43:00 joko
77     * + fixed metadata for phpDocumentor
78     *
79 joko 1.7 * Revision 1.6 2003/03/11 01:22:25 joko
80     * + fixed metadata for phpDocumentor
81     *
82 joko 1.6 * Revision 1.5 2003/03/11 00:12:49 joko
83     * + fixed metadata for phpDocumentor
84     *
85 joko 1.5 * Revision 1.4 2003/03/10 23:25:03 joko
86     * + fixed metadata for phpDocumentor
87     *
88 joko 1.4 * Revision 1.3 2003/03/09 15:50:36 joko
89     * + additional metadata for Autodia
90     *
91 joko 1.3 * Revision 1.2 2003/03/05 17:28:43 joko
92     * updated docu (phpDocumentor testing....)
93     *
94 joko 1.2 * Revision 1.1 2003/03/05 12:04:00 joko
95     * + initial commit, from GenericDataSource
96 joko 1.1 *
97     * Revision 1.3 2003/03/03 21:24:18 joko
98     * now based on DesignPattern::RemoteProxy
99     *
100     * Revision 1.2 2003/03/02 01:05:13 joko
101     * - purged old code
102     *
103     * Revision 1.1 2003/03/01 21:47:15 joko
104     * renamed from AbstractDataSource.inc
105     *
106     * Revision 1.1 2003/03/01 20:17:15 joko
107     * renamed from GenericDataSource.inc
108     * replaced '_proxy' through '_handler' to better associate the ability to act as a generic dispatcher handler
109     *
110     * Revision 1.3 2003/03/01 15:36:11 joko
111     * + debugging
112     * + renamed some methods regarding new proposal (build_handler_options, fetch_result, etc.)
113     *
114     * Revision 1.2 2003/03/01 04:50:27 joko
115     * encapsulated all output into tracing mode
116     * disabled tracing
117     *
118     * Revision 1.1 2003/03/01 03:10:40 joko
119     * + initial commit
120     *
121     */
122    
123     /**
124     * This requires the MemoryDataSource base class
125     *
126     */
127    
128     // V1: compile-time-include, stable since years ;-)
129     //include_once($phphtmllib."/widgets/data_source/MemoryDataSource.inc");
130    
131     // V2: runtime-load proposal, more flexible
132     // loadModule('MemoryDataSource', 'inc'); // doesn't work (would do if basepath of module is in libpath)
133     // loadModule($phphtmllib . '::widgets::data_source::MemoryDataSource', 'inc'); // works (by accident)
134     // loadModule($phphtmllib . "/widgets/data_source/MemoryDataSource", "inc"); // works (should be stable)
135     // loadModule($phphtmllib . "/widgets/data_source/MemoryDataSource.inc", null); // works (should be stable)
136    
137    
138    
139     /**
140     * Have to have PEAR and DB included
141     * the pear dir must be in the
142     * include path.
143     */
144     // require_once("PEAR.php"); // FIXME: what about PEAR::XML::RPC?
145     // require_once("DB.php");
146    
147 joko 1.2
148     loadModule('DesignPattern::Proxy');
149     loadModule('DesignPattern::TransparentProxy');
150     loadModule('DesignPattern::RemoteProxy');
151    
152     //class GenericDataSource extends MemoryDataSource {
153     //class GenericDataSource extends DesignPattern_Proxy {
154     //class GenericDataSource extends DesignPattern_RemoteProxy {
155     //class GenericDataSource extends DesignPattern_TransparentProxy {
156    
157     //class GenericDataSource extends MemoryDataSource {
158     //loadModule("DataSource::Proxy::Memory");
159     //class GenericDataSource extends DataSource_Proxy_Memory {
160     //class DataSource_GenericDataSource extends DataSource_Proxy_Memory {
161     //class DataSource_GenericDataSource extends DesignPattern_Proxy {
162     //class DataSource_GenericDataSource extends DataSource_Proxy_Memory {
163    
164     // now independent!!! new class-inheritance-tree possible now!
165     // solved by having an Adapter *and* a Proxy here!
166     //class GenericDataSource {
167    
168     loadModule('DesignPattern::AdapterProxy');
169    
170    
171    
172 joko 1.1 /**
173     * This GenericDataSource child class is *completely* independent
174     * of a specific storage implementation and intended to be a wrapper
175 joko 1.2 * class on the way from phpHtmlLib to Xyz. <br>
176 joko 1.1 * ("Yyz" gets represented by Data::Storage by now.....)
177     *
178     * GenericDataSource interacts with an intermediate "proxy" object
179 joko 1.2 * (e.g. Data::Driver::Proxy) when doing queries. <br>
180     * <pre>
181 joko 1.1 * Don't mix this up with a persistent database handle which gets
182     * reused each and every time for different queries.
183     * Here *is* a new instance of Data::Driver::Proxy for *each* query.
184 joko 1.2 * </pre>
185 joko 1.1 *
186     * But the point is: Caching! The actual *data* isn't read redundant!
187     *
188 joko 1.2 * <pre>
189     * --- snipped into here from above ---
190     * that may use arbitrary code modules as database handlers.
191     * It's aims are to get together:
192     * o phpHtmlLibs "source-handlers"
193     * o PEAR's database handlers
194     * o custom ones (e.g. Data::Driver::Proxy object, which talks to a remote rpc server)
195     * --- snipped into here from above ---
196     * </pre>
197     *
198 joko 1.7 * <p>
199 joko 1.1 * !!!!!! refactor this to Data::Driver::Proxy !!!!!! <-----------------
200     *
201     * Data::Driver::Proxy instantiates "handlers" below itself
202     * which act as encapsulated workers to actually do the stuff to do.
203     * It can cache data for "disconnected mode" using the
204     * php PEAR DB abstraction objects.
205     * One worker already implemented is Data::Driver::RPC::Remote, which
206     * talks to a RPC::XML server (todo: talk SOAP!) using PEAR::XML::RPC.
207     *
208 joko 1.2 * <pre>
209 joko 1.1 * --- refactored here, but: redundant somehow ---
210     * Data::Driver::Proxy uses a PEAR XML::RPC object to actually
211     * talk HTTP and serialize data chunks to and from XML,
212     * but adds some caching to this "process of fetching data from a remote side".
213     * It "proxies" arbitrary data chunks a) inside a native php4 session,
214     * b) by talking to a rdbms (single proxy-table) or c) [TODO] using PEAR::Cache.
215     * --- refactored here, but: redundant somehow ---
216 joko 1.2 * </pre>
217 joko 1.1 *
218     * !!!!!! refactor this to Data::Driver::Proxy !!!!!! <-----------------
219 joko 1.7 * </p>
220 joko 1.1 *
221     *
222 joko 1.7 * <p>
223 joko 1.2 * <b>How to use?</b>
224 joko 1.1 *
225     * Pass an array holding "locator metadata" to the constructor.
226     * GenericDataSource takes care of the rest.
227     *
228 joko 1.7 * <pre>
229 joko 1.1 * Pass an array to the constructor: (e.g.)
230     *
231     * 1. doing rpc-calls....
232 joko 1.2 * <code>
233 joko 1.1 * $locator = array(
234     * type => 'rpc',
235     * metadata => array( Host => 'localhost', Port => '8765' ),
236     * );
237 joko 1.3 * $source = ne w GenericDataSource($locator);
238 joko 1.1 * $this->set_data_source( &$source );
239 joko 1.2 * </code>
240 joko 1.1 *
241     * 2. [proposal] common datahandles....
242 joko 1.2 * <code>
243 joko 1.1 * $locator = array(
244     * type => 'mysql',
245     * dsn => 'known dsn markup',
246     * );
247 joko 1.3 * $source = ne w GenericDataSource($locator);
248 joko 1.1 * $this->set_data_source( &$source );
249 joko 1.2 * </code>
250 joko 1.7 * </pre>
251     * </p>
252     *
253 joko 1.1 *
254 joko 1.2 * @link http://www.netfrag.org/~joko/
255 joko 1.1 * @author Andreas Motl <andreas.motl@ilo.de>
256 joko 1.2 *
257     * @link http://www.netfrag.org/~jonen/
258 joko 1.1 * @author Sebastian Utz <seut@tunemedia.de>
259 joko 1.2 *
260 joko 1.1 * @copyright (c) 2003 - All Rights reserved.
261 joko 1.2 *
262     * @link http://www.gnu.org/licenses/lgpl.txt
263 joko 1.1 * @license GNU LGPL (GNU Lesser General Public License)
264     *
265     *
266 joko 1.2 * @package org.netfrag.glib
267     * @subpackage DataSource
268     * @name DataSource::Generic
269 joko 1.1 *
270 joko 1.4 * @todo this:
271 joko 1.5 * o mungle this to be able to be wrapped around phpHtmlLib's own storage-handles
272     * o implement another Data::Driver::Proxy container
273 joko 1.1 *
274 joko 1.5 * <pre>
275 joko 1.4 * !!!!!!!! THIS IS THE PROBLEM !!!!!!!!
276     * !!!!!!!! here is it where we have to break inheritance again !!!!!!!!
277     *
278     * THE CONFLICT: Beeing in phpHtmlLib *and* DesignPattern::TransparentProxy
279     * inheritance trees at the same time, which is *not* possible at
280     * declare-time. We *do* need some runtime-infrastructure to solve this!
281     *
282     * TODO: move build- and check-locator stuff from ObjectList to this place!!!
283     *
284     * ABOUT:
285     * 1. otherwhere: WebApp - scope:
286     * x handles page vs. block vs. widget; dispatches MVC-View
287     * 2. here: DataSource - scope:
288     * x handles bridge to frameworks (e.g. phpHtmlLib) vs. actual data driver libs (PEAR, etc.))
289     * o clean implementation using a DesignPattern::AdapterProxy
290 joko 1.5 * </pre>
291 joko 1.4 *
292     *
293     */
294 joko 1.1 class DataSource_Generic extends DesignPattern_AdapterProxy {
295    
296     // !!!!!!!! here is it where we have to break inheritance again !!!!!!!!
297     // !!!!!!!! THIS IS THE PROBLEM !!!!!!!!
298    
299    
300    
301     /**
302     * This var holds the locator metadata hash
303     * that is used to feed metadata to a per-query-instance
304     * of an Adapter object.
305     *
306     */
307     //var $_locator = NULL;
308    
309     /**
310     * This var holds the locator metadata hash
311     * which is built from some predefined rules
312     * using metadata from $_options and some
313     * other presets.
314     *
315     * See '_buildLocator' which acts as a dispatcher
316 joko 1.16 * depending on $_options[transport].
317 joko 1.1 * (main dispatching level)
318     *
319     * The structure of a full blown locator looks like this:
320     *
321     * $locator = array(
322     * type => '<your type specifying the datasource-type>',
323     * metadata => array(
324     * ... your arbitrary deep metadata structure ...
325     * ),
326     * [dsn => '<your dsn markup>'],
327     * );
328     *
329     * Example 1 - data is inside a rdbms, using a dsn to connect to it:
330     * $locator = array(
331     * type => 'sql',
332     * dsn => 'mysql://username:password@localhost/database',
333     * );
334     *
335     * Example 2 - data is inside an odbms, reachable by doing remote procedure calls (rpc):
336     * $locator = array(
337     * type => 'rpc',
338     * metadata => array(
339     * package => 'Data::Driver::Proxy',
340     * Host => 'localhost',
341     * Port => '8765',
342     * )
343     * );
344     *
345     */
346     var $_locator = NULL;
347    
348    
349     /**
350     * This var holds the module information required to
351     * create instances of a Proxy and an Adapter.
352     * Information might get extracted from a
353     * DataSource::Locator instance.
354     *
355     * --- A skeleton:
356     *
357     * $this->_modules = array(
358     * _proxy => array( _id => '', _module => '', _options = array(), _instance => &$obj),
359     * _adapter => array( _id => '', _module => '', _options = array(), _instance => &$obj),
360     * );
361     *
362     *
363     * --- An example:
364     *
365     * $this->_modules = array(
366     * _proxy => array( _id => 'rpc', _module => 'DesignPattern::RemoteProxy', _instance => &$obj),
367     * _adapter => array( _id => 'phpHtmlLib', _module => 'DataSource::Adapter::phpHtmlLib::DataListSource', _instance => &$obj),
368     * );
369     *
370     *
371     */
372     //var $_modules = NULL;
373    
374    
375     /**
376     * This var holds the query hash
377     * that is used to feed as query to a per-query-instance
378     * of a Data::Driver::Proxy object.
379     *
380     */
381     var $_query = NULL;
382    
383    
384     /**
385     * this holds the query result from the
386     * Data::Driver::Proxy->queryXyz() call
387     *
388     */
389     var $_result = NULL;
390    
391    
392    
393     /**
394     * The constructor is used to pass in the
395     * locator metadata hash.
396     *
397     * @param LocatorMetadataHash array - layout: array( type => '', metadata => '', dsn => '' )
398     * @param Query array - layout: array( type => '', metadata => '', dsn => '' )
399     */
400    
401    
402     function DataSource_Generic( &$locator, $query ) {
403    
404     // copy parameter from query to locator
405 joko 1.16 //$this->_locator->merge_to($this->_locator, array( datasource_type => $query[transport] ), '_');
406     //$this->_locator->_datasource_type = $query[transport];
407     //$locator[_datasource_type] = $query[transport];
408 joko 1.1
409 joko 1.3 /**
410     * <!-- Autodia -->
411     * can do: (this is metadata supplied for Autodia, don't delete!)
412     * $this->_locator = new DataSource_Locator()
413     *
414     */
415    
416 joko 1.1 // build master locator
417 joko 1.16 $this->_locator = php::mkComponent('DataSource::Locator', $locator, array( datasource_type => $query[transport] ) );
418 joko 1.1 //exit;
419     //$this->_locator = php::mkComponent('DataSource::Locator');
420    
421     $this->_locator->check();
422    
423     // trace
424     //print "locator-obj: " . Dumper($this->_locator);
425     //print "locator-data: " . Dumper($locator_data);
426     //exit;
427    
428    
429    
430     /*
431     $this->_modules = array(
432     _proxy => array( _id => $locator->_datasource_type ),
433     _adapter => array( _id => $locator->_adapter_type ),
434     );
435     */
436    
437     //$this->set_locator( $locator );
438     $this->set_query( $query );
439    
440    
441    
442     /*
443     // V1:
444     // pre-flight: establish and check locator metadata
445     $this->_buildLocator();
446     $this->_checkLocator();
447     */
448    
449    
450    
451     // pre-flight: check locator metadata
452     //$locator->build();
453     if (!$this->_locator->check()) {
454 joko 1.16 user_error("DataSource::Generic: locator-check failed." . "<br/>" . "Locator was: " . Dumper($this->_locator) );
455     //exit;
456     return;
457 joko 1.1 }
458    
459     //exit;
460    
461    
462 joko 1.3 /**
463     * <!-- Autodia -->
464     * can do: (this is metadata supplied for Autodia, don't delete!)
465     * $proxy = new DesignPattern_RemoteProxy()
466     *
467     */
468    
469    
470 joko 1.1 // --- Proxy selector/dispatcher ...
471    
472     switch ($this->_locator->_datasource_type) {
473     case 'rpc':
474     //$locator_data = $this->_locator->get_metadata();
475     //$this->_modules[_proxy][_options] = array( locator => $this->_locator, query => $query );
476     //$this->_modules[_proxy][_module] = 'DataSource::Proxy::XMLRPC';
477    
478     //$this->_modules[_proxy][_module] = 'DesignPattern::RemoteProxy';
479     //$this->_modules[_proxy][_options] = $locator_data;
480    
481     //$this->set_component_name('DesignPattern::RemoteProxy');
482     //$this->set_component_options($locator_data);
483    
484     $this->set_component_name('DesignPattern::RemoteProxy');
485    
486     break;
487     default:
488     user_error("Site::GenericPage: no Proxy could be selected!");
489     break;
490     }
491    
492    
493    
494     /*
495     // V1:
496     // make up dummy args by now
497     $args = array(
498     adapter => 'phpHtmlLib',
499     );
500     */
501    
502     // V2: now propagated from caller!
503    
504     //print Dumper(array( locator => $locator, query => $query ));
505     //exit;
506    
507     //$this->create_adapter($this->module, $this->function, $this->arguments);
508     //$this->set_handler( $this->get_adapter() );
509    
510    
511     // --- Adapter selector/dispatcher ...
512     // ... resolves this._modules.adapter._id to this._modules.adapter._module
513    
514     switch ($locator->_adapter_type) {
515 joko 1.19
516 joko 1.1 case 'phpHtmlLib':
517     //$adapter_arguments = $args[title];
518 jonen 1.9 $this->set_adapter_module('DataSource::Adapter::phpHtmlLib::DataSource');
519 joko 1.1
520     // in order to let the Adapter communicate with the Proxy,
521     // instantiate a wrapper method in a third namespace via
522     // Exporter::export_symbol(from, to)
523     $this->set_adapter_options($this);
524 joko 1.19 break;
525 joko 1.1
526 joko 1.19 // NEW [2003-04-17]: Freedom for the adapter!
527     // phpHtmlLib didn't have a tree widget, but PEAR does.
528     // So: Free us from the phpHtmlLib-adapter in this case.
529     case 'free':
530     $this->set_adapter_module('DataSource::Adapter::Free');
531     $this->set_adapter_options($this);
532     break;
533 joko 1.1
534     default:
535 joko 1.19 user_error("DataSource::Generic: no Adapter could be selected: \$locator->_adapter_type='$locator->_adapter_type'");
536 joko 1.1 break;
537     }
538    
539    
540    
541     // --- module instantiation - Proxy and Adapter
542    
543     //user_error("handle proxy here!");
544     //$this->create_proxy();
545    
546     //print Dumper($this);
547    
548     //print "this: " . Dumper($this);
549    
550     // V1:
551     /*
552     $proxy = php::mkComponent($this->_modules[_proxy][_module], $this->_modules[_proxy][_options]);
553     print "proxy: " . Dumper($proxy);
554     //exit;
555     */
556    
557     // V2:
558     /*
559     $resultHandle = mkObject('DesignPattern::RemoteProxy', $cache_key, array( key => 1, command => $command, query => $query, remote => 1, rpcinfo => $rpcinfo, cache => array( db => 0, session => 1 ) ) );
560     $result = $resultHandle->getAttributes();
561     return $result;
562     */
563    
564     // V3:
565     // $this->set_handler( $proxy );
566    
567     // V4: use _component_name & _component_options (proposal from GenericPage)
568     // $this->_component_name = ...
569     // $this->create_handler();
570    
571 joko 1.3
572     /**
573     * <!-- Autodia -->
574     * can do: (this is metadata supplied for Autodia, don't delete!)
575     * $adapter = new DataSource_Adapter_phpHtmlLib_DataListSource()
576     *
577     */
578 joko 1.1
579     // V1:
580     //$this->create_adapter($adapter_module, $this->function, $this->arguments);
581    
582     // V2: FIXME - better use V1?
583     $adapter = php::mkComponent($this->get_adapter_module(), $this->get_adapter_options());
584     $this->set_adapter($adapter);
585    
586    
587    
588    
589     }
590    
591     function make_adapter_transparent() {
592    
593     // ... known from Site::Adapter::php::Class:
594    
595     // At this place the Adapter becomes a Proxy.
596     // This functionality currently correlates to the
597     // name of our ancestor, DesignPattern::AdapterProxy.
598     // FIXME: move this code to its namespace!!!
599     // FIXME: rename to set_proxy...
600    
601     // The reason this has to occour here is required
602     // by the TransparentProxy to actually make the
603     // _handler (_proxy) transparent later....
604     //$this->set_proxy( $this->get_adapter() );
605     }
606    
607     /**
608     * Set the metadata information
609     * (a DataSource::Locator) we will use
610     * to build encapsulated instances
611     * of both a Proxy and an Adapter.
612     *
613     * @param LocatorMetadataHash array -
614     *
615     */
616     function set_metadata( &$locator ) {
617     $this->_locator = &$locator;
618     }
619    
620     function &get_metadata() {
621     return $this->_locator;
622     }
623    
624    
625     /**
626     * Set the query metadata hash we will feed *completely*
627     * to an encapsulated Proxy instance.
628     *
629     * @param QueryDeclaration array -
630     *
631     */
632     function set_query( $query ) {
633     $this->_query = $query;
634     }
635    
636     /**
637     * Issue remote/proxy call
638     * Stolen from Application_AbstractBackend::_remote_method (RefactoringProposal?)
639     * Tweaked a bit: proxy package now taken from $this->_handler_name
640     *
641     * Create a new instance of a proxy and store it for later reuse.
642     * Read the locator metadata hash and create
643     * the proxy handler instance using passed-in name.
644     *
645     * @param string - $proxy_name (namespaced classname - perl syntax - e.g.: Data::Driver::Proxy)
646     *
647     */
648     function datasource_handler_call() {
649    
650    
651     // 1. read args and build cache key
652    
653     $arg_list = func_get_args();
654     $command = array_shift($arg_list);
655     $cache_key = join("-", array(session_id(), $command, join('_', $arg_list) ));
656     //print "cache_key: $cache_key<br>";
657    
658     // FIXME: what if arg_list still contains more elements after doing this?
659     $query = array_shift($arg_list);
660    
661     // 2. prepare proxy-options (read from locator)
662    
663     //print "this: " . Dumper($this);
664     //exit;
665    
666     // read from locator metadata
667     //$proxy_name = $this->_locator[metadata][package];
668    
669     // V1:
670     //$rpcinfo = array( Host => $this->_locator[metadata][Host], Port => $this->_locator[metadata][Port] );
671    
672     // V2:
673     $rpcinfo = $this->_locator->get_metadata();
674    
675     // FIXME! implement this into Data::Driver::RPC::Remote!
676     //$rpcinfo[to_latin] = 1;
677    
678     // FIXME! patch query
679     if (sizeof($query) == 1) {
680     $query = $query[0];
681     }
682    
683     //print "query: " . Dumper($query);
684    
685     // !!! use DesignPattern::Proxy here !!!
686     // $proxy = new DesignPattern_Proxy($proxy_name, ...)
687     // or:
688     // $proxy = mkObject('DesignPattern::Proxy');
689     // $this->set_handler( $proxy );
690     // or:
691     // $proxy = mkObject('DesignPattern::Proxy');
692     // $proxy->
693     // $this->set_handler( $proxy );
694    
695    
696    
697     //$this->set_component_name( $proxy_name );
698     $this->set_component_options( $cache_key, array( key => 1, command => $command, query => $query, remote => 1, rpcinfo => $rpcinfo, cache => array( db => 0, session => 1 ) ) );
699     //print Dumper($this);
700     //exit;
701    
702     $this->create_proxy();
703    
704     //print Dumper($this);
705     //exit;
706    
707     /*
708     // -------------------- clone this & modify ----------
709     $proxy = mkObject($proxy_name, $cache_key, array( key => 1, command => $command, query => $query, remote => 1, rpcinfo => $rpcinfo, cache => array( db => 0, session => 1 ) ) );
710     $this->set_handler( $proxy );
711     //$result = $resultHandle->getAttributes();
712     //return $result;
713     //$this->_result = $resultHandle->getAttributes();
714     //$this->_result = $this->_handler->getAttributes();
715     // -------------------- clone this & modify ----------
716     */
717    
718     }
719    
720    
721     function datasource_handler_buildoptions() {
722    
723     //print Dumper($this->_query);
724     //exit;
725    
726     // make up a command from metadata
727     // FIXME: abstract this some more (e.g. via a CommandMapper|Registry)
728     switch ($this->_query[metatype]) {
729     case 'data':
730 jonen 1.9 $command = 'queryData';
731 jonen 1.13
732 jonen 1.9 //$command = 'getObjects'; // FIXME!!!
733 joko 1.1 //$this->_locator->set_option('metadata.command', $command);
734 jonen 1.9 /*
735 joko 1.1 $args = array();
736     switch ($this->_query[vartype]) {
737 jonen 1.8 case 'objects':
738 joko 1.1 if (!$this->_query[classname]) {
739 jonen 1.8 $msg = "_query[vartype] == 'objects' requires _query[classname]";
740 joko 1.16 user_error("DataSource::Generic: query_data() - failed: " . $msg);
741 joko 1.1 }
742     array_push($args, $this->_query[classname]);
743     break;
744     }
745 jonen 1.9 */
746     $query_args = array();
747 joko 1.19
748     $msg_prefix = "DataSource::Generic::datasource_handler_buildoptions failed: ";
749 jonen 1.9 switch ($this->_query[abstract_type]) {
750 joko 1.19 case 'item':
751 jonen 1.21 if (!$this->_query[nodename] && $this->_query[action] != 'create') {
752 joko 1.19 $msg = "_query[vartype] == 'objects' requires _query[nodename]";
753     user_error($msg_prefix . $msg);
754 jonen 1.21 } elseif($this->_query[action] == 'create' && $this->_query[parent]) {
755     if($this->_query[nodename]) { $query_args[node_class] = $this->_query[nodename]; }
756     if($this->_query['hash_key']) { $query_args['hash_key'] = $this->_query['hash_key']; }
757     $query_args[nodename] = $this->_query[ident];
758     $query_args[parent][guid] = $this->_query[parent][guid];
759     $query_args[parent][nodename] = $this->_query[parent][nodename];
760 jonen 1.26 } elseif($this->_query[parent]) {
761     $query_args[guid] = $this->_query[ident];
762     $query_args[nodename] = $this->_query[nodename];
763     $query_args[parent][guid] = $this->_query[parent][guid];
764     $query_args[parent][nodename] = $this->_query[parent][nodename];
765 jonen 1.21 } else {
766     $query_args[guid] = $this->_query[ident];
767     $query_args[nodename] = $this->_query[nodename];
768 jonen 1.24 // 2003-11-17 NEW: use expand flag for real obj expand at backend
769 jonen 1.25 if ($this->_query[expand]) {$query_args[expand] = 1; }
770 joko 1.19 }
771 jonen 1.26 //print "generic_source->debug: args " . Dumper($query_args) . "<br>";
772 joko 1.19 break;
773 jonen 1.9 case 'list':
774 joko 1.17 if (!$this->_query[nodename]) {
775     $msg = "_query[vartype] == 'objects' requires _query[nodename]";
776 joko 1.19 user_error($msg_prefix . $msg);
777 jonen 1.26 } elseif($this->_query[parent]) {
778     //if($this->_query[nodename]) { $query_args[node_class] = $this->_query[nodename]; }
779     //if($this->_query['hash_key']) { $query_args['hash_key'] = $this->_query['hash_key']; }
780     //$query_args[nodename] = $this->_query[ident];
781     $query_args[parent][guid] = $this->_query[parent][guid];
782     $query_args[parent][nodename] = $this->_query[parent][nodename];
783 jonen 1.9 }
784 joko 1.17 //array_push($query_args, $this->_query[nodename]);
785     $query_args[nodename] = $this->_query[nodename];
786 jonen 1.20 if($this->_query[list_meta]) { $query_args[list_meta] = $this->_query[list_meta]; }
787 jonen 1.9 break;
788 joko 1.19 case 'tree':
789     /*
790 joko 1.17 if (!$this->_query[nodename]) {
791     $msg = "_query[vartype] == 'objects' requires _query[nodename]";
792 joko 1.19 user_error($msg_prefix . $msg);
793 jonen 1.9 }
794 joko 1.19 */
795 jonen 1.9 $query_args[guid] = $this->_query[ident];
796 joko 1.19 //$query_args[nodename] = $this->_query[nodename];
797     break;
798     default:
799     $msg = "\$this->_query[abstract_type] could not be dispatched as 'item', 'list' or 'tree'.";
800     user_error($msg_prefix . $msg);
801     break;
802     }
803    
804     // filter???
805 jonen 1.23 //print "Filter: " . Dumper($this->_query[filter]) . "<br>";
806 joko 1.19 if ($this->_query[filter]) {
807     $query_args[filter] = $this->_query[filter];
808 jonen 1.13 }
809 joko 1.18
810     // dispatch action
811 jonen 1.23 //print "Action: " . $this->_query[action] . "<br>";
812 joko 1.18 if ($this->_query[action] == 'write') {
813 jonen 1.13 $query_args[action] = $this->_query[action];
814     $query_args[data] = $this->_query[data];
815 joko 1.18 } elseif ($this->_query[action] == 'delete') {
816     $query_args[action] = $this->_query[action];
817 jonen 1.21 } elseif ($this->_query[action] == 'create') {
818 jonen 1.26 $query_args[action] = $this->_query[action];
819     } elseif ($this->_query[action] == 'select') {
820 jonen 1.21 $query_args[action] = $this->_query[action];
821 jonen 1.9 }
822 joko 1.19
823 jonen 1.9 $args = array(
824     'data_type' => $this->_query[abstract_type],
825     'query_args' => $query_args
826     );
827     break;
828    
829     // querySchema
830 joko 1.1 case 'schema':
831 jonen 1.9 //print "Testing schema:" . "<br>";
832 joko 1.1 $command = 'querySchema';
833 joko 1.14 $args = array( $this->_query[filter] );
834 joko 1.1 break;
835 joko 1.16
836     // remoteMethod
837     case 'method':
838     $command = $this->_query[method];
839 joko 1.22 //$args = $this->_query[args];
840     // FIX
841     $args = array( $this->_query[args] );
842 joko 1.16 break;
843    
844 joko 1.1 }
845    
846 joko 1.16
847     // FIXME: bad behaviour?
848     if (!is_array($args)) { $args = array( $args ); }
849 joko 1.22
850     //print Dumper($args);
851 joko 1.1
852     /*
853     $this->_query[rpc_command] = $command;
854     $this->_query[rpc_args] = $command;
855     */
856    
857     // methods!!!
858     $this->_locator->_call[_method] = $command;
859     $this->_locator->_call[_arguments] = $args;
860    
861     //$adapter = $this->get_adapter();
862    
863     // trace
864     /*
865     print Dumper(null, '<b>= = = = = = = = = = = = = = = = = = = = = =</b>');
866     print Dumper('datasource_handler_buildoptions', array(
867     "_locator" => $this->_locator,
868     "_query" => $this->_query,
869     "command" => '<b>' . $command . "</b>",
870     "args" => $args
871     ));
872     */
873    
874     /*
875     $this->_handler_options = array(
876     method => $command,
877     args => $args,
878     );
879     */
880    
881     }
882    
883 joko 1.11
884    
885 joko 1.1 function &fetch_result() {
886 joko 1.19
887     //print Dumper($this);
888 joko 1.1
889     $this->datasource_handler_buildoptions();
890    
891 joko 1.11 $call = $this->_locator->get_call();
892 joko 1.19
893 joko 1.11 //print Dumper($call);
894 joko 1.19 //return;
895 joko 1.11
896 joko 1.1 // pre-flight checks
897 joko 1.11 if (!$call[method]) {
898     $msg = "Remote method is empty, please pass in proper metadata or check configuration.";
899 joko 1.16 user_error("DataSource::Generic: query_data() - failed: " . $msg);
900 joko 1.1 return;
901     }
902    
903     //print "fetch_result: this->_handler=" . Dumper($this->_handler);
904    
905     // do remote call here and get result
906     // FIXME: handle synchronous/asynchronous mode here!!!
907 joko 1.11 $this->datasource_handler_call($call[method], $call[args]);
908 joko 1.1
909    
910     // TODO: ... = $this->poll_handler_result and $this->get_handler_result
911     $proxy = $this->get_proxy();
912     $this->_result = $proxy->getResult();
913     //print "result: " . Dumper($this->_result); exit;
914    
915     $this->_result_count = sizeof($this->_result);
916    
917     // trace
918 joko 1.11 //if (constants::get('VERBOSE') && $this->_debug[notice]) {
919 joko 1.12 if (constants::get('VERBOSE') or constants::get('ERRORS_ONLY')) {
920 joko 1.1 //print "_result = " . Dumper($this->_result);
921 joko 1.11 //print "<div><b><font color=\"darkgreen\">Debug:</font></b> DataSource::Generic->_result_count = <b>" . $this->_result_count . "</b></div>";
922     $this->draw_status_box();
923 joko 1.1 }
924 joko 1.11
925 joko 1.1 return $this->_result;
926    
927     }
928    
929 joko 1.11 function draw_status_box() {
930    
931     static $boxcount;
932    
933     $boxcount++;
934    
935 joko 1.12 $box = container();
936    
937 joko 1.11 // box style
938     $style = container(
939     html_style("text/css", '.boxlabel_darkgreen { color: darkgreen; font-weight:bold; }'),
940     html_style("text/css", '.box_dsg { background: #20ab39; color: white; border: 2px black groove; width:640px; padding:10px; margin:40px; }')
941     );
942 joko 1.12 $box->add( $style );
943 joko 1.11
944     // box content
945     $statusbox = html_div('box_dsg');
946     $statusbox->add( html_b("DataSource::Generic"), html_br() );
947     $locatorbox = html_div('box_dsg');
948     $locatorbox->set_id("locatorbox_$boxcount");
949     $locatorbox->add( Dumper($this->_locator) );
950 joko 1.14
951     // FIXME: ie/mozilla?
952 joko 1.15 //$locatorbox->set_style('display:none;');
953     //$locatorbox->set_style('visibility:hidden;');
954     // already duplicate inside Tracer!!!
955     $locatorbox->set_style('visibility:hidden; position:absolute; z-index:1; margin-top:30px; padding:5px;');
956 joko 1.11
957 joko 1.15 $statusbox->add( html_span('boxlabel_darkgreen', "Locator:"), link::js_function( 'toggleVisibility', array("locatorbox_$boxcount"), '[show]'), $locatorbox, html_br() );
958 joko 1.11 $call = $this->_locator->get_call();
959     $statusbox->add( html_span('boxlabel_darkgreen', "Method:"), $call[method], html_br() );
960     if (sizeof($call[args])) {
961     $statusbox->add( html_span('boxlabel_darkgreen', "Arguments:"), Dumper($call[args]), html_br() );
962     }
963     $statusbox->add( html_span('boxlabel_darkgreen', "Count:"), $this->get_result_count(), html_br() );
964 joko 1.12 $box->add( $statusbox );
965    
966 joko 1.14 //print $box->render();
967     trace( $box );
968 joko 1.11
969     }
970    
971 joko 1.1
972     function &query_data() {
973     //print "query!<br/>";
974     return $this->fetch_result();
975     //$this->handle_result();
976     }
977    
978     function query_schema() {
979     user_error("FIXME: query_schema");
980     // $this->datasource_handler_call( ... );
981     }
982    
983     function &get_result() {
984     return $this->_result;
985 joko 1.11 }
986    
987     function get_result_count() {
988     return $this->_result_count;
989 joko 1.1 }
990    
991     }
992    
993     ?>

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