classShadowIdentityAllocator
final class ShadowIdentityAllocator
Hands out the identity values a database would have assigned.
Nothing is inserted, so nothing counts rows for us. A statement that omits an AUTO_INCREMENT column still has to read back with one, and two statements in the same session must not be given the same number, so the next value per table and column is kept here.
A projection is where a rewritten statement works out what it would have written. It is allocated against a copy so that a projection thrown away takes its numbers with it, and only a committed one moves the counter on.
Type Aliases§
Row = import from TableDefinitionRowValue = import from TableDefinitionMethods§
public function beginProjection(): voidBegin projection.
Test cases 9
ShadowIdentityAllocatorTest::testBeginProjectionDiscardsWhatAProjectionNeverCommittedcallsShadowIdentityAllocatorTest::testBeginProjectionStartsFromWhatWasCommittedcallsShadowIdentityAllocatorTest::testCommitProjectionBeginProjectionUncommittedPreparationDoesNotConsumeIdentitycallsInsertProjectionBuilderTest::testBuildInsertRowSelectFillsDefaultsAndAppliesColumnTypescallsInsertProjectionBuilderTest::testBuildInsertSelectProjectsMultipleRowsWithGeneratedIdentitycallsInsertProjectionBuilderTest::testBuildInsertSelectRejectsMismatchedRowCardinalitycallsInsertProjectionBuilderTest::testBuildSelectSourceProjectsAnInsertSelectSourcecallsSelectProjectionTest::testRenderProjectsGeneratedIdentityAndSourceColumnscallsValueProjectionTest::testRenderPreservesSequenceProgressAcrossCommittedProjectionscalls
Called from 3
- method-call ZtdQuery\Platform\MySql\Rewrite\Transformer\InsertTransformer::transform() packages/ztd-query-mysql/src/Rewrite/Transformer/InsertTransformer.php:58
- method-call ZtdQuery\Platform\Postgres\Rewrite\Transformer\InsertTransformer::transform() packages/ztd-query-postgres/src/Rewrite/Transformer/InsertTransformer.php:55
- method-call ZtdQuery\Platform\Sqlite\Rewrite\Transformer\InsertTransformer::transform() packages/ztd-query-sqlite/src/Rewrite/Transformer/InsertTransformer.php:62
public function commitProjection(): voidCommit projection.
Test cases 3
Called from 3
- method-call ZtdQuery\Platform\MySql\Rewrite\Transformer\InsertTransformer::commitRewriteState() packages/ztd-query-mysql/src/Rewrite/Transformer/InsertTransformer.php:90
- method-call ZtdQuery\Platform\Postgres\Rewrite\Transformer\InsertTransformer::commitRewriteState() packages/ztd-query-postgres/src/Rewrite/Transformer/InsertTransformer.php:93
- method-call ZtdQuery\Platform\Sqlite\Rewrite\Transformer\InsertTransformer::commitRewriteState() packages/ztd-query-sqlite/src/Rewrite/Transformer/InsertTransformer.php:113
public function allocateMissing(
string $table,
array<string, IdentityGenerationStrategy> $strategies,
list<string> $providedColumns,
array<int, Row> $existingRows,
): array<string, int>Parameters
$table | string | |
$strategies | array<string, IdentityGenerationStrategy> | |
$providedColumns | list<string> | |
$existingRows | array<int, Row> |
Returns
array<string, int>Test cases 11
ShadowIdentityAllocatorTest::testAllocateMissingLeavesAColumnTheStatementWroteAlonecallsShadowIdentityAllocatorTest::testBeginProjectionDiscardsWhatAProjectionNeverCommittedcallsShadowIdentityAllocatorTest::testBeginProjectionStartsFromWhatWasCommittedcallsShadowIdentityAllocatorTest::testCommitProjectionBeginProjectionUncommittedPreparationDoesNotConsumeIdentitycallsShadowIdentityAllocatorTest::testExplicitIdentityDoesNotPreventOtherIdentitiesFromBeingAllocatedcallsShadowIdentityAllocatorTest::testGeneratedStateIsSeparatedByTableAndColumncallsShadowIdentityAllocatorTest::testMaxValueIdentityAdvancesPastRowsAndSurvivesDeletioncallsShadowIdentityAllocatorTest::testMaxValueUsesOnlyIntegerRowscallsShadowIdentityAllocatorTest::testSelectAllocationContinuesFromMaterializedRowscallsShadowIdentityAllocatorTest::testSelectAllocationUsesStrategyStateAndAllColumnscallsShadowIdentityAllocatorTest::testSequenceIdentityDoesNotUseExplicitRowMaximumcalls
Called from 4
- method-call ZtdQuery\Platform\MySql\Rewrite\Transformer\Insert\ResultProjection::buildInsertRowSelect() packages/ztd-query-mysql/src/Rewrite/Transformer/Insert/ResultProjection.php:86
- method-call ZtdQuery\Platform\MySql\Rewrite\Transformer\Insert\ResultProjection::buildInsertSetSelect() packages/ztd-query-mysql/src/Rewrite/Transformer/Insert/ResultProjection.php:121
- method-call ZtdQuery\Platform\Postgres\Rewrite\Transformer\Insert\ValueProjection::render() packages/ztd-query-postgres/src/Rewrite/Transformer/Insert/ValueProjection.php:59
- method-call ZtdQuery\Platform\Sqlite\Rewrite\Transformer\Insert\InsertProjectionBuilder::buildInsertRowSelect() packages/ztd-query-sqlite/src/Rewrite/Transformer/Insert/InsertProjectionBuilder.php:124
Calls 2
- function-call
in_arrayline 65 - method-call ShadowIdentityAllocator::nextValue() line 69
public function allocateSelectStarts(
string $table,
array<string, IdentityGenerationStrategy> $strategies,
list<string> $providedColumns,
array<int, Row> $existingRows,
): array<string, int>Parameters
$table | string | |
$strategies | array<string, IdentityGenerationStrategy> | |
$providedColumns | list<string> | |
$existingRows | array<int, Row> |
Returns
array<string, int>Test cases 5
ShadowIdentityAllocatorTest::testAllocateSelectStartsAnswersTheFirstNumberTheQueryWouldTakecallsShadowIdentityAllocatorTest::testAllocateSelectStartsLeavesAColumnTheStatementWroteAlonecallsShadowIdentityAllocatorTest::testSelectAllocationContinuesFromMaterializedRowscallsShadowIdentityAllocatorTest::testSelectAllocationSkipsProvidedIdentityColumnscallsShadowIdentityAllocatorTest::testSelectAllocationUsesStrategyStateAndAllColumnscalls
Called from 4
- method-call ZtdQuery\Platform\MySql\Rewrite\Transformer\Insert\ResultProjection::buildInsertSourceSelect() packages/ztd-query-mysql/src/Rewrite/Transformer/Insert/ResultProjection.php:146
- method-call ZtdQuery\Platform\Postgres\Rewrite\Transformer\Insert\SelectProjection::render() packages/ztd-query-postgres/src/Rewrite/Transformer/Insert/SelectProjection.php:45
- method-call ZtdQuery\Platform\Postgres\Rewrite\Transformer\Merge\RowActions::insertedRows() packages/ztd-query-postgres/src/Rewrite/Transformer/Merge/RowActions.php:148
- method-call ZtdQuery\Platform\Sqlite\Rewrite\Transformer\Insert\InsertProjectionBuilder::buildSelectSource() packages/ztd-query-sqlite/src/Rewrite/Transformer/Insert/InsertProjectionBuilder.php:184
Calls 2
- function-call
in_arrayline 91 - method-call ShadowIdentityAllocator::nextValue() line 94
public function nextValue(
string $table,
string $column,
IdentityGenerationStrategy $strategy,
array<int, Row> $existingRows,
): intAnswers the value a generated column would take next.
A column the database derives from the greatest value present has to be read off the rows every time. One that simply counts up is read off the rows only once it has been handed out here before, because until then the rows are all there is to go on.
Parameters
$table | string | Table the column belongs to |
$column | string | Column the value is generated for |
$strategy | IdentityGenerationStrategy | How the database decides the value |
$existingRows | array<int, Row> | Rows the table already holds |
Returns
int The value the column would take nextTest cases 2
Called from 2
Calls 2
- class-const IdentityGenerationStrategy::MaxValue() line 124
- method-call ShadowIdentityAllocator::nextAfterExistingRows() line 125
public function nextAfterExistingRows(string $column, array<int, Row> $rows, int $next): intParameters
$column | string | |
$rows | array<int, Row> | |
$next | int |
Returns
intTest cases 2
Called from 2
Calls 2
- method-call ShadowIdentityAllocator::integerValue() line 140
- function-call
maxline 142
public function integerValue(mixed $value): int|nullAnswers the whole number a value stands for, if it stands for one.
A driver may answer an integer column as its text, so text that spells a whole number counts. Anything else does not stand for a number the table would have generated, and answers nothing rather than nought.
Parameters
$value | mixed | Value as the driver answered it |
Returns
int|null The number, or null where the value is not oneTest cases 2
Called from 1
Private surface 2§
Implementation details, listed for orientation only.
private array<string, array<string, int>> $committedNextValues = []private array<string, array<string, int>> $projectionNextValues = []Test cases 30§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 20
ShadowIdentityAllocatorTest::testAllocateMissingLeavesAColumnTheStatementWroteAlonecallsShadowIdentityAllocatorTest::testAllocateSelectStartsAnswersTheFirstNumberTheQueryWouldTakecallsShadowIdentityAllocatorTest::testAllocateSelectStartsLeavesAColumnTheStatementWroteAlonecallsShadowIdentityAllocatorTest::testBeginProjectionDiscardsWhatAProjectionNeverCommittedcallsShadowIdentityAllocatorTest::testBeginProjectionStartsFromWhatWasCommittedcallsShadowIdentityAllocatorTest::testCommitProjectionBeginProjectionUncommittedPreparationDoesNotConsumeIdentitycallsShadowIdentityAllocatorTest::testExplicitIdentityDoesNotPreventOtherIdentitiesFromBeingAllocatedcallsShadowIdentityAllocatorTest::testGeneratedStateIsSeparatedByTableAndColumncallsShadowIdentityAllocatorTest::testIntegerValueIsNothingForAValueThatIsNotAWholeNumbercallsShadowIdentityAllocatorTest::testIntegerValueReadsANumberHoweverTheDriverSpelledItcallsShadowIdentityAllocatorTest::testMaxValueIdentityAdvancesPastRowsAndSurvivesDeletioncallsShadowIdentityAllocatorTest::testMaxValueUsesOnlyIntegerRowscallsShadowIdentityAllocatorTest::testNextAfterExistingRowsGoesPastTheLargestNumberAlreadyTherecallsShadowIdentityAllocatorTest::testNextAfterExistingRowsKeepsTheNumberItWasGivenWhereNothingIsLargercallsShadowIdentityAllocatorTest::testNextValueReadsAMaxValueColumnOffTheRowsEveryTimecallsShadowIdentityAllocatorTest::testNextValueStartsASequenceAtOneHoweverManyRowsAreTherecallsShadowIdentityAllocatorTest::testSelectAllocationContinuesFromMaterializedRowscallsShadowIdentityAllocatorTest::testSelectAllocationSkipsProvidedIdentityColumnscallsShadowIdentityAllocatorTest::testSelectAllocationUsesStrategyStateAndAllColumnscallsShadowIdentityAllocatorTest::testSequenceIdentityDoesNotUseExplicitRowMaximumcalls
Other tests reaching this symbol 10
InsertProjectionBuilderTest::testBuildInsertRowSelectFillsDefaultsAndAppliesColumnTypescallsInsertProjectionBuilderTest::testBuildInsertSelectProjectsMultipleRowsWithGeneratedIdentitycallsInsertProjectionBuilderTest::testBuildInsertSelectRejectsMismatchedRowCardinalitycallsInsertProjectionBuilderTest::testBuildSelectSourceProjectsAnInsertSelectSourcecallsResultProjectionTest::testBuildInsertRowSelectcallsResultProjectionTest::testBuildInsertSelectcallsResultProjectionTest::testBuildInsertSetSelectcallsResultProjectionTest::testBuildInsertSourceSelectCastsDestinationColumnscallsSelectProjectionTest::testRenderProjectsGeneratedIdentityAndSourceColumnscallsValueProjectionTest::testRenderPreservesSequenceProgressAcrossCommittedProjectionscalls
Relations§
Instantiated in 4
- new ZtdQuery\Platform\MySql\Rewrite\Transformer\InsertTransformer::__construct() packages/ztd-query-mysql/src/Rewrite/Transformer/InsertTransformer.php:46
- new ZtdQuery\Platform\Postgres\Rewrite\Transformer\InsertTransformer::__construct() packages/ztd-query-postgres/src/Rewrite/Transformer/InsertTransformer.php:43
- new ZtdQuery\Platform\Postgres\Rewrite\Transformer\Merge\RowActions::insertedRows() packages/ztd-query-postgres/src/Rewrite/Transformer/Merge/RowActions.php:148
- new ZtdQuery\Platform\Sqlite\Rewrite\Transformer\InsertTransformer::__construct() packages/ztd-query-sqlite/src/Rewrite/Transformer/InsertTransformer.php:50
Method calls 14
- method-call ZtdQuery\Platform\MySql\Rewrite\Transformer\Insert\ResultProjection::buildInsertRowSelect() packages/ztd-query-mysql/src/Rewrite/Transformer/Insert/ResultProjection.php:86
- method-call ZtdQuery\Platform\MySql\Rewrite\Transformer\Insert\ResultProjection::buildInsertSetSelect() packages/ztd-query-mysql/src/Rewrite/Transformer/Insert/ResultProjection.php:121
- method-call ZtdQuery\Platform\MySql\Rewrite\Transformer\Insert\ResultProjection::buildInsertSourceSelect() packages/ztd-query-mysql/src/Rewrite/Transformer/Insert/ResultProjection.php:146
- method-call ZtdQuery\Platform\MySql\Rewrite\Transformer\InsertTransformer::transform() packages/ztd-query-mysql/src/Rewrite/Transformer/InsertTransformer.php:58
- method-call ZtdQuery\Platform\MySql\Rewrite\Transformer\InsertTransformer::commitRewriteState() packages/ztd-query-mysql/src/Rewrite/Transformer/InsertTransformer.php:90
- method-call ZtdQuery\Platform\Postgres\Rewrite\Transformer\Insert\SelectProjection::render() packages/ztd-query-postgres/src/Rewrite/Transformer/Insert/SelectProjection.php:45
- method-call ZtdQuery\Platform\Postgres\Rewrite\Transformer\Insert\ValueProjection::render() packages/ztd-query-postgres/src/Rewrite/Transformer/Insert/ValueProjection.php:59
- method-call ZtdQuery\Platform\Postgres\Rewrite\Transformer\InsertTransformer::transform() packages/ztd-query-postgres/src/Rewrite/Transformer/InsertTransformer.php:55
- method-call ZtdQuery\Platform\Postgres\Rewrite\Transformer\InsertTransformer::commitRewriteState() packages/ztd-query-postgres/src/Rewrite/Transformer/InsertTransformer.php:93
- method-call ZtdQuery\Platform\Postgres\Rewrite\Transformer\Merge\RowActions::insertedRows() packages/ztd-query-postgres/src/Rewrite/Transformer/Merge/RowActions.php:148
- method-call ZtdQuery\Platform\Sqlite\Rewrite\Transformer\Insert\InsertProjectionBuilder::buildInsertRowSelect() packages/ztd-query-sqlite/src/Rewrite/Transformer/Insert/InsertProjectionBuilder.php:124
- method-call ZtdQuery\Platform\Sqlite\Rewrite\Transformer\Insert\InsertProjectionBuilder::buildSelectSource() packages/ztd-query-sqlite/src/Rewrite/Transformer/Insert/InsertProjectionBuilder.php:184
- method-call ZtdQuery\Platform\Sqlite\Rewrite\Transformer\InsertTransformer::transform() packages/ztd-query-sqlite/src/Rewrite/Transformer/InsertTransformer.php:62
- method-call ZtdQuery\Platform\Sqlite\Rewrite\Transformer\InsertTransformer::commitRewriteState() packages/ztd-query-sqlite/src/Rewrite/Transformer/InsertTransformer.php:113
Type declarations 7
- type ZtdQuery\Platform\MySql\Rewrite\Transformer\Insert\ResultProjection packages/ztd-query-mysql/src/Rewrite/Transformer/Insert/ResultProjection.php:28
- type ZtdQuery\Platform\MySql\Rewrite\Transformer\InsertTransformer packages/ztd-query-mysql/src/Rewrite/Transformer/InsertTransformer.php:29
- type ZtdQuery\Platform\Postgres\Rewrite\Transformer\Insert\SelectProjection packages/ztd-query-postgres/src/Rewrite/Transformer/Insert/SelectProjection.php:23
- type ZtdQuery\Platform\Postgres\Rewrite\Transformer\Insert\ValueProjection packages/ztd-query-postgres/src/Rewrite/Transformer/Insert/ValueProjection.php:26
- type ZtdQuery\Platform\Postgres\Rewrite\Transformer\InsertTransformer packages/ztd-query-postgres/src/Rewrite/Transformer/InsertTransformer.php:26
- type ZtdQuery\Platform\Sqlite\Rewrite\Transformer\Insert\InsertProjectionBuilder packages/ztd-query-sqlite/src/Rewrite/Transformer/Insert/InsertProjectionBuilder.php:30
- type ZtdQuery\Platform\Sqlite\Rewrite\Transformer\InsertTransformer packages/ztd-query-sqlite/src/Rewrite/Transformer/InsertTransformer.php:33