Documentation

Transaction
in package

Description of Transaction

Tags
author

zozlak

Table of Contents

Constants

LOCK_TIMEOUT_DEFAULT  = 10000
PG_DEADLOCK  = '40P01'
PG_DUPLICATE_KEY  = '23505'
PG_FOREIGN_KEY_VIOLATION  = '23503'
PG_LOCK_FAILURE  = '55P03'
PG_WRONG_BINARY_VALUE  = '22P03'
PG_WRONG_DATE_VALUE  = '22007'
PG_WRONG_TEXT_VALUE  = '22P02'
STATE_ACTIVE  = 'active'
STATE_COMMIT  = 'commit'
STATE_LOCKED  = 'locked'
STATE_NOTX  = 'notx'
STATE_ROLLBACK  = 'rollback'
STMT_TIMEOUT_DEFAULT  = 60000

Properties

$id  : int|null
$lastRequest  : string
$lockedResources  : bool
$pdo  : PDO
Database connection.
$snapshot  : string
$startedAt  : string
$state  : string

Methods

__construct()  : mixed
createResource()  : int
delete()  : void
deleteResource()  : void
get()  : void
getId()  : int|null
getPreTransactionDbHandle()  : PDO
getState()  : string|null
head()  : void
lockResource()  : string|null
Locks a given resource with a given lock id and the current transaction id.
options()  : void
post()  : void
prolong()  : void
put()  : void
unlockResources()  : void
executeQuery()  : void
Executes a given PDO statement trapping the lock timeout and foreign key database exceptions and turning them it into the `ConflictException`.
fetchData()  : void
getResourceList()  : array<string|int, int>
lock()  : void
Tries to lock the current transaction.
releaseAndWait()  : void
Actively waits until the transaction controller daemon rollbacks/commits the transaction
setState()  : void

Constants

LOCK_TIMEOUT_DEFAULT

public mixed LOCK_TIMEOUT_DEFAULT = 10000

PG_DUPLICATE_KEY

public mixed PG_DUPLICATE_KEY = '23505'

PG_FOREIGN_KEY_VIOLATION

public mixed PG_FOREIGN_KEY_VIOLATION = '23503'

PG_LOCK_FAILURE

public mixed PG_LOCK_FAILURE = '55P03'

PG_WRONG_BINARY_VALUE

public mixed PG_WRONG_BINARY_VALUE = '22P03'

PG_WRONG_DATE_VALUE

public mixed PG_WRONG_DATE_VALUE = '22007'

PG_WRONG_TEXT_VALUE

public mixed PG_WRONG_TEXT_VALUE = '22P02'

STATE_ROLLBACK

public mixed STATE_ROLLBACK = 'rollback'

STMT_TIMEOUT_DEFAULT

public mixed STMT_TIMEOUT_DEFAULT = 60000

Properties

$lockedResources

private bool $lockedResources = false

$pdo

Database connection.

private PDO $pdo

A separate is required so it can commit changes independently from the main connection.

Methods

createResource()

public createResource(int $lockId[, array<string|int, string> $ids = [] ]) : int
Parameters
$lockId : int
$ids : array<string|int, string> = []
Tags
throws
RuntimeException
throws
DuplicatedKeyException
throws
PDOException
Return values
int

deleteResource()

public deleteResource(int $resId) : void
Parameters
$resId : int

getId()

public getId() : int|null
Return values
int|null

getPreTransactionDbHandle()

public getPreTransactionDbHandle() : PDO
Return values
PDO

getState()

public getState() : string|null
Return values
string|null

head()

public head([bool $get = false ]) : void
Parameters
$get : bool = false

lockResource()

Locks a given resource with a given lock id and the current transaction id.

public lockResource(int $resId, int $lockId) : string|null
  • First a database lock on the transaction is obtained with $this->lock(false).
  • Then a database lock on the resource is obtained and the resource is marked as arche-locked by setting up transaction_id and lock column values
  • Finally the database transaction is commited.
Parameters
$resId : int
$lockId : int
Tags
throws
RuntimeException
throws
BadRequestException
throws
ConflictException
Return values
string|null

options()

public options([int $code = 204 ]) : void
Parameters
$code : int = 204

unlockResources()

public unlockResources(int $lockId) : void
Parameters
$lockId : int

executeQuery()

Executes a given PDO statement trapping the lock timeout and foreign key database exceptions and turning them it into the `ConflictException`.

private executeQuery(PDOStatement $query, array<string|int, mixed> $param[, string $errorMsg = "Database lock timeout" ][, bool $logException = false ]) : void
Parameters
$query : PDOStatement
$param : array<string|int, mixed>
$errorMsg : string = "Database lock timeout"
$logException : bool = false
Tags
throws
ConflictException
throws
PDOException

getResourceList()

private getResourceList() : array<string|int, int>
Return values
array<string|int, int>

lock()

Tries to lock the current transaction.

private lock([bool $checkResourceLocks = true ]) : void

Assures no other transaction PUT(commit)/DELETE(rollback) is executed in parallel. Will succeed only if there's no this transaction related resource operation being executed.

Lock persists until $this->pdo->commit()/rollBack();

Parameters
$checkResourceLocks : bool = true
Tags
throws
ConflictException
throws
PDOException

releaseAndWait()

Actively waits until the transaction controller daemon rollbacks/commits the transaction

private releaseAndWait() : void

setState()

private setState(string $state) : void
Parameters
$state : string

        
On this page

Search results