From 966fd66f217911d079c4bd6a87b09f4a0c5c4736 Mon Sep 17 00:00:00 2001 From: "godzilla80@gmx.net" <> Date: Sat, 13 Feb 2010 19:04:45 +0000 Subject: NEW: Add Beta of master/slave senario solution - add package System.Testing.Data.Analysis - add package System.Testing.Data.Distributed - add sub package System.Testing.Data.Distributed.MasterSlave - add unittest for System.Testing.Data.Analysis --- .../MasterSlave/TMasterSlaveDbTransaction.php | 83 ++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 framework/Testing/Data/Distributed/MasterSlave/TMasterSlaveDbTransaction.php (limited to 'framework/Testing/Data/Distributed/MasterSlave/TMasterSlaveDbTransaction.php') diff --git a/framework/Testing/Data/Distributed/MasterSlave/TMasterSlaveDbTransaction.php b/framework/Testing/Data/Distributed/MasterSlave/TMasterSlaveDbTransaction.php new file mode 100644 index 00000000..254afdb5 --- /dev/null +++ b/framework/Testing/Data/Distributed/MasterSlave/TMasterSlaveDbTransaction.php @@ -0,0 +1,83 @@ + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2010 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + * @package System.Testing.Data.Distributed.MasterSlave + */ + Prado::using('System.Data.TDbTransaction'); + + /** + * TMasterSlaveDbTransaction class + * + * IMPORTANT!!! + * BETA Version - Use with care and NOT in production environment (only tested with MySql) + * + * TMasterSlaveDbTransaction represents a DB transaction in master/slave senario. + * + * @author Yves Berkholz + * @version $Id$ + * @package System.Testing.Data.Distributed.MasterSlave + * @since 4.0 + */ + class TMasterSlaveDbTransaction extends TDbTransaction + { + /** + * @var boolean + */ + private $_compatible = false; + + /** + * Constructor. + * @param TDbConnection the connection associated with this transaction + * @see TDbConnection::beginTransaction + */ + public function __construct(TDbConnection $connection) + { + if($connection instanceof ISlaveDbConnection) + { + $this->_compatible = true; + $master = $connection->getMasterConnection(); + $master->setForceMaster(TMasterSlaveDbConnectionForceMaster::ON_TRANSACTION); + Prado::log('contstuct, ForceMaster: ON_TRANSACTION', TLogger::DEBUG, 'System.Testing.Data.Distributed.MasterSlave.TMasterSlaveDbTransaction'); + parent::__construct($master); + } + else + { + if($connection instanceof IMasterSlaveDbConnection) + { + $this->_compatible = true; + $connection->setForceMaster(TMasterSlaveDbConnectionForceMaster::ON_TRANSACTION); + Prado::log('contstuct, ForceMaster: ON_TRANSACTION', TLogger::DEBUG, 'System.TestingData.Distributed.MasterSlave.TMasterSlaveDbTransaction'); + } + parent::__construct($connection); + } + } + + /** + * Commits a transaction. + * @throws TDbException if the transaction or the DB connection is not active. + */ + public function commit() + { + if($this->_compatible) $this->getConnection()->setForceMaster(TMasterSlaveDbConnectionForceMaster::OFF_AUTOMATIC); + Prado::log('commit, ForceMaster: OFF_AUTOMATIC', TLogger::DEBUG, 'System.Testing.Data.Distributed.MasterSlave.TMasterSlaveDbTransaction'); + parent::commit(); + } + + /** + * Rolls back a transaction. + * @throws TDbException if the transaction or the DB connection is not active. + */ + public function rollback() + { + if($this->_compatible) $this->getConnection()->setForceMaster(TMasterSlaveDbConnectionForceMaster::OFF_AUTOMATIC); + Prado::log('rollback, ForceMaster: OFF_AUTOMATIC', TLogger::DEBUG, 'System.Testing.Data.Distributed.MasterSlave.TMasterSlaveDbTransaction'); + parent::rollback(); + } + } +?> \ No newline at end of file -- cgit v1.2.3