Source for file Transaction.php

Documentation is available at Transaction.php

  1. <?php
  2. /**
  3.  * Teeple2 - PHP5 Web Application Framework inspired by Seasar2
  4.  *
  5.  * PHP versions 5
  6.  *
  7.  * LICENSE: This source file is subject to version 3.0 of the PHP license
  8.  * that is available through the world-wide-web at the following URI:
  9.  * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
  10.  * the PHP License and are unable to obtain it through the web, please
  11.  * send a note to license@php.net so we can mail you a copy immediately.
  12.  *
  13.  * @package     teeple
  14.  * @author      Mitsutaka Sato <miztaka@gmail.com>
  15.  * @license     http://www.php.net/license/3_0.txt  PHP License 3.0
  16.  */
  17.  
  18. /**
  19.  * Transactionクラスです。
  20.  * 
  21.  * @package teeple
  22.  */
  23.  
  24.     /**
  25.      * @var Teeple_DataSource 
  26.      */
  27.     private $dataSource;
  28.     public function setComponent_Teeple_DataSource($c{
  29.         $this->dataSource $c;
  30.     }
  31.     
  32.     /**
  33.      * コネクションを格納する配列です。
  34.      */
  35.     private $connection array();
  36.  
  37.     private $isstart false;
  38.     private $isclose false;
  39.     
  40.     /**
  41.      * @var Logger 
  42.      */
  43.     private $log;
  44.     
  45.     /**
  46.      * コンストラクタ
  47.      *
  48.      */
  49.     public function __construct({
  50.         $this->log LoggerManager::getLogger(get_class($this));
  51.     }
  52.     
  53.     /**
  54.      * トランザクションを開始します。
  55.      *
  56.      */
  57.     public function start({
  58.         if ($this->isclose == true{
  59.             $this->log->error('トランザクションを開始しようとしましたが既に終了しています。');
  60.             throw new Teeple_Exception('トランザクションを開始しようとしましたが既に終了しています。');
  61.         }
  62.         if ($this->isstart == true{
  63.             $this->log->info("トランザクションを開始しようとしましたが既に開始されています。");
  64.             return;
  65.         }
  66.         $this->log->info("トランザクションを開始します。");
  67.         foreach($this->connection as $name => $conn{
  68.             $conn->beginTransaction();
  69.         }
  70.         $this->isstart true;
  71.     }
  72.     
  73.     /**
  74.      * トランザクションをコミットします。
  75.      *
  76.      */
  77.     public function commit({
  78.         if ($this->isclose == true{
  79.             $this->log->info('トランザクションをコミットしようとしましたが既に終了しています。');
  80.             throw new Teeple_Exception('トランザクションをコミットしようとしましたが既に終了しています。');
  81.         }
  82.         if ($this->isstart == false{
  83.             $this->log->info("トランザクションをコミットしようとしましたがまだ開始されていません。");
  84.             return;
  85.         }
  86.         $this->log->info("トランザクションをコミットします。");
  87.         foreach($this->connection as $name => $conn{
  88.             $conn->commit();
  89.         }
  90.         $this->isclose true;
  91.         $this->log->info("トランザクションをコミットしました。");        
  92.         return;
  93.     }
  94.     
  95.     /**
  96.      * トランザクションをロールバックします。
  97.      *
  98.      */
  99.     public function rollback({
  100.         if ($this->isclose == true{
  101.             $this->log->error('トランザクションをロールバックしようとしましたが既に終了しています。');
  102.             throw new Teeple_Exception('トランザクションをロールバックしようとしましたが既に終了しています。');
  103.         }
  104.         if ($this->isstart == false{
  105.             $this->log->info("トランザクションをロールバックしようとしましたがまだ開始されていません。");
  106.             return;
  107.         }
  108.         $this->log->info("トランザクションをロールバックします。");
  109.         foreach($this->connection as $name => $conn{
  110.             $conn->rollback();
  111.         }
  112.         $this->isclose true;
  113.         $this->log->info("トランザクションをロールバックしました。");
  114.         return;
  115.     }
  116.     
  117.     /**
  118.      * Entityを取得するマジックメソッドです。
  119.      *
  120.      * @param string $name 
  121.      * @return Teeple_ActiveRecord 
  122.      */
  123.     public function __get($name{
  124.         $this->log->debug("エンティティ $name を取得します。");
  125.         if (preg_match('/^Entity_/'$name)) {
  126.             $ref new ReflectionClass($name);
  127.             $ds $ref->getStaticPropertyValue('_DATASOURCE');
  128.             if ($ds == ""{
  129.                 $ds DEFAULT_DATASOURCE;
  130.             }
  131.             $this->log->debug("データソース: {$ds}");
  132.             if (isset($this->connection[$ds])) {
  133.                 $conn $this->connection[$ds];
  134.             else {
  135.                 $conn $this->dataSource->getConnection($ds);
  136.                 $this->connection[$ds$conn;
  137.                 if ($this->isstart{
  138.                     $conn->beginTransaction();
  139.                 }
  140.             }
  141.             return new $name($conn->getDB());
  142.         }
  143.         return NULL;
  144.     }
  145.     
  146.     public function isStarted({
  147.         return $this->isstart;
  148.     }
  149.     
  150.     public function isClosed({
  151.         return $this->isclose;
  152.     }
  153.     
  154. }
  155.  
  156. ?>

Documentation generated on Mon, 26 Apr 2010 09:00:01 +0900 by phpDocumentor 1.4.3