New component Doctrine_Query (replaces Doctrine_DQL_Parser)
This commit is contained in:
parent
d07dfbd7dd
commit
09ca6e464b
@ -365,16 +365,16 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* @param Doctrine_DQL_Parser $graph
|
||||
* @param Doctrine_Query $query
|
||||
* @param integer $key
|
||||
*/
|
||||
public function populate(Doctrine_DQL_Parser $graph) {
|
||||
public function populate(Doctrine_Query $query) {
|
||||
$name = $this->table->getComponentName();
|
||||
|
||||
if($this instanceof Doctrine_Collection_Immediate ||
|
||||
$this instanceof Doctrine_Collection_Offset) {
|
||||
|
||||
$data = $graph->getData($name);
|
||||
$data = $query->getData($name);
|
||||
if(is_array($data)) {
|
||||
foreach($data as $k=>$v):
|
||||
$this->table->setData($v);
|
||||
@ -382,7 +382,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
|
||||
endforeach;
|
||||
}
|
||||
} elseif($this instanceof Doctrine_Collection_Batch) {
|
||||
$this->data = $graph->getData($name);
|
||||
$this->data = $query->getData($name);
|
||||
|
||||
if(isset($this->generator)) {
|
||||
foreach($this->data as $k => $v) {
|
||||
|
@ -12,19 +12,19 @@ require_once("EventListener.class.php");
|
||||
*/
|
||||
class Doctrine_Manager extends Doctrine_Configurable implements Countable, IteratorAggregate {
|
||||
/**
|
||||
* @var array $session an array containing all the opened sessions
|
||||
* @var array $session an array containing all the opened sessions
|
||||
*/
|
||||
private $sessions = array();
|
||||
/**
|
||||
* @var integer $index
|
||||
* @var integer $index the incremented index
|
||||
*/
|
||||
private $index = 0;
|
||||
/**
|
||||
* @var integer $currIndex
|
||||
* @var integer $currIndex the current session index
|
||||
*/
|
||||
private $currIndex = 0;
|
||||
/**
|
||||
* @var string $root
|
||||
* @var string $root root directory
|
||||
*/
|
||||
private $root;
|
||||
|
||||
@ -36,6 +36,9 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
|
||||
}
|
||||
/**
|
||||
* setDefaultAttributes
|
||||
* sets default attributes
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
final public function setDefaultAttributes() {
|
||||
static $init = false;
|
||||
@ -61,7 +64,9 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
|
||||
if($old === null)
|
||||
$this->setAttribute($attribute,$value);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* returns the root directory of Doctrine
|
||||
@ -78,7 +83,7 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
|
||||
final public static function getInstance() {
|
||||
static $instance;
|
||||
if( ! isset($instance))
|
||||
$instance = new Doctrine_Manager();
|
||||
$instance = new self();
|
||||
|
||||
return $instance;
|
||||
}
|
||||
@ -157,6 +162,8 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
|
||||
}
|
||||
/**
|
||||
* getSessions
|
||||
* returns all opened sessions
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
final public function getSessions() {
|
||||
@ -177,14 +184,17 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
|
||||
}
|
||||
/**
|
||||
* count
|
||||
* @return integer the number of open sessions
|
||||
* returns the number of opened sessions
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function count() {
|
||||
return count($this->sessions);
|
||||
}
|
||||
/**
|
||||
* getIterator
|
||||
* returns an ArrayIterator that iterates through open sessions
|
||||
* returns an ArrayIterator that iterates through all sessions
|
||||
*
|
||||
* @return ArrayIterator
|
||||
*/
|
||||
public function getIterator() {
|
||||
@ -193,6 +203,7 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
|
||||
/**
|
||||
* getCurrentSession
|
||||
* returns the current session
|
||||
*
|
||||
* @throws Doctrine_Session_Exception if there are no open sessions
|
||||
* @return Doctrine_Session
|
||||
*/
|
||||
|
@ -372,11 +372,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
if(is_array($this->data[$name])) {
|
||||
|
||||
// no use trying to load the data from database if the Doctrine_Record is not a proxy
|
||||
if($this->state != Doctrine_Record::STATE_TDIRTY &&
|
||||
$this->state != Doctrine_Record::STATE_TCLEAN &&
|
||||
$this->state != Doctrine_Record::STATE_CLEAN &&
|
||||
$this->state != Doctrine_Record::STATE_DIRTY) {
|
||||
|
||||
if($this->state == Doctrine_Record::STATE_PROXY) {
|
||||
if( ! empty($this->collections)) {
|
||||
foreach($this->collections as $collection) {
|
||||
$collection->load($this);
|
||||
@ -501,7 +497,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
endswitch;
|
||||
|
||||
} elseif($fk instanceof Doctrine_Association) {
|
||||
// many-to-many relation found
|
||||
// join table relation found
|
||||
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.");
|
||||
}
|
||||
@ -822,7 +818,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
$name = $table->getComponentName();
|
||||
$local = $fk->getLocal();
|
||||
$foreign = $fk->getForeign();
|
||||
$graph = $table->getDQLParser();
|
||||
$graph = $table->getQueryObject();
|
||||
$type = $fk->getType();
|
||||
|
||||
switch($this->getState()):
|
||||
@ -895,20 +891,18 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
|
||||
$this->originals[$name] = clone $coll;
|
||||
|
||||
} elseif($fk instanceof Doctrine_Association) {
|
||||
|
||||
|
||||
} elseif($fk instanceof Doctrine_Association) {
|
||||
$asf = $fk->getAssociationFactory();
|
||||
$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)";
|
||||
|
||||
$coll = $graph->query($query, array($this->getID()));
|
||||
|
||||
$this->references[$name] = $coll;
|
||||
$this->originals[$name] = clone $coll;
|
||||
|
||||
|
||||
}
|
||||
endswitch;
|
||||
break;
|
||||
|
@ -2,7 +2,8 @@
|
||||
require_once("Configurable.class.php");
|
||||
require_once("Record.class.php");
|
||||
/**
|
||||
* @author Konsta Vesterinen
|
||||
* Doctrine_Session
|
||||
*
|
||||
* @package Doctrine ORM
|
||||
* @url www.phpdoctrine.com
|
||||
* @license LGPL
|
||||
@ -33,11 +34,11 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab
|
||||
* @see Doctrine_Session::STATE_* constants
|
||||
* @var boolean $state the current state of the session
|
||||
*/
|
||||
private $state = 0;
|
||||
private $state = 0;
|
||||
/**
|
||||
* @var integer $transaction_level the nesting level of transactions, used by transaction methods
|
||||
*/
|
||||
private $transaction_level = 0;
|
||||
private $transaction_level = 0;
|
||||
|
||||
/**
|
||||
* @var PDO $cacheHandler
|
||||
@ -47,7 +48,7 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab
|
||||
* @var array $tables an array containing all the initialized Doctrine_Table objects
|
||||
* keys representing Doctrine_Table component names and values as Doctrine_Table objects
|
||||
*/
|
||||
protected $tables = array();
|
||||
protected $tables = array();
|
||||
/**
|
||||
* @var Doctrine_Validator $validator transaction validator
|
||||
*/
|
||||
@ -56,17 +57,17 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab
|
||||
* @var array $update two dimensional pending update list, the records in
|
||||
* this list will be updated when transaction is committed
|
||||
*/
|
||||
protected $update = array();
|
||||
protected $update = array();
|
||||
/**
|
||||
* @var array $insert two dimensional pending insert list, the records in
|
||||
* this list will be inserted when transaction is committed
|
||||
*/
|
||||
protected $insert = array();
|
||||
protected $insert = array();
|
||||
/**
|
||||
* @var array $delete two dimensional pending delete list, the records in
|
||||
* this list will be deleted when transaction is committed
|
||||
*/
|
||||
protected $delete = array();
|
||||
protected $delete = array();
|
||||
|
||||
|
||||
|
||||
@ -103,19 +104,26 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab
|
||||
return $this->cacheHandler;
|
||||
}
|
||||
/**
|
||||
* returns the state of this session
|
||||
*
|
||||
* @see Doctrine_Session::STATE_* constants
|
||||
* @return integer the session state
|
||||
*/
|
||||
public function getState() {
|
||||
return $this->state;
|
||||
}
|
||||
/**
|
||||
* returns the manager that created this session
|
||||
*
|
||||
* @return Doctrine_Manager
|
||||
*/
|
||||
public function getManager() {
|
||||
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() {
|
||||
return $this->dbh;
|
||||
@ -125,7 +133,7 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab
|
||||
* queries the database with Doctrine Query Language
|
||||
*/
|
||||
final public function query($query,array $params = array()) {
|
||||
$parser = new Doctrine_DQL_Parser($this);
|
||||
$parser = new Doctrine_Query($this);
|
||||
|
||||
return $parser->query($query, $params);
|
||||
}
|
||||
@ -145,7 +153,10 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab
|
||||
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()) {
|
||||
if( ! empty($params)) {
|
||||
@ -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
|
||||
*/
|
||||
public function hasTable($name) {
|
||||
|
@ -3,12 +3,12 @@
|
||||
* standard session, the parent of pgsql, mysql and sqlite
|
||||
*/
|
||||
class Doctrine_Session_Common extends Doctrine_Session {
|
||||
public function modifyLimitQuery($query,$limit = null,$offset = null) {
|
||||
if(isset($limit) && isset($offset)) {
|
||||
public function modifyLimitQuery($query,$limit = false,$offset = false) {
|
||||
if($limit && $offset) {
|
||||
$query .= " LIMIT ".$limit." OFFSET ".$offset;
|
||||
} elseif(isset($limit) && ! isset($offset)) {
|
||||
} elseif($limit && ! $offset) {
|
||||
$query .= " LIMIT ".$limit;
|
||||
} elseif( ! isset($limit) && isset($offset)) {
|
||||
} elseif( ! $limit && $offset) {
|
||||
$query .= " LIMIT 999999999999 OFFSET ".$offset;
|
||||
}
|
||||
|
||||
|
@ -68,7 +68,7 @@ class Doctrine_Table extends Doctrine_Configurable {
|
||||
*/
|
||||
private $cache;
|
||||
/**
|
||||
* @var Doctrine_Table_Description $description columns object for this table
|
||||
* @var array $columns an array of column definitions
|
||||
*/
|
||||
private $columns;
|
||||
/**
|
||||
@ -96,8 +96,6 @@ class Doctrine_Table extends Doctrine_Configurable {
|
||||
|
||||
$this->setParent($this->session);
|
||||
|
||||
$name = ucwords(strtolower($name));
|
||||
|
||||
$this->name = $name;
|
||||
|
||||
if( ! class_exists($name) || empty($name))
|
||||
@ -340,12 +338,12 @@ class Doctrine_Table extends Doctrine_Configurable {
|
||||
}
|
||||
/**
|
||||
* @param string $objTableName
|
||||
* @param string $fkField
|
||||
* @param string $field
|
||||
* @return void
|
||||
*/
|
||||
final public function bind($objTableName,$fkField,$type,$localKey) {
|
||||
final public function bind($objTableName,$field,$type,$localKey) {
|
||||
$name = (string) $objTableName;
|
||||
$field = (string) $fkField;
|
||||
$field = (string) $field;
|
||||
|
||||
if(isset($this->foreignKeys[$name]))
|
||||
throw new InvalidKeyException();
|
||||
@ -387,7 +385,7 @@ class Doctrine_Table extends Doctrine_Configurable {
|
||||
}
|
||||
/**
|
||||
* @param string $name component name of which a foreign key object is bound
|
||||
* @return Doctrine_ForeignKey
|
||||
* @return Doctrine_Relation
|
||||
*/
|
||||
final public function getForeignKey($name) {
|
||||
if(isset($this->foreignKeys[$name]))
|
||||
@ -540,7 +538,7 @@ class Doctrine_Table extends Doctrine_Configurable {
|
||||
* @return Doctrine_Collection a collection of all data access objects
|
||||
*/
|
||||
public function findAll() {
|
||||
$graph = new Doctrine_DQL_Parser($this->session);
|
||||
$graph = new Doctrine_Query($this->session);
|
||||
$users = $graph->query("FROM ".$this->name);
|
||||
return $users;
|
||||
}
|
||||
@ -549,7 +547,7 @@ class Doctrine_Table extends Doctrine_Configurable {
|
||||
* @return Doctrine_Collection a collection of data access objects
|
||||
*/
|
||||
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);
|
||||
return $users;
|
||||
}
|
||||
@ -587,16 +585,19 @@ class Doctrine_Table extends Doctrine_Configurable {
|
||||
return $this->columns;
|
||||
}
|
||||
/**
|
||||
* @param integer $fetchMode
|
||||
* @return Doctrine_DQL_Parser a Doctrine_DQL_Parser object
|
||||
* @return Doctrine_Query a Doctrine_Query object
|
||||
*/
|
||||
public function getDQLParser() {
|
||||
$graph = new Doctrine_DQL_Parser($this->getSession());
|
||||
public function getQueryObject() {
|
||||
$graph = new Doctrine_Query($this->getSession());
|
||||
$graph->load($this->getComponentName());
|
||||
return $graph;
|
||||
}
|
||||
/**
|
||||
* execute
|
||||
* @param string $query
|
||||
* @param array $array
|
||||
* @param integer $limit
|
||||
* @param integer $offset
|
||||
*/
|
||||
public function execute($query, array $array = array(), $limit = null, $offset = null) {
|
||||
$coll = new Doctrine_Collection($this);
|
||||
|
@ -2,7 +2,7 @@
|
||||
require_once("UnitTestCase.class.php");
|
||||
class Doctrine_BatchIteratorTestCase extends Doctrine_UnitTestCase {
|
||||
public function testIterator() {
|
||||
$graph = new Doctrine_DQL_Parser($this->session);
|
||||
$graph = new Doctrine_Query($this->session);
|
||||
$entities = $graph->query("FROM Entity");
|
||||
$i = 0;
|
||||
foreach($entities as $entity) {
|
||||
|
@ -16,6 +16,7 @@ require_once("CollectionTestCase.class.php");
|
||||
require_once("CacheSqliteTestCase.class.php");
|
||||
require_once("CollectionOffsetTestCase.class.php");
|
||||
require_once("SenseiTestCase.class.php");
|
||||
require_once("QueryTestCase.class.php");
|
||||
|
||||
|
||||
print "<pre>";
|
||||
@ -33,35 +34,27 @@ $test->addTestCase(new Doctrine_TableTestCase());
|
||||
|
||||
$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_ManagerTestCase());
|
||||
|
||||
|
||||
|
||||
$test->addTestCase(new Doctrine_AccessTestCase());
|
||||
|
||||
|
||||
$test->addTestCase(new Doctrine_EventListenerTestCase());
|
||||
|
||||
$test->addTestCase(new Doctrine_BatchIteratorTestCase());
|
||||
|
||||
|
||||
|
||||
$test->addTestCase(new Doctrine_ConfigurableTestCase());
|
||||
|
||||
$test->addTestCase(new Doctrine_CollectionTestCase());
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
$test->addTestCase(new Doctrine_Collection_OffsetTestCase());
|
||||
|
||||
$test->addTestCase(new Sensei_UnitTestCase());
|
||||
|
||||
$test->addTestCase(new Doctrine_QueryTestCase());
|
||||
//$test->addTestCase(new Doctrine_Cache_FileTestCase());
|
||||
//$test->addTestCase(new Doctrine_Cache_SqliteTestCase());
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user