Created
January 15, 2015 16:40
-
-
Save tlode/ba9a41785c40931802f4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* begin transaction | |
*/ | |
public function begin() | |
{ | |
if(count($this->transactionStack) == 0) | |
{ | |
$this->transactionStack[0] = true; | |
parent::beginTransaction(); | |
} | |
else | |
{ | |
$savePoint = 'savepoint_'. count($this->transactionStack); | |
array_push($this->transactionStack, $savePoint); | |
$this->setSavePoint($savePoint); | |
} | |
} | |
/** | |
* commit | |
*/ | |
public function commit() | |
{ | |
if(count($this->transactionStack) > 1) | |
{ | |
$savePoint = array_pop($this->transactionStack); | |
$this->releaseSavePoint($savePoint); | |
} | |
else | |
{ | |
$this->transactionStack = array(); | |
parent::commit(); | |
} | |
} | |
/** | |
* rollback | |
*/ | |
public function rollback() | |
{ | |
/** | |
* Take care of nesting transaction blocks | |
*/ | |
if(count($this->transactionStack) > 1) | |
{ | |
$savePoint = array_pop($this->transactionStack); | |
$this->rollbackToSavePoint($savePoint); | |
} | |
else | |
{ | |
$this->transactionStack = array(); | |
parent::rollback(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment