Refactored Doctrine_Connection
This commit is contained in:
parent
d6d7824135
commit
caf4185955
@ -35,14 +35,6 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
|
|||||||
* @var $dbh the database handler
|
* @var $dbh the database handler
|
||||||
*/
|
*/
|
||||||
private $dbh;
|
private $dbh;
|
||||||
/**
|
|
||||||
* @var Doctrine_Transaction $transaction the transaction object
|
|
||||||
*/
|
|
||||||
private $transaction;
|
|
||||||
/**
|
|
||||||
* @var Doctrine_UnitOfWork $unitOfWork the unit of work object
|
|
||||||
*/
|
|
||||||
private $unitOfWork;
|
|
||||||
/**
|
/**
|
||||||
* @var array $tables an array containing all the initialized Doctrine_Table objects
|
* @var array $tables an array containing all the initialized Doctrine_Table objects
|
||||||
* keys representing Doctrine_Table component names and values as Doctrine_Table objects
|
* keys representing Doctrine_Table component names and values as Doctrine_Table objects
|
||||||
@ -58,18 +50,30 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
|
|||||||
* one of the following (true, false, 'emulated')
|
* one of the following (true, false, 'emulated')
|
||||||
*/
|
*/
|
||||||
protected $supported = array();
|
protected $supported = array();
|
||||||
/**
|
|
||||||
* @var Doctrine_DataDict $dataDict
|
|
||||||
*/
|
|
||||||
private $dataDict;
|
|
||||||
|
|
||||||
protected $options = array();
|
|
||||||
|
|
||||||
private $modules = array('Transaction' => false,
|
protected $options = array();
|
||||||
'Expression' => false,
|
/**
|
||||||
'DataDict' => false,
|
* @var array $modules an array containing all modules
|
||||||
'Export' => false,
|
* transaction Doctrine_Transaction driver, handles savepoint and transaction isolation abstraction
|
||||||
'UnitOfWork' => false,
|
*
|
||||||
|
* expression Doctrine_Expression driver, handles expression abstraction
|
||||||
|
*
|
||||||
|
* dataDict Doctrine_DataDict driver, handles datatype abstraction
|
||||||
|
*
|
||||||
|
* export Doctrine_Export driver, handles db structure modification abstraction (contains
|
||||||
|
* methods such as alterTable, createConstraint etc.)
|
||||||
|
*
|
||||||
|
* @see Doctrine_Connection::__get()
|
||||||
|
* @see Doctrine_DataDict
|
||||||
|
* @see Doctrine_Expression
|
||||||
|
* @see Doctrine_Export
|
||||||
|
* @see Doctrine_Transaction
|
||||||
|
*/
|
||||||
|
private $modules = array('transaction' => false,
|
||||||
|
'expression' => false,
|
||||||
|
'dataDict' => false,
|
||||||
|
'export' => false,
|
||||||
|
'unitOfWork' => false,
|
||||||
);
|
);
|
||||||
/**
|
/**
|
||||||
* @var array $availibleDrivers an array containing all availible drivers
|
* @var array $availibleDrivers an array containing all availible drivers
|
||||||
@ -96,8 +100,8 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
|
|||||||
|
|
||||||
$this->dbh = $adapter;
|
$this->dbh = $adapter;
|
||||||
|
|
||||||
$this->transaction = new Doctrine_Connection_Transaction($this);
|
$this->modules['transaction'] = new Doctrine_Connection_Transaction($this);
|
||||||
$this->unitOfWork = new Doctrine_Connection_UnitOfWork($this);
|
$this->modules['unitOfWork'] = new Doctrine_Connection_UnitOfWork($this);
|
||||||
|
|
||||||
$this->setParent($manager);
|
$this->setParent($manager);
|
||||||
|
|
||||||
@ -119,21 +123,25 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
|
|||||||
* __get
|
* __get
|
||||||
* lazy loads given module and returns it
|
* lazy loads given module and returns it
|
||||||
*
|
*
|
||||||
|
* @see Doctrine_DataDict
|
||||||
|
* @see Doctrine_Expression
|
||||||
|
* @see Doctrine_Export
|
||||||
|
* @see Doctrine_Transaction
|
||||||
* @param string $name the name of the module to get
|
* @param string $name the name of the module to get
|
||||||
* @throws Doctrine_Connection_Exception if trying to get an unknown module
|
* @throws Doctrine_Connection_Exception if trying to get an unknown module
|
||||||
* @return Doctrine_Connection_Module connection module
|
* @return Doctrine_Connection_Module connection module
|
||||||
*/
|
*/
|
||||||
public function __get($name) {
|
public function __get($name) {
|
||||||
if( ! isset($this->modules[$name]))
|
if( ! isset($this->modules[$name]))
|
||||||
throw new Doctrine_Connection_Exception('Unknown module ' . $name);
|
throw new Doctrine_Connection_Exception('Unknown module ' . $name);
|
||||||
|
|
||||||
if($this->modules[$name] === false) {
|
if($this->modules[$name] === false) {
|
||||||
switch($name) {
|
switch($name) {
|
||||||
case 'UnitOfWork':
|
case 'unitOfWork':
|
||||||
$this->modules[$name] = new Doctrine_Connection_UnitOfWork($this);
|
$this->modules[$name] = new Doctrine_Connection_UnitOfWork($this);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
$class = 'Doctrine_' . $name . '_' . $this->getName();
|
$class = 'Doctrine_' . ucwords($name) . '_' . $this->getName();
|
||||||
$this->modules[$name] = new $class($this);
|
$this->modules[$name] = new $class($this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -200,26 +208,6 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
|
|||||||
$str = str_replace($this->identifier_quoting['end'], $this->identifier_quoting['escape'] . $this->identifier_quoting['end'], $str);
|
$str = str_replace($this->identifier_quoting['end'], $this->identifier_quoting['escape'] . $this->identifier_quoting['end'], $str);
|
||||||
return $this->identifier_quoting['start'] . $str . $this->identifier_quoting['end'];
|
return $this->identifier_quoting['start'] . $str . $this->identifier_quoting['end'];
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* getUnitOfWork
|
|
||||||
*
|
|
||||||
* returns the unit of work object
|
|
||||||
*
|
|
||||||
* @return Doctrine_UnitOfWork
|
|
||||||
*/
|
|
||||||
public function getUnitOfWork() {
|
|
||||||
return $this->unitOfWork;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* getTransaction
|
|
||||||
*
|
|
||||||
* returns the current transaction object
|
|
||||||
*
|
|
||||||
* @return Doctrine_Transaction
|
|
||||||
*/
|
|
||||||
public function getTransaction() {
|
|
||||||
return $this->transaction;
|
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
* returns the manager that created this connection
|
* returns the manager that created this connection
|
||||||
*
|
*
|
||||||
@ -261,10 +249,11 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
|
|||||||
* @return string name of the sequence with possible formatting removed
|
* @return string name of the sequence with possible formatting removed
|
||||||
*/
|
*/
|
||||||
public function fixSequenceName($sqn) {
|
public function fixSequenceName($sqn) {
|
||||||
$seq_pattern = '/^'.preg_replace('/%s/', '([a-z0-9_]+)', $db->options['seqname_format']).'$/i';
|
$seqPattern = '/^'.preg_replace('/%s/', '([a-z0-9_]+)', $this->getAttribute(Doctrine::ATTR_SEQNAME_FORMAT)).'$/i';
|
||||||
$seq_name = preg_replace($seq_pattern, '\\1', $sqn);
|
$seqName = preg_replace($seqPattern, '\\1', $sqn);
|
||||||
if ($seq_name && ! strcasecmp($sqn, $db->getSequenceName($seq_name))) {
|
|
||||||
return $seq_name;
|
if ($seqName && ! strcasecmp($sqn, $db->getSequenceName($seqName))) {
|
||||||
|
return $seqName;
|
||||||
}
|
}
|
||||||
return $sqn;
|
return $sqn;
|
||||||
}
|
}
|
||||||
@ -275,27 +264,14 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
|
|||||||
* @return string name of the index with possible formatting removed
|
* @return string name of the index with possible formatting removed
|
||||||
*/
|
*/
|
||||||
public function fixIndexName($idx) {
|
public function fixIndexName($idx) {
|
||||||
$idx_pattern = '/^'.preg_replace('/%s/', '([a-z0-9_]+)', $db->options['idxname_format']).'$/i';
|
$indexPattern = '/^'.preg_replace('/%s/', '([a-z0-9_]+)', $this->getAttribute(Doctrine::ATTR_IDXNAME_FORMAT)).'$/i';
|
||||||
$idx_name = preg_replace($idx_pattern, '\\1', $idx);
|
$indexName = preg_replace($indexPattern, '\\1', $idx);
|
||||||
if ($idx_name && !strcasecmp($idx, $db->getIndexName($idx_name))) {
|
if ($indexName && ! strcasecmp($idx, $this->getIndexName($indexName))) {
|
||||||
return $idx_name;
|
return $indexName;
|
||||||
}
|
}
|
||||||
return $idx;
|
return $idx;
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* returns a datadict object
|
|
||||||
*
|
|
||||||
* @return Doctrine_DataDict
|
|
||||||
*/
|
|
||||||
public function getDataDict() {
|
|
||||||
if(isset($this->dataDict))
|
|
||||||
return $this->dataDict;
|
|
||||||
|
|
||||||
$class = 'Doctrine_DataDict_' . $this->getName();
|
|
||||||
$this->dataDict = new $class($this->dbh);
|
|
||||||
|
|
||||||
return $this->dataDict;
|
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
* Execute a SQL REPLACE query. A REPLACE query is identical to a INSERT
|
* Execute a SQL REPLACE query. A REPLACE query is identical to a INSERT
|
||||||
* query, except that if there is already a row in the table with the same
|
* query, except that if there is already a row in the table with the same
|
||||||
|
@ -22,14 +22,14 @@ Doctrine::autoload('Doctrine_Expression');
|
|||||||
/**
|
/**
|
||||||
* Doctrine_Expression_Sqlite
|
* Doctrine_Expression_Sqlite
|
||||||
*
|
*
|
||||||
* @package Doctrine
|
* @package Doctrine
|
||||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||||
* @category Object Relational Mapping
|
* @category Object Relational Mapping
|
||||||
* @link www.phpdoctrine.com
|
* @link www.phpdoctrine.com
|
||||||
* @since 1.0
|
* @since 1.0
|
||||||
* @version $Revision$
|
* @version $Revision$
|
||||||
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
||||||
*/
|
*/
|
||||||
class Doctrine_Expression_Sqlite extends Doctrine_Expression {
|
class Doctrine_Expression_Sqlite extends Doctrine_Expression {
|
||||||
/**
|
/**
|
||||||
* Returns the md5 sum of the data that SQLite's md5() function receives.
|
* Returns the md5 sum of the data that SQLite's md5() function receives.
|
||||||
@ -72,16 +72,16 @@ class Doctrine_Expression_Sqlite extends Doctrine_Expression {
|
|||||||
public static function locateImpl($substr, $str) {
|
public static function locateImpl($substr, $str) {
|
||||||
return strpos($str, $substr);
|
return strpos($str, $substr);
|
||||||
}
|
}
|
||||||
public static function sha1($str) {
|
public static function sha1Impl($str) {
|
||||||
return sha1($str);
|
return sha1($str);
|
||||||
}
|
}
|
||||||
public static function ltrim($str) {
|
public static function ltrimImpl($str) {
|
||||||
return ltrim($str);
|
return ltrim($str);
|
||||||
}
|
}
|
||||||
public static function rtrim($str) {
|
public static function rtrimImpl($str) {
|
||||||
return rtrim($str);
|
return rtrim($str);
|
||||||
}
|
}
|
||||||
public static function trim($str) {
|
public static function trimImpl($str) {
|
||||||
return trim($str);
|
return trim($str);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user