classShadowTransactions
final class ShadowTransactions
implements TransactionTarget
@visibility public.Keeps the shadow at the point each open transaction could go back to.
Nothing is sent to the database, so a transaction here is a stack of savepoints over the shadow. A nested BEGIN is ignored, because that is what a database does with one; a savepoint declared twice under the same name takes the place of the first, which is what SQL says it does.
$store = new \ZtdQuery\Shadow\ShadowStore();
$store->set('users', [['id' => 1]]);
$transactions = new \ZtdQuery\Shadow\ShadowTransactionManager($store);
$transactions->begin();
$transactions->savepoint('before_insert');
$store->insert('users', [['id' => 2]]);
$transactions->rollBackTo('before_insert');
$store->get('users') // => [['id' => 1]]
$transactions->commit();Methods§
public function __construct(
private ShadowStore $store,
private TableDefinitionRegistry|null $registry = null,
)Parameters
$store | ShadowStore | Rows a rollback puts back |
$registry | TableDefinitionRegistry|null | Tables a rollback puts back, where anything is describing them |
Test cases 8
ShadowTransactionsTest::testBeginIsIgnoredWhereATransactionHasAlreadyBeguncoversShadowTransactionsTest::testCommitLeavesNothingToRollBackTocoversShadowTransactionsTest::testPositionOfIsNothingForANameNothingWasDeclaredUndercoversShadowTransactionsTest::testReleaseGivesUpTheSavepointAndEveryNestedOneWithoutUndoingAnythingcoversShadowTransactionsTest::testRollBackPutsBackTheRowsTheTablesAndWhatDescribesThemcoversShadowTransactionsTest::testRollBackToKeepsTheSavepointAndGivesUpEveryLaterOnecoversShadowTransactionsTest::testRollBackToLeavesItsTargetToBeRolledBackToAgaincoversShadowTransactionsTest::testSavepointDeclaredTwiceUnderOneNameTakesThePlaceOfTheFirstcovers
public function begin(): voidStarts a transaction, unless one has already been started.
Test cases 8
ShadowTransactionsTest::testBeginIsIgnoredWhereATransactionHasAlreadyBeguncovers and callsShadowTransactionsTest::testCommitLeavesNothingToRollBackTocovers and callsShadowTransactionsTest::testReleaseGivesUpTheSavepointAndEveryNestedOneWithoutUndoingAnythingcovers and callsShadowTransactionsTest::testRollBackPutsBackTheRowsTheTablesAndWhatDescribesThemcovers and callsShadowTransactionsTest::testRollBackToKeepsTheSavepointAndGivesUpEveryLaterOnecovers and callsShadowTransactionsTest::testRollBackToLeavesItsTargetToBeRolledBackToAgaincovers and callsShadowTransactionsTest::testSavepointDeclaredTwiceUnderOneNameTakesThePlaceOfTheFirstcovers and callsTransactionStatementTest::testSavepointPreservesTheNamedTransactionBoundarycalls
Called from 1
Calls 1
- static-call ShadowSavepoint::of() line 57
public function commit(): voidKeeps everything the transaction did.
Test cases 3
Called from 1
public function rollBack(): voidPuts the shadow back to what it was when the transaction began.
Test cases 5
ShadowTransactionsTest::testBeginIsIgnoredWhereATransactionHasAlreadyBeguncovers and callsShadowTransactionsTest::testCommitLeavesNothingToRollBackTocovers and callsShadowTransactionsTest::testRollBackPutsBackTheRowsTheTablesAndWhatDescribesThemcovers and callsShadowTransactionsTest::testRollBackToLeavesItsTargetToBeRolledBackToAgaincovers and callsTransactionStatementParserTest::testParseReadsAStatementThatOpensATransactioncalls
Called from 1
public function savepoint(string $name): voidDeclares a savepoint the transaction can go back to.
Parameters
$name | string | Name to declare it under |
Test cases 5
ShadowTransactionsTest::testPositionOfIsNothingForANameNothingWasDeclaredUndercovers and callsShadowTransactionsTest::testReleaseGivesUpTheSavepointAndEveryNestedOneWithoutUndoingAnythingcovers and callsShadowTransactionsTest::testRollBackToKeepsTheSavepointAndGivesUpEveryLaterOnecovers and callsShadowTransactionsTest::testRollBackToLeavesItsTargetToBeRolledBackToAgaincovers and callsShadowTransactionsTest::testSavepointDeclaredTwiceUnderOneNameTakesThePlaceOfTheFirstcovers and calls
Calls 3
- method-call ShadowTransactions::positionOf() line 88
- function-call
array_sliceline 90 - static-call ShadowSavepoint::of() line 92
public function rollBackTo(string $name): voidPuts the shadow back to a named savepoint, which stays declared.
Parameters
$name | string | Savepoint to go back to |
Test cases 5
ShadowTransactionsTest::testPositionOfIsNothingForANameNothingWasDeclaredUndercovers and callsShadowTransactionsTest::testReleaseGivesUpTheSavepointAndEveryNestedOneWithoutUndoingAnythingcovers and callsShadowTransactionsTest::testRollBackToKeepsTheSavepointAndGivesUpEveryLaterOnecovers and callsShadowTransactionsTest::testRollBackToLeavesItsTargetToBeRolledBackToAgaincovers and callsShadowTransactionsTest::testSavepointDeclaredTwiceUnderOneNameTakesThePlaceOfTheFirstcovers and calls
Calls 2
- method-call ShadowTransactions::positionOf() line 102
- function-call
array_sliceline 108
public function release(string $name): voidGives up a named savepoint, keeping everything done since it.
Parameters
$name | string | Savepoint to give up |
Test cases 3
ShadowTransactionsTest::testPositionOfIsNothingForANameNothingWasDeclaredUndercovers and callsShadowTransactionsTest::testReleaseGivesUpTheSavepointAndEveryNestedOneWithoutUndoingAnythingcovers and callsShadowTransactionsTest::testSavepointDeclaredTwiceUnderOneNameTakesThePlaceOfTheFirstcovers and calls
Calls 2
- method-call ShadowTransactions::positionOf() line 118
- function-call
array_sliceline 120
public function positionOf(string $name): int|nullAnswers where a named savepoint is, counting the innermost first.
A name declared more than once names the innermost of them, which is the one a rollback goes back to.
Parameters
$name | string | Savepoint to look for |
Returns
int|null Its position, or null when nothing is declared under that nameTest cases 10
ShadowTransactionsTest::testPositionOfIsNothingForANameNothingWasDeclaredUndercoversShadowTransactionsTest::testReleaseGivesUpTheSavepointAndEveryNestedOneWithoutUndoingAnythingcoversShadowTransactionsTest::testRollBackToKeepsTheSavepointAndGivesUpEveryLaterOnecoversShadowTransactionsTest::testRollBackToLeavesItsTargetToBeRolledBackToAgaincoversShadowTransactionsTest::testSavepointDeclaredTwiceUnderOneNameTakesThePlaceOfTheFirstcoversTransactionStatementParserTest::testParseReadsAStatementThatDeclaresASavepointcallsTransactionStatementParserTest::testParseReadsAStatementThatGivesUpASavepointcallsTransactionStatementTest::testApplyDoesWhatEachOperationSayscallsTransactionStatementTest::testRollbackToGoesBackToTheSavepointAndLeavesItDeclaredcallsTransactionStatementTest::testSavepointPreservesTheNamedTransactionBoundarycalls
Called from 3
- method-call ZtdQuery\Shadow\ShadowTransactions::savepoint() packages/ztd-query-core/src/Shadow/ShadowTransactions.php:88
- method-call ZtdQuery\Shadow\ShadowTransactions::rollBackTo() packages/ztd-query-core/src/Shadow/ShadowTransactions.php:102
- method-call ZtdQuery\Shadow\ShadowTransactions::release() packages/ztd-query-core/src/Shadow/ShadowTransactions.php:118
Calls 1
- function-call
countline 136
Private surface 3§
Implementation details, listed for orientation only.
private list<ShadowSavepoint> $savepoints = []private ShadowStore $storeprivate TableDefinitionRegistry|null $registry = nullTest cases 20§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 8
ShadowTransactionsTest::testBeginIsIgnoredWhereATransactionHasAlreadyBeguncovers and callsShadowTransactionsTest::testCommitLeavesNothingToRollBackTocovers and callsShadowTransactionsTest::testPositionOfIsNothingForANameNothingWasDeclaredUndercovers and callsShadowTransactionsTest::testReleaseGivesUpTheSavepointAndEveryNestedOneWithoutUndoingAnythingcovers and callsShadowTransactionsTest::testRollBackPutsBackTheRowsTheTablesAndWhatDescribesThemcovers and callsShadowTransactionsTest::testRollBackToKeepsTheSavepointAndGivesUpEveryLaterOnecovers and callsShadowTransactionsTest::testRollBackToLeavesItsTargetToBeRolledBackToAgaincovers and callsShadowTransactionsTest::testSavepointDeclaredTwiceUnderOneNameTakesThePlaceOfTheFirstcovers and calls
Other tests reaching this symbol 12
SessionTest::testBeginTransactionRollBackTransactionBeginTransactionUsesProvidedTransactionManagerForSchemaRollbackcallsStatementSimulatorTestcallsTransactionStatementParserTest::testParseReadsAStatementThatDeclaresASavepointcallsTransactionStatementParserTest::testParseReadsAStatementThatGivesUpASavepointcallsTransactionStatementParserTest::testParseReadsAStatementThatOpensATransactioncallsTransactionStatementTest::testApplyDoesWhatEachOperationSayscallsTransactionStatementTest::testBeginStartsATransactionARollbackCanGoBackTocallsTransactionStatementTest::testCommitKeepsEverythingTheTransactionDidcallsTransactionStatementTest::testReleaseCommitAppliesNamedTransactionLifecycleWithoutSqlcallsTransactionStatementTest::testRollbackAppliesRollbackcallsTransactionStatementTest::testRollbackToGoesBackToTheSavepointAndLeavesItDeclaredcallsTransactionStatementTest::testSavepointPreservesTheNamedTransactionBoundarycalls
Relations§
Instantiated in 1
Method calls 3
Constant reads 1
- class-const packages/ztd-query-core/src/Compatibility/ClassAliases.php packages/ztd-query-core/src/Compatibility/ClassAliases.php:33