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 |
public function begin(): voidStarts a transaction, unless one has already been started.
Test cases 11
ShadowTransactionsTest::testBeginIsIgnoredWhereATransactionHasAlreadyBeguncallsShadowTransactionsTest::testCommitLeavesNothingToRollBackTocallsShadowTransactionsTest::testReleaseGivesUpTheSavepointAndEveryNestedOneWithoutUndoingAnythingcallsShadowTransactionsTest::testRollBackPutsBackTheRowsTheTablesAndWhatDescribesThemcallsShadowTransactionsTest::testRollBackToKeepsTheSavepointAndGivesUpEveryLaterOnecallsShadowTransactionsTest::testRollBackToLeavesItsTargetToBeRolledBackToAgaincallsShadowTransactionsTest::testSavepointDeclaredTwiceUnderOneNameTakesThePlaceOfTheFirstcallsMySqlTransactionStatementParserTest::testAppliesUnescapedMySqlSavepointNamecallsPgSqlTransactionStatementParserTest::testAppliesUnescapedPostgresSavepointNamecallsSqliteTransactionStatementParserTest::testAppliesUnescapedSqliteSavepointNamecallsTransactionStatementTest::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::testBeginIsIgnoredWhereATransactionHasAlreadyBeguncallsShadowTransactionsTest::testCommitLeavesNothingToRollBackTocallsShadowTransactionsTest::testRollBackPutsBackTheRowsTheTablesAndWhatDescribesThemcallsShadowTransactionsTest::testRollBackToLeavesItsTargetToBeRolledBackToAgaincallsTransactionStatementParserTest::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::testPositionOfIsNothingForANameNothingWasDeclaredUndercallsShadowTransactionsTest::testReleaseGivesUpTheSavepointAndEveryNestedOneWithoutUndoingAnythingcallsShadowTransactionsTest::testRollBackToKeepsTheSavepointAndGivesUpEveryLaterOnecallsShadowTransactionsTest::testRollBackToLeavesItsTargetToBeRolledBackToAgaincallsShadowTransactionsTest::testSavepointDeclaredTwiceUnderOneNameTakesThePlaceOfTheFirstcalls
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 8
ShadowTransactionsTest::testPositionOfIsNothingForANameNothingWasDeclaredUndercallsShadowTransactionsTest::testReleaseGivesUpTheSavepointAndEveryNestedOneWithoutUndoingAnythingcallsShadowTransactionsTest::testRollBackToKeepsTheSavepointAndGivesUpEveryLaterOnecallsShadowTransactionsTest::testRollBackToLeavesItsTargetToBeRolledBackToAgaincallsShadowTransactionsTest::testSavepointDeclaredTwiceUnderOneNameTakesThePlaceOfTheFirstcallsMySqlTransactionStatementParserTest::testAppliesUnescapedMySqlSavepointNamecallsPgSqlTransactionStatementParserTest::testAppliesUnescapedPostgresSavepointNamecallsSqliteTransactionStatementParserTest::testAppliesUnescapedSqliteSavepointNamecalls
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
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 5
TransactionStatementParserTest::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 24§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 8
ShadowTransactionsTest::testBeginIsIgnoredWhereATransactionHasAlreadyBeguncallsShadowTransactionsTest::testCommitLeavesNothingToRollBackTocallsShadowTransactionsTest::testPositionOfIsNothingForANameNothingWasDeclaredUndercallsShadowTransactionsTest::testReleaseGivesUpTheSavepointAndEveryNestedOneWithoutUndoingAnythingcallsShadowTransactionsTest::testRollBackPutsBackTheRowsTheTablesAndWhatDescribesThemcallsShadowTransactionsTest::testRollBackToKeepsTheSavepointAndGivesUpEveryLaterOnecallsShadowTransactionsTest::testRollBackToLeavesItsTargetToBeRolledBackToAgaincallsShadowTransactionsTest::testSavepointDeclaredTwiceUnderOneNameTakesThePlaceOfTheFirstcalls
Other tests reaching this symbol 16
SqliteRewriterTest::testTransactionStatementRestoresSnapshotOnRollbackcallsSessionTest::testBeginTransactionRollBackTransactionBeginTransactionUsesProvidedTransactionManagerForSchemaRollbackcallsStatementSimulatorTestcallsMySqlTransactionStatementParserTest::testAppliesUnescapedMySqlSavepointNamecallsPgSqlTransactionStatementParserTest::testAppliesUnescapedPostgresSavepointNamecallsSqliteTransactionStatementParserTest::testAppliesUnescapedSqliteSavepointNamecallsTransactionStatementParserTest::testParseReadsAStatementThatDeclaresASavepointcallsTransactionStatementParserTest::testParseReadsAStatementThatGivesUpASavepointcallsTransactionStatementParserTest::testParseReadsAStatementThatOpensATransactioncallsTransactionStatementTest::testApplyDoesWhatEachOperationSayscallsTransactionStatementTest::testBeginStartsATransactionARollbackCanGoBackTocallsTransactionStatementTest::testCommitKeepsEverythingTheTransactionDidcallsTransactionStatementTest::testReleaseCommitAppliesNamedTransactionLifecycleWithoutSqlcallsTransactionStatementTest::testRollbackAppliesRollbackcallsTransactionStatementTest::testRollbackToGoesBackToTheSavepointAndLeavesItDeclaredcallsTransactionStatementTest::testSavepointPreservesTheNamedTransactionBoundarycalls
Relations§
Instantiated in 4
- new ZtdQuery\Session::__construct() packages/ztd-query-core/src/Session.php:99
- new ZtdQuery\Platform\MySql\MySqlSessionFactory::create() packages/ztd-query-mysql/src/MySqlSessionFactory.php:77
- new ZtdQuery\Platform\Postgres\PgSqlSessionFactory::create() packages/ztd-query-postgres/src/PgSqlSessionFactory.php:83
- new ZtdQuery\Platform\Sqlite\SqliteSessionFactory::create() packages/ztd-query-sqlite/src/SqliteSessionFactory.php:76