17 |
* $Id$ |
* $Id$ |
18 |
* |
* |
19 |
* $Log$ |
* $Log$ |
20 |
|
* Revision 1.3 2003/03/03 21:24:18 joko |
21 |
|
* now based on DesignPattern::RemoteProxy |
22 |
|
* |
23 |
|
* Revision 1.2 2003/03/02 01:05:13 joko |
24 |
|
* - purged old code |
25 |
|
* |
26 |
* Revision 1.1 2003/03/01 21:47:15 joko |
* Revision 1.1 2003/03/01 21:47:15 joko |
27 |
* renamed from AbstractDataSource.inc |
* renamed from AbstractDataSource.inc |
28 |
* |
* |
147 |
*/ |
*/ |
148 |
|
|
149 |
|
|
150 |
class GenericDataSource extends MemoryDataSource { |
//loadModule('DesignPattern::Proxy'); |
151 |
|
loadModule('DesignPattern::RemoteProxy'); |
152 |
|
|
153 |
|
//class GenericDataSource extends MemoryDataSource { |
154 |
|
//class GenericDataSource extends DesignPattern_Proxy { |
155 |
|
class GenericDataSource extends DesignPattern_RemoteProxy { |
156 |
|
|
157 |
/** |
/** |
158 |
* This var holds the locator metadata hash |
* This var holds the locator metadata hash |
173 |
|
|
174 |
|
|
175 |
/** |
/** |
|
* This var holds the Handler object |
|
|
* that is used to do the work. |
|
|
* It acts as a dispatcher combining result caching. |
|
|
* It is assumed that this provides 4 methods: |
|
|
* queryData() - execute a query against a data storage |
|
|
* querySchema() - execute a query against underlying storage metadata |
|
|
* sendCommand() - send a command against an arbitrary execution engine |
|
|
* ... or others! (these are just proposals for convenience) |
|
|
* |
|
|
*/ |
|
|
var $_handler = NULL; |
|
|
|
|
|
|
|
|
/** |
|
|
* This var holds options fed to the Proxy object |
|
|
* These are built from locator metadata (_locator) and query arguments (_query) |
|
|
* It's a simple structured hash: |
|
|
* $proxy_options = array( |
|
|
* method => '<remote-method-name>', |
|
|
* args => array('list', 'of', 'arguments') |
|
|
* ); |
|
|
* |
|
|
*/ |
|
|
var $_handler_options = NULL; |
|
|
|
|
|
|
|
|
/** |
|
176 |
* this holds the query result from the |
* this holds the query result from the |
177 |
* Data::Driver::Proxy->queryXyz() call |
* Data::Driver::Proxy->queryXyz() call |
178 |
* |
* |
179 |
*/ |
*/ |
180 |
var $_result = NULL; |
var $_result = NULL; |
181 |
|
|
|
/** |
|
|
* This holds some information about the tracing level. |
|
|
* |
|
|
*/ |
|
|
var $_debug = array( |
|
|
notice => 0, |
|
|
trace => 0, |
|
|
payload => 0, |
|
|
); |
|
182 |
|
|
183 |
|
|
184 |
/** |
/** |
217 |
} |
} |
218 |
|
|
219 |
/** |
/** |
|
* Directly inject a Data::Driver::Proxy instance to use. |
|
|
* |
|
|
* @param Data::Driver::Proxy object - &$proxy |
|
|
* |
|
|
*/ |
|
|
function set_handler( &$proxy ) { |
|
|
$this->_handler = &$proxy; |
|
|
} |
|
|
|
|
|
/** |
|
220 |
* Issue remote/proxy call |
* Issue remote/proxy call |
221 |
* Stolen from Application_AbstractBackend::_remote_method (RefactoringProposal?) |
* Stolen from Application_AbstractBackend::_remote_method (RefactoringProposal?) |
222 |
* Tweaked a bit: proxy package now taken from $this->_handler_name |
* Tweaked a bit: proxy package now taken from $this->_handler_name |
228 |
* @param string - $proxy_name (namespaced classname - perl syntax - e.g.: Data::Driver::Proxy) |
* @param string - $proxy_name (namespaced classname - perl syntax - e.g.: Data::Driver::Proxy) |
229 |
* |
* |
230 |
*/ |
*/ |
231 |
function do_handler_call() { |
function call_handler() { |
232 |
|
|
233 |
|
|
234 |
// 1. read args |
// 1. read args |
255 |
if (sizeof($query) == 1) { |
if (sizeof($query) == 1) { |
256 |
$query = $query[0]; |
$query = $query[0]; |
257 |
} |
} |
258 |
|
|
259 |
|
// !!! use DesignPattern::Proxy here !!! |
260 |
|
// $proxy = new DesignPattern_Proxy($proxy_name, ...) |
261 |
|
// or: |
262 |
|
// $proxy = mkObject('DesignPattern::Proxy'); |
263 |
|
// $this->set_handler( $proxy ); |
264 |
|
// or: |
265 |
|
// $proxy = mkObject('DesignPattern::Proxy'); |
266 |
|
// $proxy-> |
267 |
|
// $this->set_handler( $proxy ); |
268 |
|
|
269 |
|
$this->set_component_name( $proxy_name ); |
270 |
|
$this->set_component_options( $cache_key, array( key => 1, command => $command, query => $query, remote => 1, rpcinfo => $rpcinfo, cache => array( db => 0, session => 1 ) ) ); |
271 |
|
|
272 |
|
$this->create_handler(); |
273 |
|
|
274 |
|
/* |
275 |
// -------------------- clone this & modify ---------- |
// -------------------- clone this & modify ---------- |
276 |
$proxy = mkObject($proxy_name, $cache_key, array( key => 1, command => $command, query => $query, remote => 1, rpcinfo => $rpcinfo, cache => array( db => 0, session => 1 ) ) ); |
$proxy = mkObject($proxy_name, $cache_key, array( key => 1, command => $command, query => $query, remote => 1, rpcinfo => $rpcinfo, cache => array( db => 0, session => 1 ) ) ); |
277 |
$this->set_handler( $proxy ); |
$this->set_handler( $proxy ); |
280 |
//$this->_result = $resultHandle->getAttributes(); |
//$this->_result = $resultHandle->getAttributes(); |
281 |
//$this->_result = $this->_handler->getAttributes(); |
//$this->_result = $this->_handler->getAttributes(); |
282 |
// -------------------- clone this & modify ---------- |
// -------------------- clone this & modify ---------- |
283 |
|
*/ |
284 |
|
|
285 |
} |
} |
286 |
|
|
|
function O_do_query() { |
|
|
$this->_result = $this->_db->query($this->_query); |
|
|
if (DB::isError($this->_result)) { |
|
|
$msg = $this->_result->getMessage(); |
|
|
user_error("PEARSQLDataListSource::do_query() - query failed : ".$msg); |
|
|
} |
|
|
} |
|
287 |
|
|
288 |
function build_handler_options() { |
function build_handler_options() { |
289 |
|
|
343 |
|
|
344 |
// do remote call here and get result |
// do remote call here and get result |
345 |
// FIXME: handle synchronous/asynchronous mode here!!! |
// FIXME: handle synchronous/asynchronous mode here!!! |
346 |
$this->do_handler_call($method, $args); |
$this->call_handler($method, $args); |
347 |
// TODO: ... = $this->poll_handler_result and $this->get_handler_result |
// TODO: ... = $this->poll_handler_result and $this->get_handler_result |
348 |
$this->_result = $this->_handler->getAttributes(); |
$this->_result = $this->_handler->getAttributes(); |
349 |
|
|
361 |
$this->fetch_result(); |
$this->fetch_result(); |
362 |
$this->handle_result(); |
$this->handle_result(); |
363 |
} |
} |
364 |
|
|
365 |
|
function do_query_schema() { |
366 |
|
user_error("FIXME: do_query_schema"); |
367 |
|
// $this->call_handler( ... ); |
368 |
|
} |
369 |
|
|
370 |
function get_header() { |
function get_header() { |
371 |
$this->fetch_result(); |
$this->fetch_result(); |
374 |
} |
} |
375 |
|
|
376 |
|
|
|
function O_do_prequery() { |
|
|
//print "prequery!<br/>"; |
|
|
// HACK!!! |
|
|
// modify behaviour here: for now it is needed to call for the schem |
|
|
// eventually modify here to get schema from some registry component (already locally available) |
|
|
$this->fetch_result(); |
|
|
//print Dumper($this->_result); |
|
|
//print Dumper($this->_result[0]); |
|
|
//exit; |
|
|
|
|
|
//$this->_get_header(); |
|
|
} |
|
377 |
|
|
|
|
|
|
function O_get_header() { |
|
|
//$this->do_prequery(); |
|
|
// FIXME: prevent multi-calls by base class |
|
|
$this->fetch_result(); |
|
|
foreach($this->_result[0] as $key => $value) { |
|
|
array_push($this->_data_keys, $key); |
|
|
} |
|
|
|
|
|
$this->set_schema($this->_result[0]); |
|
|
|
|
|
//$this->_get_header(); |
|
|
//return $this->_data_keys; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
* This function gets the next data row |
|
|
* from the query() |
|
|
* |
|
|
* @return array() |
|
|
*/ |
|
|
function O_get_next_data_row() { |
|
|
return $this->_result->fetchRow(DB_FETCHMODE_ASSOC); |
|
|
} |
|
|
|
|
|
/** |
|
|
* This function builds the limit |
|
|
* clause portion of a DB query. |
|
|
* |
|
|
* @return string - the limit portion of |
|
|
* the query. |
|
|
*/ |
|
|
function O_build_limit_clause($offset, $limit) { |
|
|
if ($this->get_limit() != -1 ) { |
|
|
if ($offset == '' || $offset == "none") { |
|
|
$offset = 0; |
|
|
} |
|
|
switch(get_class($this->_db)) { |
|
|
case "db_mysql": |
|
|
$clause = " LIMIT $offset, $limit "; |
|
|
break; |
|
|
case "db_pgsql": |
|
|
$clause = " LIMIT $limit, $offset "; |
|
|
break; |
|
|
default: |
|
|
$clause = " LIMIT $offset, $limit "; |
|
|
break; |
|
|
} |
|
|
return $clause; |
|
|
} else { |
|
|
return NULL; |
|
|
} |
|
|
} |
|
|
|
|
|
/** |
|
|
* find the number of rows to be returned |
|
|
* from a query from a table and where clause |
|
|
* |
|
|
* @param string $table - the table to count from |
|
|
* @param string $where_clause - a where clause |
|
|
* |
|
|
* @return int the # of rows |
|
|
*/ |
|
|
function O_count($tables, $where_clause='', $count_clause='*') { |
|
|
$query = "select count(".$count_clause.") as COUNT from ".$tables." ".$where_clause; |
|
|
$result = $this->_db->query($query); |
|
|
if (DB::isError($this->_result)) { |
|
|
$msg = $result->getMessage(); |
|
|
user_error("PEARSQLDataListSource::count() - query failed : ".$msg); |
|
|
} |
|
|
$value = $result->fetchRow(DB_FETCHMODE_ASSOC); |
|
|
return ($value ? (int)$value["COUNT"] : NULL); |
|
|
} |
|
378 |
|
|
379 |
} |
} |
380 |
|
|