class DatabaseTransactionsManager

Manages database transaction callbacks in a coroutine-safe manner.

Uses Context to store transaction state per-coroutine, ensuring that concurrent requests don't interfere with each other's transactions.

Constants

protected COMMITTED_CONTEXT_KEY

protected PENDING_CONTEXT_KEY

protected CURRENT_CONTEXT_KEY

Methods

getCommittedTransactionsInternal()

Get all committed transactions for the current coroutine.

void
setCommittedTransactions(Collection $transactions)

Set committed transactions for the current coroutine.

getPendingTransactionsInternal()

Get all pending transactions for the current coroutine.

void
setPendingTransactions(Collection $transactions)

Set pending transactions for the current coroutine.

array
getCurrentTransaction()

Get current transaction map for the current coroutine.

void
setCurrentTransactionForConnection(string $connection, DatabaseTransactionRecord|null $transaction)

Set current transaction for a connection.

getCurrentTransactionForConnection(string $connection)

Get current transaction for a connection.

void
begin(string $connection, int $level)

Start a new database transaction.

commit(string $connection, int $levelBeingCommitted, int $newTransactionLevel)

Commit the root database transaction and execute callbacks.

void
stageTransactions(string $connection, int $levelBeingCommitted)

Move relevant pending transactions to a committed state.

void
rollback(string $connection, int $newTransactionLevel)

Rollback the active database transaction.

void
removeAllTransactionsForConnection(string $connection)

Remove all pending, completed, and current transactions for the given connection name.

removeCommittedTransactionsThatAreChildrenOf(DatabaseTransactionRecord $transaction)

Remove and return all committed descendants of the given transaction.

void
executeRollbackCallbacks(Collection $transactions)

Execute rollback callbacks for every detached transaction.

void
addCallback(callable $callback)

Register a transaction callback.

void
addCallbackForRollback(callable $callback)

Register a callback for transaction rollback.

callbackApplicableTransactions()

Get the transactions that are applicable to callbacks.

bool
afterCommitCallbacksShouldBeExecuted(int $level)

Determine if after commit callbacks should be executed for the given transaction level.

getPendingTransactions()

Get all of the pending transactions.

getCommittedTransactions()

Get all of the committed transactions.

static bool
hasNonCoroutinePendingTransactions()

Check whether there are pending transactions in non-coroutine storage.

static void
copyToNonCoroutineState()

Copy transaction state from the current coroutine to non-coroutine storage.

static void
clearNonCoroutineState()

Clear all transaction state from non-coroutine storage.

Details

at line 30
protected Collection getCommittedTransactionsInternal()

Get all committed transactions for the current coroutine.

Return Value

Collection

at line 40
protected void setCommittedTransactions(Collection $transactions)

Set committed transactions for the current coroutine.

Parameters

Collection $transactions

Return Value

void

at line 50
protected Collection getPendingTransactionsInternal()

Get all pending transactions for the current coroutine.

Return Value

Collection

at line 60
protected void setPendingTransactions(Collection $transactions)

Set pending transactions for the current coroutine.

Parameters

Collection $transactions

Return Value

void

at line 70
protected array getCurrentTransaction()

Get current transaction map for the current coroutine.

Return Value

array

at line 78
protected void setCurrentTransactionForConnection(string $connection, DatabaseTransactionRecord|null $transaction)

Set current transaction for a connection.

Parameters

string $connection
DatabaseTransactionRecord|null $transaction

Return Value

void

at line 88
protected DatabaseTransactionRecord|null getCurrentTransactionForConnection(string $connection)

Get current transaction for a connection.

Parameters

string $connection

Return Value

DatabaseTransactionRecord|null

at line 96
void begin(string $connection, int $level)

Start a new database transaction.

Parameters

string $connection
int $level

Return Value

void

at line 116
Collection commit(string $connection, int $levelBeingCommitted, int $newTransactionLevel)

Commit the root database transaction and execute callbacks.

Parameters

string $connection
int $levelBeingCommitted
int $newTransactionLevel

Return Value

Collection

at line 152
void stageTransactions(string $connection, int $levelBeingCommitted)

Move relevant pending transactions to a committed state.

Parameters

string $connection
int $levelBeingCommitted

Return Value

void

at line 175
void rollback(string $connection, int $newTransactionLevel)

Rollback the active database transaction.

Parameters

string $connection
int $newTransactionLevel

Return Value

void

at line 223
protected void removeAllTransactionsForConnection(string $connection)

Remove all pending, completed, and current transactions for the given connection name.

Parameters

string $connection

Return Value

void

at line 263
protected Collection removeCommittedTransactionsThatAreChildrenOf(DatabaseTransactionRecord $transaction)

Remove and return all committed descendants of the given transaction.

Parameters

DatabaseTransactionRecord $transaction

Return Value

Collection

at line 289
protected void executeRollbackCallbacks(Collection $transactions)

Execute rollback callbacks for every detached transaction.

Parameters

Collection $transactions

Return Value

void

at line 309
void addCallback(callable $callback)

Register a transaction callback.

Parameters

callable $callback

Return Value

void

at line 322
void addCallbackForRollback(callable $callback)

Register a callback for transaction rollback.

Parameters

callable $callback

Return Value

void

at line 334
Collection callbackApplicableTransactions()

Get the transactions that are applicable to callbacks.

Return Value

Collection

at line 342
bool afterCommitCallbacksShouldBeExecuted(int $level)

Determine if after commit callbacks should be executed for the given transaction level.

Parameters

int $level

Return Value

bool

at line 352
Collection getPendingTransactions()

Get all of the pending transactions.

Return Value

Collection

at line 362
Collection getCommittedTransactions()

Get all of the committed transactions.

Return Value

Collection

at line 370
static bool hasNonCoroutinePendingTransactions()

Check whether there are pending transactions in non-coroutine storage.

Return Value

bool

at line 383
static void copyToNonCoroutineState()

Copy transaction state from the current coroutine to non-coroutine storage.

Tests only. This copies coroutine-local transaction state into worker-global storage, so request-time use can leak or race across concurrent requests.

Return Value

void

at line 398
static void clearNonCoroutineState()

Clear all transaction state from non-coroutine storage.

Tests only. This mutates worker-global transaction state, so request-time use can race with concurrent requests using the same storage.

Return Value

void