From 61c59aa0e0193893921f00f7e8aaf10ff5d4602e Mon Sep 17 00:00:00 2001 From: zYne Date: Mon, 13 Nov 2006 20:31:38 +0000 Subject: [PATCH] Doctrine_Transaction drivers --- lib/Doctrine/Transaction.php | 61 +++++++++++------------ lib/Doctrine/Transaction/Firebird.php | 70 ++++++++++++++++++++++++++ lib/Doctrine/Transaction/Informix.php | 33 +++++++++++++ lib/Doctrine/Transaction/Mssql.php | 33 +++++++++++++ lib/Doctrine/Transaction/Mysql.php | 70 ++++++++++++++++++++++++++ lib/Doctrine/Transaction/Oracle.php | 69 ++++++++++++++++++++++++++ lib/Doctrine/Transaction/Pgsql.php | 71 +++++++++++++++++++++++++++ lib/Doctrine/Transaction/Sqlite.php | 33 +++++++++++++ 8 files changed, 409 insertions(+), 31 deletions(-) create mode 100644 lib/Doctrine/Transaction/Firebird.php create mode 100644 lib/Doctrine/Transaction/Informix.php create mode 100644 lib/Doctrine/Transaction/Mssql.php create mode 100644 lib/Doctrine/Transaction/Mysql.php create mode 100644 lib/Doctrine/Transaction/Oracle.php create mode 100644 lib/Doctrine/Transaction/Pgsql.php create mode 100644 lib/Doctrine/Transaction/Sqlite.php diff --git a/lib/Doctrine/Transaction.php b/lib/Doctrine/Transaction.php index 546fdd7f6..25db7cd5a 100644 --- a/lib/Doctrine/Transaction.php +++ b/lib/Doctrine/Transaction.php @@ -56,7 +56,7 @@ class Doctrine_Transaction { /** * the constructor * - * @param Doctrine_Connection $conn + * @param Doctrine_Connection $conn Doctrine_Connection object */ public function __construct(Doctrine_Connection $conn) { $this->conn = $conn; @@ -119,6 +119,7 @@ class Doctrine_Transaction { return $level; } /** + * commit * Commit the database changes done during a transaction that is in * progress or release a savepoint. This function may only be called when * auto-committing is disabled, otherwise it will fail. Therefore, a new @@ -130,41 +131,39 @@ class Doctrine_Transaction { * @throws Doctrine_Validator_Exception if the transaction fails due to record validations * @return void */ - public function commit($savepoint) { + public function commit($savepoint = null) { if($this->transactionLevel == 0) throw new Doctrine_Transaction_Exception('Commit/release savepoint cannot be done. There is no active transaction.'); - - + if ( ! is_null($savepoint)) { - $query = 'RELEASE SAVEPOINT '.$savepoint; - return $this->_doQuery($query, true); + $this->releaseSavePoint($savepoint); } else { - $this->transactionLevel--; - - if($this->transactionLevel == 0) { - $this->conn->getAttribute(Doctrine::ATTR_LISTENER)->onPreTransactionCommit($this->conn); - - try { - $this->bulkDelete(); - - } catch(Exception $e) { - $this->rollback(); - - throw new Doctrine_Connection_Transaction_Exception($e->__toString()); + $this->transactionLevel--; + + if($this->transactionLevel == 0) { + $this->conn->getAttribute(Doctrine::ATTR_LISTENER)->onPreTransactionCommit($this->conn); + + try { + $this->bulkDelete(); + + } catch(Exception $e) { + $this->rollback(); + + throw new Doctrine_Connection_Transaction_Exception($e->__toString()); + } + + if($tmp = $this->unitOfWork->getInvalid()) { + $this->rollback(); + + throw new Doctrine_Validator_Exception($tmp); + } + + $this->conn->getDbh()->commit(); + + $this->unitOfWork->reset(); + + $this->conn->getAttribute(Doctrine::ATTR_LISTENER)->onTransactionCommit($this->conn); } - - if($tmp = $this->unitOfWork->getInvalid()) { - $this->rollback(); - - throw new Doctrine_Validator_Exception($tmp); - } - - $this->conn->getDbh()->commit(); - - $this->unitOfWork->reset(); - - $this->conn->getAttribute(Doctrine::ATTR_LISTENER)->onTransactionCommit($this->conn); - } } } /** diff --git a/lib/Doctrine/Transaction/Firebird.php b/lib/Doctrine/Transaction/Firebird.php new file mode 100644 index 000000000..aefaf19d9 --- /dev/null +++ b/lib/Doctrine/Transaction/Firebird.php @@ -0,0 +1,70 @@ +. + */ +Doctrine::autoload('Doctrine_Transaction'); +/** + * + * @author Konsta Vesterinen + * @author Lukas Smith (PEAR MDB2 library) + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @package Doctrine + * @category Object Relational Mapping + * @link www.phpdoctrine.com + * @since 1.0 + * @version $Revision$ + */ +class Doctrine_Transaction_Firebird extends Doctrine_Transaction { + /** + * createSavepoint + * creates a new savepoint + * + * @param string $savepoint name of a savepoint to set + * @return void + */ + public function createSavePoint($savepoint) { + $query = 'SAVEPOINT '.$savepoint; + + return $this->conn->getDbh()->query($query); + } + /** + * releaseSavePoint + * releases given savepoint + * + * @param string $savepoint name of a savepoint to release + * @return void + */ + public function releaseSavePoint($savepoint) { + $query = 'RELEASE SAVEPOINT '.$savepoint; + + return $this->conn->getDbh()->query($query); + } + /** + * rollbackSavePoint + * releases given savepoint + * + * @param string $savepoint name of a savepoint to rollback to + * @return void + */ + public function rollbackSavePoint($savepoint) { + $query = 'ROLLBACK TO SAVEPOINT '.$savepoint; + + return $this->conn->getDbh()->query($query); + } +} diff --git a/lib/Doctrine/Transaction/Informix.php b/lib/Doctrine/Transaction/Informix.php new file mode 100644 index 000000000..99d484698 --- /dev/null +++ b/lib/Doctrine/Transaction/Informix.php @@ -0,0 +1,33 @@ +. + */ +Doctrine::autoload('Doctrine_Transaction'); +/** + * + * @author Konsta Vesterinen + * @author Lukas Smith (PEAR MDB2 library) + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @package Doctrine + * @category Object Relational Mapping + * @link www.phpdoctrine.com + * @since 1.0 + * @version $Revision$ + */ +class Doctrine_Transaction_Informix extends Doctrine_Transaction { } diff --git a/lib/Doctrine/Transaction/Mssql.php b/lib/Doctrine/Transaction/Mssql.php new file mode 100644 index 000000000..170c4f723 --- /dev/null +++ b/lib/Doctrine/Transaction/Mssql.php @@ -0,0 +1,33 @@ +. + */ +Doctrine::autoload('Doctrine_Transaction'); +/** + * + * @author Konsta Vesterinen + * @author Lukas Smith (PEAR MDB2 library) + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @package Doctrine + * @category Object Relational Mapping + * @link www.phpdoctrine.com + * @since 1.0 + * @version $Revision$ + */ +class Doctrine_Transaction_Mssql extends Doctrine_Transaction { } diff --git a/lib/Doctrine/Transaction/Mysql.php b/lib/Doctrine/Transaction/Mysql.php new file mode 100644 index 000000000..0150f9742 --- /dev/null +++ b/lib/Doctrine/Transaction/Mysql.php @@ -0,0 +1,70 @@ +. + */ +Doctrine::autoload('Doctrine_Transaction'); +/** + * + * @author Konsta Vesterinen + * @author Lukas Smith (PEAR MDB2 library) + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @package Doctrine + * @category Object Relational Mapping + * @link www.phpdoctrine.com + * @since 1.0 + * @version $Revision$ + */ +class Doctrine_Transaction_Mysql extends Doctrine_Transaction { + /** + * createSavepoint + * creates a new savepoint + * + * @param string $savepoint name of a savepoint to set + * @return void + */ + public function createSavePoint($savepoint) { + $query = 'SAVEPOINT '.$savepoint; + + return $this->conn->getDbh()->query($query); + } + /** + * releaseSavePoint + * releases given savepoint + * + * @param string $savepoint name of a savepoint to release + * @return void + */ + public function releaseSavePoint($savepoint) { + $query = 'RELEASE SAVEPOINT '.$savepoint; + + return $this->conn->getDbh()->query($query); + } + /** + * rollbackSavePoint + * releases given savepoint + * + * @param string $savepoint name of a savepoint to rollback to + * @return void + */ + public function rollbackSavePoint($savepoint) { + $query = 'ROLLBACK TO SAVEPOINT '.$savepoint; + + return $this->conn->getDbh()->query($query); + } +} diff --git a/lib/Doctrine/Transaction/Oracle.php b/lib/Doctrine/Transaction/Oracle.php new file mode 100644 index 000000000..c65c72c63 --- /dev/null +++ b/lib/Doctrine/Transaction/Oracle.php @@ -0,0 +1,69 @@ +. + */ +Doctrine::autoload('Doctrine_Transaction'); +/** + * + * @author Konsta Vesterinen + * @author Lukas Smith (PEAR MDB2 library) + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @package Doctrine + * @category Object Relational Mapping + * @link www.phpdoctrine.com + * @since 1.0 + * @version $Revision$ + */ +class Doctrine_Transaction_Oracle extends Doctrine_Transaction { + /** + * createSavepoint + * creates a new savepoint + * + * @param string $savepoint name of a savepoint to set + * @return void + */ + public function createSavePoint($savepoint) { + $query = 'SAVEPOINT '.$savepoint; + + return $this->conn->getDbh()->query($query); + } + /** + * releaseSavePoint + * releases given savepoint + * + * @param string $savepoint name of a savepoint to release + * @return void + */ + public function releaseSavePoint($savepoint) { + // oracle doesn't support manual releasing of savepoints + return true; + } + /** + * rollbackSavePoint + * releases given savepoint + * + * @param string $savepoint name of a savepoint to rollback to + * @return void + */ + public function rollbackSavePoint($savepoint) { + $query = 'ROLLBACK TO SAVEPOINT '.$savepoint; + + return $this->conn->getDbh()->query($query); + } +} diff --git a/lib/Doctrine/Transaction/Pgsql.php b/lib/Doctrine/Transaction/Pgsql.php new file mode 100644 index 000000000..0e904ea4f --- /dev/null +++ b/lib/Doctrine/Transaction/Pgsql.php @@ -0,0 +1,71 @@ +. + */ +Doctrine::autoload('Doctrine_Transaction'); +/** + * + * @author Konsta Vesterinen + * @author Paul Cooper (PEAR MDB2 Pgsql driver) + * @author Lukas Smith (PEAR MDB2 library) + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @package Doctrine + * @category Object Relational Mapping + * @link www.phpdoctrine.com + * @since 1.0 + * @version $Revision$ + */ +class Doctrine_Transaction_Pgsql extends Doctrine_Transaction { + /** + * createSavepoint + * creates a new savepoint + * + * @param string $savepoint name of a savepoint to set + * @return void + */ + public function createSavePoint($savepoint) { + $query = 'SAVEPOINT '.$savepoint; + + return $this->conn->getDbh()->query($query); + } + /** + * releaseSavePoint + * releases given savepoint + * + * @param string $savepoint name of a savepoint to release + * @return void + */ + public function releaseSavePoint($savepoint) { + $query = 'RELEASE SAVEPOINT '.$savepoint; + + return $this->conn->getDbh()->query($query); + } + /** + * rollbackSavePoint + * releases given savepoint + * + * @param string $savepoint name of a savepoint to rollback to + * @return void + */ + public function rollbackSavePoint($savepoint) { + $query = 'ROLLBACK TO SAVEPOINT '.$savepoint; + + return $this->conn->getDbh()->query($query); + } +} diff --git a/lib/Doctrine/Transaction/Sqlite.php b/lib/Doctrine/Transaction/Sqlite.php new file mode 100644 index 000000000..23dcfb77e --- /dev/null +++ b/lib/Doctrine/Transaction/Sqlite.php @@ -0,0 +1,33 @@ +. + */ +Doctrine::autoload('Doctrine_Transaction'); +/** + * + * @author Konsta Vesterinen + * @author Lukas Smith (PEAR MDB2 library) + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @package Doctrine + * @category Object Relational Mapping + * @link www.phpdoctrine.com + * @since 1.0 + * @version $Revision$ + */ +class Doctrine_Transaction_Sqlite extends Doctrine_Transaction { }