/[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.13 - (hide annotations)
Fri Apr 4 02:37:14 2003 UTC (21 years, 4 months ago) by jonen
Branch: MAIN
Changes since 1.12: +9 -1 lines
_query[action] == write

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

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