Changeset 15139


Ignore:
Timestamp:
2007/07/27 11:21:45 (17 years ago)
Author:
nanasess
Message:

トランザクションとキャッシュまわり修正

Location:
branches/feature-module-update
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/feature-module-update/data/class/db/SC_DB_MasterData.php

    r15135 r15139  
    9494            $sqlVal = array($columns[0] => $key, 
    9595                            $columns[1] => $val, 
    96                             $columns[2] => $i); 
     96                            $columns[2] => (string) $i); 
    9797            $this->objQuery->insert($name, $sqlVal); 
    9898            $i++; 
     
    130130        // マスタデータを削除 
    131131        $this->deleteMasterData($name, false); 
     132 
    132133        // マスタデータを追加 
    133134        $this->registMasterData($name, $columns, $masterData, false); 
     135 
    134136        if ($autoCommit) { 
    135137            $this->objQuery->commit(); 
    136138        } 
    137  
    138         // キャッシュを消去 
    139         $this->clearCache($name); 
    140         // 新規にデータを取得してキャッシュ生成 
    141         $newData = $this->getMasterData($name, $columns); 
    142         return count($newData); 
     139        return count($masterData); 
    143140    } 
    144141 
     
    155152    function deleteMasterData($name, $autoCommit = true) { 
    156153        $this->objQuery = new SC_Query(); 
    157         return $this->objQuery->delete($name); 
     154        if ($autoCommit) { 
     155            $this->objQuery->begin(); 
     156        } 
     157 
     158        // DB の内容とキャッシュをクリア 
     159        $result = $this->objQuery->delete($name); 
     160        $this->clearCache($name); 
     161 
     162        if ($autoCommit) { 
     163            $this->objQuery->commit(); 
     164        } 
     165        return $result; 
    158166    } 
    159167 
     
    165173     */ 
    166174    function clearCache($name) { 
    167         unlink(MASTER_DATA_DIR . $name . ".php"); 
     175        $masterDataFile = MASTER_DATA_DIR . $name . ".php"; 
     176        if (is_file($masterDataFile)) { 
     177            unlink($masterDataFile); 
     178        } 
    168179    } 
    169180 
  • branches/feature-module-update/test/class/db/SC_DB_MasterData_Test.php

    r15135 r15139  
    4242        $this->assertEquals($expected, $actual); 
    4343    } 
     44 
     45    /** 
     46     * SC_DB_MasterData::updateMasterData() のテストケース 
     47     */ 
     48    function testUpdateMasterData() { 
     49 
     50        $columns = array("pref_id", "pref_name", "rank"); 
     51        $masterData = new SC_DB_MasterData_Ex(); 
     52 
     53        // Transaction を有効にするため接続しておく 
     54        $masterData->objQuery = new SC_Query(); 
     55        $masterData->objQuery->begin(); 
     56 
     57        $expected = array("10" => "北海道", "20" => "愛知", "30" => "岐阜"); 
     58        $masterData->updateMasterData("mtb_pref", $columns, $expected, false); 
     59 
     60        $actual = $masterData->getMasterData("mtb_pref", $columns); 
     61 
     62        $this->assertEquals($expected, $actual); 
     63 
     64        $masterData->objQuery->rollback(); 
     65        $masterData->clearCache("mtb_pref"); 
     66    } 
    4467} 
    4568?> 
Note: See TracChangeset for help on using the changeset viewer.