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 TableDefinition
RowValue = import from TableDefinition

Methods§

public function allocateMissing(
    string $table,
    array<string, IdentityGenerationStrategy> $strategies,
    list<string> $providedColumns,
    array<int, Row> $existingRows,
): array<string, int>
public function allocateSelectStarts(
    string $table,
    array<string, IdentityGenerationStrategy> $strategies,
    list<string> $providedColumns,
    array<int, Row> $existingRows,
): array<string, int>
public function nextValue(
    string $table,
    string $column,
    IdentityGenerationStrategy $strategy,
    array<int, Row> $existingRows,
): int

Answers 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

$tablestringTable the column belongs to
$columnstringColumn the value is generated for
$strategyIdentityGenerationStrategyHow the database decides the value
$existingRowsarray<int, Row>Rows the table already holds

Returns

int The value the column would take next
Test cases 14
Called from 2
Calls 2
public function nextAfterExistingRows(string $column, array<int, Row> $rows, int $next): int

Parameters

$columnstring
$rowsarray<int, Row>
$nextint

Returns

int
Test cases 13
Called from 2
Calls 2
public function integerValue(mixed $value): int|null

Answers 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

$valuemixedValue as the driver answered it

Returns

int|null The number, or null where the value is not one
Test cases 11
Called from 1
Calls 3

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