/[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.27 - (hide annotations)
Tue Jun 15 12:50:48 2004 UTC (20 years, 2 months ago) by joko
Branch: MAIN
Changes since 1.26: +5 -2 lines
disabled caching in "datasource_handler_call"

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

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