diff --git a/Doctrine/Collection.php b/Doctrine/Collection.php index ecda8b09c..7fc28a47b 100644 --- a/Doctrine/Collection.php +++ b/Doctrine/Collection.php @@ -75,7 +75,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator $table = Doctrine_Manager::getInstance() ->getCurrentConnection() ->getTable($table); - + $this->table = $table; $name = $table->getAttribute(Doctrine::ATTR_COLL_KEY); @@ -122,7 +122,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator */ public function unserialize($serialized) { $manager = Doctrine_Manager::getInstance(); - $session = $manager->getCurrentSession(); + $connection = $manager->getCurrentConnection(); $array = unserialize($serialized); @@ -130,7 +130,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator $this->$name = $values; } - $this->table = $session->getTable($this->table); + $this->table = $connection->getTable($this->table); $this->expanded = array(); $this->expandable = true; @@ -287,7 +287,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator $query = "SELECT ".$foreign." FROM ".$asf->getTableName()." WHERE ".$local."=".$this->getIncremented(); $table = $fk->getTable(); - $graph = new Doctrine_Query($table->getSession()); + $graph = new Doctrine_Query($table->getConnection()); $q = "FROM ".$table->getComponentName()." WHERE ".$table->getComponentName().".".$table->getIdentifier()." IN ($query)"; @@ -526,7 +526,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator * @param mixed $name */ public function loadRelated($name = null) { - $query = new Doctrine_Query($this->table->getSession()); + $query = new Doctrine_Query($this->table->getConnection()); if( ! isset($name)) { foreach($this->data as $record): @@ -639,7 +639,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator * @return void */ public function save() { - $this->table->getSession()->saveCollection($this); + $this->table->getConnection()->saveCollection($this); } /** * single shot delete @@ -648,7 +648,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator * @return boolean */ public function delete() { - $ids = $this->table->getSession()->deleteCollection($this); + $ids = $this->table->getConnection()->deleteCollection($this); $this->data = array(); } /** diff --git a/Doctrine/Configurable.php b/Doctrine/Configurable.php index 0731814f7..7104c5355 100644 --- a/Doctrine/Configurable.php +++ b/Doctrine/Configurable.php @@ -20,7 +20,7 @@ */ /** * Doctrine_Configurable - * the base for Doctrine_Table, Doctrine_Manager and Doctrine_Session + * the base for Doctrine_Table, Doctrine_Manager and Doctrine_Connection * * * @package Doctrine ORM @@ -89,17 +89,17 @@ abstract class Doctrine_Configurable { break; case Doctrine::ATTR_LOCKMODE: - if($this instanceof Doctrine_Session) { - if($this->getState() != Doctrine_Session::STATE_OPEN) + if($this instanceof Doctrine_Connection) { + if($this->getState() != Doctrine_Connection::STATE_OPEN) throw new Doctrine_Exception("Couldn't set lockmode. There are transactions open."); } elseif($this instanceof Doctrine_Manager) { - foreach($this as $session) { - if($session->getState() != Doctrine_Session::STATE_OPEN) + foreach($this as $connection) { + if($connection->getState() != Doctrine_Connection::STATE_OPEN) throw new Doctrine_Exception("Couldn't set lockmode. There are transactions open."); } } else { - throw new Doctrine_Exception("Lockmode attribute can only be set at the global or session level."); + throw new Doctrine_Exception("Lockmode attribute can only be set at the global or connection level."); } break; case Doctrine::ATTR_CREATE_TABLES: diff --git a/Doctrine/EventListener.php b/Doctrine/EventListener.php index 81db0810f..918e7846c 100644 --- a/Doctrine/EventListener.php +++ b/Doctrine/EventListener.php @@ -45,19 +45,19 @@ abstract class Doctrine_EventListener implements Doctrine_EventListener_Interfac public function onDeleteCascade(Doctrine_Record $record) { } public function onPreDeleteCascade(Doctrine_Record $record) { } - public function onClose(Doctrine_Session $session) { } - public function onPreClose(Doctrine_Session $session) { } + public function onClose(Doctrine_Connection $connection) { } + public function onPreClose(Doctrine_Connection $connection) { } - public function onOpen(Doctrine_Session $session) { } + public function onOpen(Doctrine_Connection $connection) { } - public function onTransactionCommit(Doctrine_Session $session) { } - public function onPreTransactionCommit(Doctrine_Session $session) { } + public function onTransactionCommit(Doctrine_Connection $connection) { } + public function onPreTransactionCommit(Doctrine_Connection $connection) { } - public function onTransactionRollback(Doctrine_Session $session) { } - public function onPreTransactionRollback(Doctrine_Session $session) { } + public function onTransactionRollback(Doctrine_Connection $connection) { } + public function onPreTransactionRollback(Doctrine_Connection $connection) { } - public function onTransactionBegin(Doctrine_Session $session) { } - public function onPreTransactionBegin(Doctrine_Session $session) { } + public function onTransactionBegin(Doctrine_Connection $connection) { } + public function onPreTransactionBegin(Doctrine_Connection $connection) { } public function onCollectionDelete(Doctrine_Collection $collection) { } public function onPreCollectionDelete(Doctrine_Collection $collection) { } diff --git a/Doctrine/Hydrate.php b/Doctrine/Hydrate.php index 43a0413b0..e3a805dbe 100644 --- a/Doctrine/Hydrate.php +++ b/Doctrine/Hydrate.php @@ -50,9 +50,9 @@ abstract class Doctrine_Hydrate extends Doctrine_Access { */ protected $data = array(); /** - * @var Doctrine_Session $session Doctrine_Session object + * @var Doctrine_Connection $connection Doctrine_Connection object */ - protected $session; + protected $connection; /** * @var Doctrine_View $view Doctrine_View object */ @@ -90,10 +90,10 @@ abstract class Doctrine_Hydrate extends Doctrine_Access { * @param Doctrine_Connection|null $connection */ public function __construct($connection = null) { - if( ! ($connection instanceof Doctrine_Session)) + if( ! ($connection instanceof Doctrine_Connection)) $connection = Doctrine_Manager::getInstance()->getCurrentConnection(); - $this->session = $connection; + $this->connection = $connection; } /** * getQuery @@ -151,10 +151,10 @@ abstract class Doctrine_Hydrate extends Doctrine_Access { $this->tableAliases = array(); } /** - * @return Doctrine_Session + * @return Doctrine_Connection */ - public function getSession() { - return $this->session; + public function getConnection() { + return $this->connection; } /** * setView @@ -255,7 +255,7 @@ abstract class Doctrine_Hydrate extends Doctrine_Access { $keys = array_keys($this->tables); $name = $this->tables[$keys[0]]->getComponentName(); - $stmt = $this->session->execute($query,$params); + $stmt = $this->connection->execute($query,$params); while($data = $stmt->fetch(PDO::FETCH_ASSOC)): foreach($data as $key => $value): @@ -279,7 +279,7 @@ abstract class Doctrine_Hydrate extends Doctrine_Access { if($this->isLimitSubqueryUsed()) $params = array_merge($params, $params); - $stmt = $this->session->execute($query,$params); + $stmt = $this->connection->execute($query,$params); $previd = array(); diff --git a/Doctrine/Lib.php b/Doctrine/Lib.php index e22ea1f76..8941fd141 100644 --- a/Doctrine/Lib.php +++ b/Doctrine/Lib.php @@ -68,40 +68,40 @@ class Doctrine_Lib { } /** * getStateAsString - * returns a given session state as string - * @param integer $state session state + * returns a given connection state as string + * @param integer $state connection state */ - public static function getSessionStateAsString($state) { + public static function getConnectionStateAsString($state) { switch($state): - case Doctrine_Session::STATE_OPEN: + case Doctrine_Connection::STATE_OPEN: return "open"; break; - case Doctrine_Session::STATE_CLOSED: + case Doctrine_Connection::STATE_CLOSED: return "closed"; break; - case Doctrine_Session::STATE_BUSY: + case Doctrine_Connection::STATE_BUSY: return "busy"; break; - case Doctrine_Session::STATE_ACTIVE: + case Doctrine_Connection::STATE_ACTIVE: return "active"; break; endswitch; } /** - * returns a string representation of Doctrine_Session object - * @param Doctrine_Session $session + * returns a string representation of Doctrine_Connection object + * @param Doctrine_Connection $connection * @return string */ - public static function getSessionAsString(Doctrine_Session $session) { + public static function getConnectionAsString(Doctrine_Connection $connection) { $r[] = "
";
-        $r[] = "Doctrine_Session object";
-        $r[] = "State               : ".Doctrine_Lib::getSessionStateAsString($session->getState());
-        $r[] = "Open Transactions   : ".$session->getTransactionLevel();
-        $r[] = "Open Factories      : ".$session->count();
+        $r[] = "Doctrine_Connection object";
+        $r[] = "State               : ".Doctrine_Lib::getConnectionStateAsString($connection->getState());
+        $r[] = "Open Transactions   : ".$connection->getTransactionLevel();
+        $r[] = "Open Factories      : ".$connection->count();
         $sum = 0;
         $rsum = 0;
         $csum = 0;
-        foreach($session->getTables() as $objTable) {
+        foreach($connection->getTables() as $objTable) {
             if($objTable->getCache() instanceof Doctrine_Cache_File) {
                 $sum += array_sum($objTable->getCache()->getStats());
                 $rsum += $objTable->getRepository()->count();
@@ -113,11 +113,11 @@ class Doctrine_Lib {
 
         $r[] = "Repositories        : ".$rsum." objects ";
         $queries = false;
-        if($session->getDBH() instanceof Doctrine_DB) {
+        if($connection->getDBH() instanceof Doctrine_DB) {
             $handler = "Doctrine Database Handler";
-            $queries = count($session->getDBH()->getQueries());
-            $sum     = array_sum($session->getDBH()->getExecTimes());
-        } elseif($session->getDBH() instanceof PDO) {
+            $queries = count($connection->getDBH()->getQueries());
+            $sum     = array_sum($connection->getDBH()->getExecTimes());
+        } elseif($connection->getDBH() instanceof PDO) {
             $handler = "PHP Native PDO Driver";
         } else
             $handler = "Unknown Database Handler";
diff --git a/Doctrine/Manager.php b/Doctrine/Manager.php
index 8558f148c..b47f24c45 100644
--- a/Doctrine/Manager.php
+++ b/Doctrine/Manager.php
@@ -26,7 +26,7 @@ require_once("EventListener.php");
  * @license     LGPL
  * 
  * Doctrine_Manager is the base component of all doctrine based projects. 
- * It opens and keeps track of all sessions (database connections).
+ * It opens and keeps track of all connections (database connections).
  */
 class Doctrine_Manager extends Doctrine_Configurable implements Countable, IteratorAggregate {
     /**
@@ -38,7 +38,7 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
      */
     private $index      = 0;
     /**
-     * @var integer $currIndex      the current session index
+     * @var integer $currIndex      the current connection index
      */
     private $currIndex  = 0;
     /**
@@ -144,11 +144,11 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
     }
     /**
      * openConnection
-     * opens a new connection and saves it to Doctrine_Manager->sessions
+     * opens a new connection and saves it to Doctrine_Manager->connections
      *
      * @param PDO $pdo                      PDO database driver
      * @param string $name                  name of the connection, if empty numeric key is used
-     * @return Doctrine_Session
+     * @return Doctrine_Connection
      */
     public function openConnection(PDO $pdo, $name = null) {
         // initialize the default attributes
@@ -157,7 +157,7 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
         if($name !== null) {
             $name = (string) $name;
             if(isset($this->connections[$name]))
-                throw new InvalidKeyException();
+                throw new Doctrine_Exception("Connection with $name already exists!");
         
         } else {
             $name = $this->index;
@@ -165,25 +165,25 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
         }
         switch($pdo->getAttribute(PDO::ATTR_DRIVER_NAME)):
             case "mysql":
-                $this->connections[$name] = new Doctrine_Session_Mysql($this,$pdo);
+                $this->connections[$name] = new Doctrine_Connection_Mysql($this,$pdo);
             break;
             case "sqlite":
-                $this->connections[$name] = new Doctrine_Session_Sqlite($this,$pdo);
+                $this->connections[$name] = new Doctrine_Connection_Sqlite($this,$pdo);
             break;
             case "pgsql":
-                $this->connections[$name] = new Doctrine_Session_Pgsql($this,$pdo);
+                $this->connections[$name] = new Doctrine_Connection_Pgsql($this,$pdo);
             break;
             case "oci":
-                $this->connections[$name] = new Doctrine_Session_Oracle($this,$pdo);
+                $this->connections[$name] = new Doctrine_Connection_Oracle($this,$pdo);
             break;
             case "mssql":
-                $this->connections[$name] = new Doctrine_Session_Mssql($this,$pdo);
+                $this->connections[$name] = new Doctrine_Connection_Mssql($this,$pdo);
             break;
             case "firebird":
-                $this->connections[$name] = new Doctrine_Session_Firebird($this,$pdo);
+                $this->connections[$name] = new Doctrine_Connection_Firebird($this,$pdo);
             break;
             case "informix":
-                $this->connections[$name] = new Doctrine_Session_Informix($this,$pdo);
+                $this->connections[$name] = new Doctrine_Connection_Informix($this,$pdo);
             break;
         endswitch;
 
@@ -195,9 +195,9 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
         return $this->openConnection($pdo, $name);
     }
     /**
-     * getSession
+     * getConnection
      * @param integer $index
-     * @return object Doctrine_Session
+     * @return object Doctrine_Connection
      * @throws InvalidKeyException
      */
     public function getConnection($index) {
@@ -210,16 +210,16 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
     public function getSession($index) { return $this->getConnection($index); }
 
     /**
-     * closes the session
+     * closes the connection
      *
-     * @param Doctrine_Session $session
+     * @param Doctrine_Connection $connection
      * @return void
      */
-    public function closeConnection(Doctrine_Session $session) {
-        $session->close();
-        unset($session);
+    public function closeConnection(Doctrine_Connection $connection) {
+        $connection->close();
+        unset($connection);
     }
-    public function closeSession(Doctrine_Session $session) { $this->closeConnection($session); }
+    public function closeSession(Doctrine_Connection $connection) { $this->closeConnection($connection); }
     /**
      * getConnections
      * returns all opened connections
@@ -252,7 +252,7 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
     }
     /**
      * count
-     * returns the number of opened sessions
+     * returns the number of opened connections
      *
      * @return integer
      */
@@ -261,7 +261,7 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
     }
     /**
      * getIterator
-     * returns an ArrayIterator that iterates through all sessions
+     * returns an ArrayIterator that iterates through all connections
      *
      * @return ArrayIterator
      */
@@ -272,13 +272,13 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
      * getCurrentConnection
      * returns the current connection
      *
-     * @throws Doctrine_Session_Exception       if there are no open sessions
-     * @return Doctrine_Session
+     * @throws Doctrine_Connection_Exception       if there are no open connections
+     * @return Doctrine_Connection
      */
     public function getCurrentConnection() {
         $i = $this->currIndex;
         if( ! isset($this->connections[$i]))
-            throw new Doctrine_Session_Exception();
+            throw new Doctrine_Connection_Exception();
 
         return $this->connections[$i];
     }
@@ -292,7 +292,7 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
     public function __toString() {
         $r[] = "
";
         $r[] = "Doctrine_Manager";
-        $r[] = "Sessions : ".count($this->connections);
+        $r[] = "Connections : ".count($this->connections);
         $r[] = "
"; return implode("\n",$r); } diff --git a/Doctrine/Module.php b/Doctrine/Module.php index fd4d2bfdf..6b84253d8 100644 --- a/Doctrine/Module.php +++ b/Doctrine/Module.php @@ -31,9 +31,9 @@ class Doctrine_Module implements IteratorAggregate, Countable { * @return void */ public function flush() { - $session = Doctrine_Manager::getInstance()->getCurrentSession(); + $connection = Doctrine_Manager::getInstance()->getCurrentConnection(); - $tree = $session->buildFlushTree($this->components); + $tree = $connection->buildFlushTree($this->components); } /** * getIterator diff --git a/Doctrine/Query.php b/Doctrine/Query.php index 244b00227..f1cc3c45b 100644 --- a/Doctrine/Query.php +++ b/Doctrine/Query.php @@ -68,7 +68,7 @@ class Doctrine_Query extends Doctrine_Hydrate { if( ! empty($having)) $q .= " HAVING ".implode(' AND ',$having); - $a = $this->getSession()->execute($q, $params)->fetch(PDO::FETCH_NUM); + $a = $this->getConnection()->execute($q, $params)->fetch(PDO::FETCH_NUM); return $a[0]; } /** @@ -320,7 +320,7 @@ class Doctrine_Query extends Doctrine_Hydrate { $modifyLimit = false; if( ! empty($this->parts["limit"]) || ! empty($this->parts["offset"])) { if($needsSubQuery) { - $subquery = $this->session->modifyLimitQuery($subquery,$this->parts["limit"],$this->parts["offset"]); + $subquery = $this->connection->modifyLimitQuery($subquery,$this->parts["limit"],$this->parts["offset"]); $field = $table->getTableName().'.'.$table->getIdentifier(); array_unshift($this->parts['where'], $field.' IN ('.$subquery.')'); @@ -333,7 +333,7 @@ class Doctrine_Query extends Doctrine_Hydrate { $q .= ( ! empty($this->parts['having']))?" HAVING ".implode(" ",$this->parts["having"]):''; $q .= ( ! empty($this->parts['orderby']))?" ORDER BY ".implode(" ",$this->parts["orderby"]):''; if($modifyLimit) - $q = $this->session->modifyLimitQuery($q,$this->parts["limit"],$this->parts["offset"]); + $q = $this->connection->modifyLimitQuery($q,$this->parts["limit"],$this->parts["offset"]); // return to the previous state if( ! empty($string)) @@ -358,7 +358,7 @@ class Doctrine_Query extends Doctrine_Hydrate { if($this->aggregate) { $keys = array_keys($this->tables); $query = $this->getQuery(); - $stmt = $this->tables[$keys[0]]->getSession()->select($query,$this->parts["limit"],$this->parts["offset"]); + $stmt = $this->tables[$keys[0]]->getConnection()->select($query,$this->parts["limit"],$this->parts["offset"]); $data = $stmt->fetch(PDO::FETCH_ASSOC); if(count($data) == 1) { return current($data); @@ -573,7 +573,7 @@ class Doctrine_Query extends Doctrine_Hydrate { if($key == 0) { $currPath = substr($currPath,1); - $table = $this->session->getTable($name); + $table = $this->connection->getTable($name); $tname = $table->getTableName(); diff --git a/Doctrine/RawSql.php b/Doctrine/RawSql.php index f0b19b4f2..5a8053c2c 100644 --- a/Doctrine/RawSql.php +++ b/Doctrine/RawSql.php @@ -203,7 +203,7 @@ class Doctrine_RawSql extends Doctrine_Hydrate { else $alias = $tableAlias; - $table = $this->session->getTable($component); + $table = $this->connection->getTable($component); $this->tables[$alias] = $table; $this->fetchModes[$alias] = Doctrine::FETCH_IMMEDIATE; $this->tableAliases[$currPath] = $alias; diff --git a/Doctrine/Record.php b/Doctrine/Record.php index ba3516138..18d223c54 100644 --- a/Doctrine/Record.php +++ b/Doctrine/Record.php @@ -141,23 +141,23 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite /** * constructor * @param Doctrine_Table $table a Doctrine_Table object - * @throws Doctrine_Session_Exception if object is created using the new operator and there are no - * open sessions + * @throws Doctrine_Connection_Exception if object is created using the new operator and there are no + * open connections */ public function __construct($table = null) { if(isset($table) && $table instanceof Doctrine_Table) { $this->table = $table; $exists = ( ! $this->table->isNewEntry()); } else { - $this->table = Doctrine_Manager::getInstance()->getCurrentSession()->getTable(get_class($this)); + $this->table = Doctrine_Manager::getInstance()->getCurrentConnection()->getTable(get_class($this)); $exists = false; } - // Check if the current session has the records table in its registry + // Check if the current connection has the records table in its registry // If not this is record is only used for creating table definition and setting up // relations. - if($this->table->getSession()->hasTable($this->table->getComponentName())) { + if($this->table->getConnection()->hasTable($this->table->getComponentName())) { $this->oid = self::$index; @@ -373,12 +373,12 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite */ public function unserialize($serialized) { $manager = Doctrine_Manager::getInstance(); - $session = $manager->getCurrentSession(); + $connection = $manager->getCurrentConnection(); $this->oid = self::$index; self::$index++; - $this->table = $session->getTable(get_class($this)); + $this->table = $connection->getTable(get_class($this)); $array = unserialize($serialized); @@ -462,7 +462,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite $id = array_values($id); $query = $this->table->getQuery()." WHERE ".implode(" = ? AND ",$this->table->getPrimaryKeys())." = ?"; - $this->data = $this->table->getSession()->execute($query,$id)->fetch(PDO::FETCH_ASSOC); + $this->data = $this->table->getConnection()->execute($query,$id)->fetch(PDO::FETCH_ASSOC); $this->modified = array(); $this->cleanData(); @@ -741,11 +741,11 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite * @return void */ final public function save() { - $this->table->getSession()->beginTransaction(); + $this->table->getConnection()->beginTransaction(); - $saveLater = $this->table->getSession()->saveRelated($this); + $saveLater = $this->table->getConnection()->saveRelated($this); - $this->table->getSession()->save($this); + $this->table->getConnection()->save($this); foreach($saveLater as $fk) { $table = $fk->getTable(); @@ -761,7 +761,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite $this->saveAssociations(); - $this->table->getSession()->commit(); + $this->table->getConnection()->commit(); } /** * returns an array of modified fields and associated values @@ -866,7 +866,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite foreach($r as $record) { $query = "DELETE FROM ".$asf->getTableName()." WHERE ".$fk->getForeign()." = ?" ." AND ".$fk->getLocal()." = ?"; - $this->table->getSession()->execute($query, array($record->getIncremented(),$this->getIncremented())); + $this->table->getConnection()->execute($query, array($record->getIncremented(),$this->getIncremented())); } $r = Doctrine_Relation::getInsertOperations($this->originals[$alias],$new); @@ -928,7 +928,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite * @return boolean true on success, false on failure */ public function delete() { - return $this->table->getSession()->delete($this); + return $this->table->getConnection()->delete($this); } /** * returns a copy of this object diff --git a/Doctrine/View.php b/Doctrine/View.php index 698365caa..b1d4f50cd 100644 --- a/Doctrine/View.php +++ b/Doctrine/View.php @@ -41,7 +41,7 @@ class Doctrine_View { $this->name = $viewName; $this->query = $query; $this->query->setView($this); - $this->dbh = $query->getSession()->getDBH(); + $this->dbh = $query->getConnection()->getDBH(); } /** * simple get method for getting