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 3
ShadowIdentityAllocatorTest::testBeginProjectionDiscardsWhatAProjectionNeverCommittedcovers and callsShadowIdentityAllocatorTest::testBeginProjectionStartsFromWhatWasCommittedcovers and callsShadowIdentityAllocatorTest::testCommitProjectionBeginProjectionUncommittedPreparationDoesNotConsumeIdentitycovers and calls
public function commitProjection(): voidCommit projection.
Test cases 2
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::testAllocateMissingLeavesAColumnTheStatementWroteAlonecovers and callsShadowIdentityAllocatorTest::testBeginProjectionDiscardsWhatAProjectionNeverCommittedcovers and callsShadowIdentityAllocatorTest::testBeginProjectionStartsFromWhatWasCommittedcovers and callsShadowIdentityAllocatorTest::testCommitProjectionBeginProjectionUncommittedPreparationDoesNotConsumeIdentitycovers and callsShadowIdentityAllocatorTest::testExplicitIdentityDoesNotPreventOtherIdentitiesFromBeingAllocatedcovers and callsShadowIdentityAllocatorTest::testGeneratedStateIsSeparatedByTableAndColumncovers and callsShadowIdentityAllocatorTest::testMaxValueIdentityAdvancesPastRowsAndSurvivesDeletioncovers and callsShadowIdentityAllocatorTest::testMaxValueUsesOnlyIntegerRowscovers and callsShadowIdentityAllocatorTest::testSelectAllocationContinuesFromMaterializedRowscovers and callsShadowIdentityAllocatorTest::testSelectAllocationUsesStrategyStateAndAllColumnscovers and callsShadowIdentityAllocatorTest::testSequenceIdentityDoesNotUseExplicitRowMaximumcovers and calls
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::testAllocateSelectStartsAnswersTheFirstNumberTheQueryWouldTakecovers and callsShadowIdentityAllocatorTest::testAllocateSelectStartsLeavesAColumnTheStatementWroteAlonecovers and callsShadowIdentityAllocatorTest::testSelectAllocationContinuesFromMaterializedRowscovers and callsShadowIdentityAllocatorTest::testSelectAllocationSkipsProvidedIdentityColumnscovers and callsShadowIdentityAllocatorTest::testSelectAllocationUsesStrategyStateAndAllColumnscovers and calls
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 14
ShadowIdentityAllocatorTest::testAllocateSelectStartsAnswersTheFirstNumberTheQueryWouldTakecoversShadowIdentityAllocatorTest::testBeginProjectionDiscardsWhatAProjectionNeverCommittedcoversShadowIdentityAllocatorTest::testBeginProjectionStartsFromWhatWasCommittedcoversShadowIdentityAllocatorTest::testCommitProjectionBeginProjectionUncommittedPreparationDoesNotConsumeIdentitycoversShadowIdentityAllocatorTest::testExplicitIdentityDoesNotPreventOtherIdentitiesFromBeingAllocatedcoversShadowIdentityAllocatorTest::testGeneratedStateIsSeparatedByTableAndColumncoversShadowIdentityAllocatorTest::testMaxValueIdentityAdvancesPastRowsAndSurvivesDeletioncoversShadowIdentityAllocatorTest::testMaxValueUsesOnlyIntegerRowscoversShadowIdentityAllocatorTest::testNextValueReadsAMaxValueColumnOffTheRowsEveryTimecovers and callsShadowIdentityAllocatorTest::testNextValueStartsASequenceAtOneHoweverManyRowsAreTherecovers and callsShadowIdentityAllocatorTest::testSelectAllocationContinuesFromMaterializedRowscoversShadowIdentityAllocatorTest::testSelectAllocationSkipsProvidedIdentityColumnscoversShadowIdentityAllocatorTest::testSelectAllocationUsesStrategyStateAndAllColumnscoversShadowIdentityAllocatorTest::testSequenceIdentityDoesNotUseExplicitRowMaximumcovers
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 13
ShadowIdentityAllocatorTest::testAllocateSelectStartsAnswersTheFirstNumberTheQueryWouldTakecoversShadowIdentityAllocatorTest::testBeginProjectionStartsFromWhatWasCommittedcoversShadowIdentityAllocatorTest::testCommitProjectionBeginProjectionUncommittedPreparationDoesNotConsumeIdentitycoversShadowIdentityAllocatorTest::testExplicitIdentityDoesNotPreventOtherIdentitiesFromBeingAllocatedcoversShadowIdentityAllocatorTest::testGeneratedStateIsSeparatedByTableAndColumncoversShadowIdentityAllocatorTest::testMaxValueIdentityAdvancesPastRowsAndSurvivesDeletioncoversShadowIdentityAllocatorTest::testMaxValueUsesOnlyIntegerRowscoversShadowIdentityAllocatorTest::testNextAfterExistingRowsGoesPastTheLargestNumberAlreadyTherecovers and callsShadowIdentityAllocatorTest::testNextAfterExistingRowsKeepsTheNumberItWasGivenWhereNothingIsLargercovers and callsShadowIdentityAllocatorTest::testNextValueReadsAMaxValueColumnOffTheRowsEveryTimecoversShadowIdentityAllocatorTest::testSelectAllocationContinuesFromMaterializedRowscoversShadowIdentityAllocatorTest::testSelectAllocationUsesStrategyStateAndAllColumnscoversShadowIdentityAllocatorTest::testSequenceIdentityDoesNotUseExplicitRowMaximumcovers
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 11
ShadowIdentityAllocatorTest::testAllocateSelectStartsAnswersTheFirstNumberTheQueryWouldTakecoversShadowIdentityAllocatorTest::testCommitProjectionBeginProjectionUncommittedPreparationDoesNotConsumeIdentitycoversShadowIdentityAllocatorTest::testIntegerValueIsNothingForAValueThatIsNotAWholeNumbercovers and callsShadowIdentityAllocatorTest::testIntegerValueReadsANumberHoweverTheDriverSpelledItcovers and callsShadowIdentityAllocatorTest::testMaxValueIdentityAdvancesPastRowsAndSurvivesDeletioncoversShadowIdentityAllocatorTest::testMaxValueUsesOnlyIntegerRowscoversShadowIdentityAllocatorTest::testNextAfterExistingRowsGoesPastTheLargestNumberAlreadyTherecoversShadowIdentityAllocatorTest::testNextAfterExistingRowsKeepsTheNumberItWasGivenWhereNothingIsLargercoversShadowIdentityAllocatorTest::testNextValueReadsAMaxValueColumnOffTheRowsEveryTimecoversShadowIdentityAllocatorTest::testSelectAllocationContinuesFromMaterializedRowscoversShadowIdentityAllocatorTest::testSelectAllocationUsesStrategyStateAndAllColumnscovers
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 20§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 20
ShadowIdentityAllocatorTest::testAllocateMissingLeavesAColumnTheStatementWroteAlonecovers and callsShadowIdentityAllocatorTest::testAllocateSelectStartsAnswersTheFirstNumberTheQueryWouldTakecovers and callsShadowIdentityAllocatorTest::testAllocateSelectStartsLeavesAColumnTheStatementWroteAlonecovers and callsShadowIdentityAllocatorTest::testBeginProjectionDiscardsWhatAProjectionNeverCommittedcovers and callsShadowIdentityAllocatorTest::testBeginProjectionStartsFromWhatWasCommittedcovers and callsShadowIdentityAllocatorTest::testCommitProjectionBeginProjectionUncommittedPreparationDoesNotConsumeIdentitycovers and callsShadowIdentityAllocatorTest::testExplicitIdentityDoesNotPreventOtherIdentitiesFromBeingAllocatedcovers and callsShadowIdentityAllocatorTest::testGeneratedStateIsSeparatedByTableAndColumncovers and callsShadowIdentityAllocatorTest::testIntegerValueIsNothingForAValueThatIsNotAWholeNumbercovers and callsShadowIdentityAllocatorTest::testIntegerValueReadsANumberHoweverTheDriverSpelledItcovers and callsShadowIdentityAllocatorTest::testMaxValueIdentityAdvancesPastRowsAndSurvivesDeletioncovers and callsShadowIdentityAllocatorTest::testMaxValueUsesOnlyIntegerRowscovers and callsShadowIdentityAllocatorTest::testNextAfterExistingRowsGoesPastTheLargestNumberAlreadyTherecovers and callsShadowIdentityAllocatorTest::testNextAfterExistingRowsKeepsTheNumberItWasGivenWhereNothingIsLargercovers and callsShadowIdentityAllocatorTest::testNextValueReadsAMaxValueColumnOffTheRowsEveryTimecovers and callsShadowIdentityAllocatorTest::testNextValueStartsASequenceAtOneHoweverManyRowsAreTherecovers and callsShadowIdentityAllocatorTest::testSelectAllocationContinuesFromMaterializedRowscovers and callsShadowIdentityAllocatorTest::testSelectAllocationSkipsProvidedIdentityColumnscovers and callsShadowIdentityAllocatorTest::testSelectAllocationUsesStrategyStateAndAllColumnscovers and callsShadowIdentityAllocatorTest::testSequenceIdentityDoesNotUseExplicitRowMaximumcovers and calls