Commit 09ca6e46 authored by doctrine's avatar doctrine

New component Doctrine_Query (replaces Doctrine_DQL_Parser)

parent d07dfbd7
...@@ -365,16 +365,16 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator ...@@ -365,16 +365,16 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
return true; return true;
} }
/** /**
* @param Doctrine_DQL_Parser $graph * @param Doctrine_Query $query
* @param integer $key * @param integer $key
*/ */
public function populate(Doctrine_DQL_Parser $graph) { public function populate(Doctrine_Query $query) {
$name = $this->table->getComponentName(); $name = $this->table->getComponentName();
if($this instanceof Doctrine_Collection_Immediate || if($this instanceof Doctrine_Collection_Immediate ||
$this instanceof Doctrine_Collection_Offset) { $this instanceof Doctrine_Collection_Offset) {
$data = $graph->getData($name); $data = $query->getData($name);
if(is_array($data)) { if(is_array($data)) {
foreach($data as $k=>$v): foreach($data as $k=>$v):
$this->table->setData($v); $this->table->setData($v);
...@@ -382,7 +382,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator ...@@ -382,7 +382,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
endforeach; endforeach;
} }
} elseif($this instanceof Doctrine_Collection_Batch) { } elseif($this instanceof Doctrine_Collection_Batch) {
$this->data = $graph->getData($name); $this->data = $query->getData($name);
if(isset($this->generator)) { if(isset($this->generator)) {
foreach($this->data as $k => $v) { foreach($this->data as $k => $v) {
......
...@@ -16,15 +16,15 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera ...@@ -16,15 +16,15 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
*/ */
private $sessions = array(); private $sessions = array();
/** /**
* @var integer $index * @var integer $index the incremented index
*/ */
private $index = 0; private $index = 0;
/** /**
* @var integer $currIndex * @var integer $currIndex the current session index
*/ */
private $currIndex = 0; private $currIndex = 0;
/** /**
* @var string $root * @var string $root root directory
*/ */
private $root; private $root;
...@@ -36,6 +36,9 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera ...@@ -36,6 +36,9 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
} }
/** /**
* setDefaultAttributes * setDefaultAttributes
* sets default attributes
*
* @return boolean
*/ */
final public function setDefaultAttributes() { final public function setDefaultAttributes() {
static $init = false; static $init = false;
...@@ -61,7 +64,9 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera ...@@ -61,7 +64,9 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
if($old === null) if($old === null)
$this->setAttribute($attribute,$value); $this->setAttribute($attribute,$value);
} }
return true;
} }
return false;
} }
/** /**
* returns the root directory of Doctrine * returns the root directory of Doctrine
...@@ -78,7 +83,7 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera ...@@ -78,7 +83,7 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
final public static function getInstance() { final public static function getInstance() {
static $instance; static $instance;
if( ! isset($instance)) if( ! isset($instance))
$instance = new Doctrine_Manager(); $instance = new self();
return $instance; return $instance;
} }
...@@ -157,6 +162,8 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera ...@@ -157,6 +162,8 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
} }
/** /**
* getSessions * getSessions
* returns all opened sessions
*
* @return array * @return array
*/ */
final public function getSessions() { final public function getSessions() {
...@@ -177,14 +184,17 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera ...@@ -177,14 +184,17 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
} }
/** /**
* count * count
* @return integer the number of open sessions * returns the number of opened sessions
*
* @return integer
*/ */
public function count() { public function count() {
return count($this->sessions); return count($this->sessions);
} }
/** /**
* getIterator * getIterator
* returns an ArrayIterator that iterates through open sessions * returns an ArrayIterator that iterates through all sessions
*
* @return ArrayIterator * @return ArrayIterator
*/ */
public function getIterator() { public function getIterator() {
...@@ -193,6 +203,7 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera ...@@ -193,6 +203,7 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
/** /**
* getCurrentSession * getCurrentSession
* returns the current session * returns the current session
*
* @throws Doctrine_Session_Exception if there are no open sessions * @throws Doctrine_Session_Exception if there are no open sessions
* @return Doctrine_Session * @return Doctrine_Session
*/ */
......
...@@ -372,11 +372,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite ...@@ -372,11 +372,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
if(is_array($this->data[$name])) { if(is_array($this->data[$name])) {
// no use trying to load the data from database if the Doctrine_Record is not a proxy // no use trying to load the data from database if the Doctrine_Record is not a proxy
if($this->state != Doctrine_Record::STATE_TDIRTY && if($this->state == Doctrine_Record::STATE_PROXY) {
$this->state != Doctrine_Record::STATE_TCLEAN &&
$this->state != Doctrine_Record::STATE_CLEAN &&
$this->state != Doctrine_Record::STATE_DIRTY) {
if( ! empty($this->collections)) { if( ! empty($this->collections)) {
foreach($this->collections as $collection) { foreach($this->collections as $collection) {
$collection->load($this); $collection->load($this);
...@@ -501,7 +497,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite ...@@ -501,7 +497,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
endswitch; endswitch;
} elseif($fk instanceof Doctrine_Association) { } elseif($fk instanceof Doctrine_Association) {
// many-to-many relation found // join table relation found
if( ! ($value instanceof Doctrine_Collection)) if( ! ($value instanceof Doctrine_Collection))
throw new Doctrine_Exception("Couldn't call Doctrine::set(), second argument should be an instance of Doctrine_Collection when setting one-to-many references."); throw new Doctrine_Exception("Couldn't call Doctrine::set(), second argument should be an instance of Doctrine_Collection when setting one-to-many references.");
} }
...@@ -822,7 +818,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite ...@@ -822,7 +818,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
$name = $table->getComponentName(); $name = $table->getComponentName();
$local = $fk->getLocal(); $local = $fk->getLocal();
$foreign = $fk->getForeign(); $foreign = $fk->getForeign();
$graph = $table->getDQLParser(); $graph = $table->getQueryObject();
$type = $fk->getType(); $type = $fk->getType();
switch($this->getState()): switch($this->getState()):
...@@ -896,12 +892,10 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite ...@@ -896,12 +892,10 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
$this->originals[$name] = clone $coll; $this->originals[$name] = clone $coll;
} elseif($fk instanceof Doctrine_Association) { } elseif($fk instanceof Doctrine_Association) {
$asf = $fk->getAssociationFactory(); $asf = $fk->getAssociationFactory();
$query = "SELECT ".$foreign." FROM ".$asf->getTableName()." WHERE ".$local." = ?"; $query = "SELECT ".$foreign." FROM ".$asf->getTableName()." WHERE ".$local." = ?";
$graph = new Doctrine_DQL_Parser($table->getSession()); $graph = new Doctrine_Query($table->getSession());
$query = "FROM ".$table->getComponentName()." WHERE ".$table->getComponentName().".".$table->getIdentifier()." IN ($query)"; $query = "FROM ".$table->getComponentName()." WHERE ".$table->getComponentName().".".$table->getIdentifier()." IN ($query)";
$coll = $graph->query($query, array($this->getID())); $coll = $graph->query($query, array($this->getID()));
......
...@@ -2,7 +2,8 @@ ...@@ -2,7 +2,8 @@
require_once("Configurable.class.php"); require_once("Configurable.class.php");
require_once("Record.class.php"); require_once("Record.class.php");
/** /**
* @author Konsta Vesterinen * Doctrine_Session
*
* @package Doctrine ORM * @package Doctrine ORM
* @url www.phpdoctrine.com * @url www.phpdoctrine.com
* @license LGPL * @license LGPL
...@@ -103,19 +104,26 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab ...@@ -103,19 +104,26 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab
return $this->cacheHandler; return $this->cacheHandler;
} }
/** /**
* returns the state of this session
*
* @see Doctrine_Session::STATE_* constants
* @return integer the session state * @return integer the session state
*/ */
public function getState() { public function getState() {
return $this->state; return $this->state;
} }
/** /**
* returns the manager that created this session
*
* @return Doctrine_Manager * @return Doctrine_Manager
*/ */
public function getManager() { public function getManager() {
return $this->getParent(); return $this->getParent();
} }
/** /**
* @return object PDO the database handle * returns the database handler of which this session uses
*
* @return object PDO the database handler
*/ */
public function getDBH() { public function getDBH() {
return $this->dbh; return $this->dbh;
...@@ -125,7 +133,7 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab ...@@ -125,7 +133,7 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab
* queries the database with Doctrine Query Language * queries the database with Doctrine Query Language
*/ */
final public function query($query,array $params = array()) { final public function query($query,array $params = array()) {
$parser = new Doctrine_DQL_Parser($this); $parser = new Doctrine_Query($this);
return $parser->query($query, $params); return $parser->query($query, $params);
} }
...@@ -145,7 +153,10 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab ...@@ -145,7 +153,10 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab
return $this->dbh->query($query); return $this->dbh->query($query);
} }
/** /**
* @return object PDOStatement -- the PDOStatement object * @param string $query sql query
* @param array $params query parameters
*
* @return PDOStatement
*/ */
public function execute($query, array $params = array()) { public function execute($query, array $params = array()) {
if( ! empty($params)) { if( ! empty($params)) {
...@@ -157,7 +168,9 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab ...@@ -157,7 +168,9 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab
} }
} }
/** /**
* @param $mixed -- Doctrine_Table name * whether or not this session has table $name initialized
*
* @param $mixed $name
* @return boolean * @return boolean
*/ */
public function hasTable($name) { public function hasTable($name) {
......
...@@ -3,12 +3,12 @@ ...@@ -3,12 +3,12 @@
* standard session, the parent of pgsql, mysql and sqlite * standard session, the parent of pgsql, mysql and sqlite
*/ */
class Doctrine_Session_Common extends Doctrine_Session { class Doctrine_Session_Common extends Doctrine_Session {
public function modifyLimitQuery($query,$limit = null,$offset = null) { public function modifyLimitQuery($query,$limit = false,$offset = false) {
if(isset($limit) && isset($offset)) { if($limit && $offset) {
$query .= " LIMIT ".$limit." OFFSET ".$offset; $query .= " LIMIT ".$limit." OFFSET ".$offset;
} elseif(isset($limit) && ! isset($offset)) { } elseif($limit && ! $offset) {
$query .= " LIMIT ".$limit; $query .= " LIMIT ".$limit;
} elseif( ! isset($limit) && isset($offset)) { } elseif( ! $limit && $offset) {
$query .= " LIMIT 999999999999 OFFSET ".$offset; $query .= " LIMIT 999999999999 OFFSET ".$offset;
} }
......
...@@ -68,7 +68,7 @@ class Doctrine_Table extends Doctrine_Configurable { ...@@ -68,7 +68,7 @@ class Doctrine_Table extends Doctrine_Configurable {
*/ */
private $cache; private $cache;
/** /**
* @var Doctrine_Table_Description $description columns object for this table * @var array $columns an array of column definitions
*/ */
private $columns; private $columns;
/** /**
...@@ -96,8 +96,6 @@ class Doctrine_Table extends Doctrine_Configurable { ...@@ -96,8 +96,6 @@ class Doctrine_Table extends Doctrine_Configurable {
$this->setParent($this->session); $this->setParent($this->session);
$name = ucwords(strtolower($name));
$this->name = $name; $this->name = $name;
if( ! class_exists($name) || empty($name)) if( ! class_exists($name) || empty($name))
...@@ -340,12 +338,12 @@ class Doctrine_Table extends Doctrine_Configurable { ...@@ -340,12 +338,12 @@ class Doctrine_Table extends Doctrine_Configurable {
} }
/** /**
* @param string $objTableName * @param string $objTableName
* @param string $fkField * @param string $field
* @return void * @return void
*/ */
final public function bind($objTableName,$fkField,$type,$localKey) { final public function bind($objTableName,$field,$type,$localKey) {
$name = (string) $objTableName; $name = (string) $objTableName;
$field = (string) $fkField; $field = (string) $field;
if(isset($this->foreignKeys[$name])) if(isset($this->foreignKeys[$name]))
throw new InvalidKeyException(); throw new InvalidKeyException();
...@@ -387,7 +385,7 @@ class Doctrine_Table extends Doctrine_Configurable { ...@@ -387,7 +385,7 @@ class Doctrine_Table extends Doctrine_Configurable {
} }
/** /**
* @param string $name component name of which a foreign key object is bound * @param string $name component name of which a foreign key object is bound
* @return Doctrine_ForeignKey * @return Doctrine_Relation
*/ */
final public function getForeignKey($name) { final public function getForeignKey($name) {
if(isset($this->foreignKeys[$name])) if(isset($this->foreignKeys[$name]))
...@@ -540,7 +538,7 @@ class Doctrine_Table extends Doctrine_Configurable { ...@@ -540,7 +538,7 @@ class Doctrine_Table extends Doctrine_Configurable {
* @return Doctrine_Collection a collection of all data access objects * @return Doctrine_Collection a collection of all data access objects
*/ */
public function findAll() { public function findAll() {
$graph = new Doctrine_DQL_Parser($this->session); $graph = new Doctrine_Query($this->session);
$users = $graph->query("FROM ".$this->name); $users = $graph->query("FROM ".$this->name);
return $users; return $users;
} }
...@@ -549,7 +547,7 @@ class Doctrine_Table extends Doctrine_Configurable { ...@@ -549,7 +547,7 @@ class Doctrine_Table extends Doctrine_Configurable {
* @return Doctrine_Collection a collection of data access objects * @return Doctrine_Collection a collection of data access objects
*/ */
public function findBySql($sql, array $params = array()) { public function findBySql($sql, array $params = array()) {
$graph = new Doctrine_DQL_Parser($this->session); $graph = new Doctrine_Query($this->session);
$users = $graph->query("FROM ".$this->name." WHERE ".$sql, $params); $users = $graph->query("FROM ".$this->name." WHERE ".$sql, $params);
return $users; return $users;
} }
...@@ -587,16 +585,19 @@ class Doctrine_Table extends Doctrine_Configurable { ...@@ -587,16 +585,19 @@ class Doctrine_Table extends Doctrine_Configurable {
return $this->columns; return $this->columns;
} }
/** /**
* @param integer $fetchMode * @return Doctrine_Query a Doctrine_Query object
* @return Doctrine_DQL_Parser a Doctrine_DQL_Parser object
*/ */
public function getDQLParser() { public function getQueryObject() {
$graph = new Doctrine_DQL_Parser($this->getSession()); $graph = new Doctrine_Query($this->getSession());
$graph->load($this->getComponentName()); $graph->load($this->getComponentName());
return $graph; return $graph;
} }
/** /**
* execute * execute
* @param string $query
* @param array $array
* @param integer $limit
* @param integer $offset
*/ */
public function execute($query, array $array = array(), $limit = null, $offset = null) { public function execute($query, array $array = array(), $limit = null, $offset = null) {
$coll = new Doctrine_Collection($this); $coll = new Doctrine_Collection($this);
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
require_once("UnitTestCase.class.php"); require_once("UnitTestCase.class.php");
class Doctrine_BatchIteratorTestCase extends Doctrine_UnitTestCase { class Doctrine_BatchIteratorTestCase extends Doctrine_UnitTestCase {
public function testIterator() { public function testIterator() {
$graph = new Doctrine_DQL_Parser($this->session); $graph = new Doctrine_Query($this->session);
$entities = $graph->query("FROM Entity"); $entities = $graph->query("FROM Entity");
$i = 0; $i = 0;
foreach($entities as $entity) { foreach($entities as $entity) {
......
...@@ -16,6 +16,7 @@ require_once("CollectionTestCase.class.php"); ...@@ -16,6 +16,7 @@ require_once("CollectionTestCase.class.php");
require_once("CacheSqliteTestCase.class.php"); require_once("CacheSqliteTestCase.class.php");
require_once("CollectionOffsetTestCase.class.php"); require_once("CollectionOffsetTestCase.class.php");
require_once("SenseiTestCase.class.php"); require_once("SenseiTestCase.class.php");
require_once("QueryTestCase.class.php");
print "<pre>"; print "<pre>";
...@@ -33,35 +34,27 @@ $test->addTestCase(new Doctrine_TableTestCase()); ...@@ -33,35 +34,27 @@ $test->addTestCase(new Doctrine_TableTestCase());
$test->addTestCase(new Doctrine_SessionTestCase()); $test->addTestCase(new Doctrine_SessionTestCase());
$test->addTestCase(new Doctrine_DQL_ParserTestCase()); //$test->addTestCase(new Doctrine_DQL_ParserTestCase());
$test->addTestCase(new Doctrine_ValidatorTestCase()); $test->addTestCase(new Doctrine_ValidatorTestCase());
$test->addTestCase(new Doctrine_ManagerTestCase()); $test->addTestCase(new Doctrine_ManagerTestCase());
$test->addTestCase(new Doctrine_AccessTestCase()); $test->addTestCase(new Doctrine_AccessTestCase());
$test->addTestCase(new Doctrine_EventListenerTestCase()); $test->addTestCase(new Doctrine_EventListenerTestCase());
$test->addTestCase(new Doctrine_BatchIteratorTestCase()); $test->addTestCase(new Doctrine_BatchIteratorTestCase());
$test->addTestCase(new Doctrine_ConfigurableTestCase()); $test->addTestCase(new Doctrine_ConfigurableTestCase());
$test->addTestCase(new Doctrine_CollectionTestCase()); $test->addTestCase(new Doctrine_CollectionTestCase());
$test->addTestCase(new Doctrine_Collection_OffsetTestCase()); $test->addTestCase(new Doctrine_Collection_OffsetTestCase());
$test->addTestCase(new Sensei_UnitTestCase()); $test->addTestCase(new Sensei_UnitTestCase());
$test->addTestCase(new Doctrine_QueryTestCase());
//$test->addTestCase(new Doctrine_Cache_FileTestCase()); //$test->addTestCase(new Doctrine_Cache_FileTestCase());
//$test->addTestCase(new Doctrine_Cache_SqliteTestCase()); //$test->addTestCase(new Doctrine_Cache_SqliteTestCase());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment