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