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