From e2cb1585f629984febbc03df30df0e0901c52e26 Mon Sep 17 00:00:00 2001 From: zYne Date: Thu, 1 Feb 2007 08:57:56 +0000 Subject: [PATCH] db eventlisteners updated --- lib/Doctrine/Db/Cache.php | 44 +++------------------ lib/Doctrine/Db/EventListener.php | 10 +++++ lib/Doctrine/Db/EventListener/Chain.php | 25 ++++++++++++ lib/Doctrine/Db/EventListener/Interface.php | 6 +++ lib/Doctrine/Db/Statement.php | 24 +---------- 5 files changed, 47 insertions(+), 62 deletions(-) diff --git a/lib/Doctrine/Db/Cache.php b/lib/Doctrine/Db/Cache.php index 4929631a9..8d11488a5 100644 --- a/lib/Doctrine/Db/Cache.php +++ b/lib/Doctrine/Db/Cache.php @@ -18,6 +18,7 @@ * and is licensed under the LGPL. For more information, see * . */ +Doctrine::autoload('Doctrine_Db_EventListener'); /** * Doctrine_Db_Cache * @@ -32,48 +33,13 @@ */ class Doctrine_Db_Cache extends Doctrine_Db_EventListener { + + protected $cache; - public function __construct($cacheDriver) + public function __construct(Doctrine_Cache $cache) { - - } - public function onPreQuery(Doctrine_Db_Event $event) - { - $query = $event->getQuery(); - - $this->cache->process($query); - } - public function onQuery(Doctrine_Db_Event $event) - { - + $this->cache = $cache; } - public function onPrePrepare(Doctrine_Db_Event $event) - { - } - public function onPrepare(Doctrine_Db_Event $event) - { - - } - - public function onPreExec(Doctrine_Db_Event $event) - { - - } - public function onExec(Doctrine_Db_Event $event) - { - - } - - public function onPreExecute(Doctrine_Db_Event $event) - { - $query = $event->getQuery(); - - $this->cache->process($query); - } - public function onExecute(Doctrine_Db_Event $event) - { - - } } diff --git a/lib/Doctrine/Db/EventListener.php b/lib/Doctrine/Db/EventListener.php index 4456a6a53..34b5e3121 100644 --- a/lib/Doctrine/Db/EventListener.php +++ b/lib/Doctrine/Db/EventListener.php @@ -55,6 +55,16 @@ class Doctrine_Db_EventListener implements Doctrine_Db_EventListener_Interface { } public function onExec(Doctrine_Db_Event $event) { } + + public function onPreFetch(Doctrine_Db_Event $event) + { } + public function onFetch(Doctrine_Db_Event $event) + { } + + public function onPreFetchAll(Doctrine_Db_Event $event) + { } + public function onFetchAll(Doctrine_Db_Event $event) + { } public function onPreRollBack(Doctrine_Db_Event $event) { } diff --git a/lib/Doctrine/Db/EventListener/Chain.php b/lib/Doctrine/Db/EventListener/Chain.php index 11c0ae7e0..db0c85e20 100644 --- a/lib/Doctrine/Db/EventListener/Chain.php +++ b/lib/Doctrine/Db/EventListener/Chain.php @@ -130,6 +130,31 @@ class Doctrine_Db_EventListener_Chain extends Doctrine_Access implements Doctrin $listener->onCommit($event); } } + public function onPreFetch(Doctrine_Db_Event $event) + { + foreach ($this->listeners as $listener) { + $listener->onPreFetch($event); + } + } + public function onFetch(Doctrine_Db_Event $event) + { + foreach ($this->listeners as $listener) { + $listener->onFetch($event); + } + } + + public function onPreFetchAll(Doctrine_Db_Event $event) + { + foreach ($this->listeners as $listener) { + $listener->onPreFetchAll($event); + } + } + public function onFetchAll(Doctrine_Db_Event $event) + { + foreach ($this->listeners as $listener) { + $listener->onFetchAll($event); + } + } public function onPreRollBack(Doctrine_Db_Event $event) { diff --git a/lib/Doctrine/Db/EventListener/Interface.php b/lib/Doctrine/Db/EventListener/Interface.php index 98cc5c1e7..a10bd3457 100644 --- a/lib/Doctrine/Db/EventListener/Interface.php +++ b/lib/Doctrine/Db/EventListener/Interface.php @@ -38,6 +38,12 @@ interface Doctrine_Db_EventListener_Interface { public function onPreExec(Doctrine_Db_Event $event); public function onExec(Doctrine_Db_Event $event); + public function onPreFetch(Doctrine_Db_Event $event); + public function onFetch(Doctrine_Db_Event $event); + + public function onPreFetchAll(Doctrine_Db_Event $event); + public function onFetchAll(Doctrine_Db_Event $event); + public function onPreCommit(Doctrine_Db_Event $event); public function onCommit(Doctrine_Db_Event $event); diff --git a/lib/Doctrine/Db/Statement.php b/lib/Doctrine/Db/Statement.php index edd6f867b..d5794b04d 100644 --- a/lib/Doctrine/Db/Statement.php +++ b/lib/Doctrine/Db/Statement.php @@ -29,42 +29,20 @@ * @since 1.0 * @version $Revision$ */ -class Doctrine_Db_Statement extends PDOStatement +class Doctrine_Db_Statement implements Doctrine_Adapter_Statement_Interface { protected $dbh; - protected $querySequence; - - protected $baseSequence; - protected $executed = false; protected function __construct($dbh) { $this->dbh = $dbh; - $this->baseSequence = $this->querySequence = $this->dbh->getQuerySequence(); - } - - public function getQuerySequence() - { - return $this->querySequence; - } - public function getBaseSequence() - { - return $this->baseSequence; } public function getQuery() { return $this->queryString; } - public function isExecuted($executed = null) - { - if ($executed === null) - return $this->executed; - - $this->executed = (bool) $executed; - } - public function execute(array $params = null) { $event = new Doctrine_Db_Event($this, Doctrine_Db_Event::EXECUTE, $this->queryString, $params);