function DoctrineDbalPostgreSqlStore::save
Overrides PersistingStoreInterface::save
File
-
vendor/
symfony/ lock/ Store/ DoctrineDbalPostgreSqlStore.php, line 74
Class
- DoctrineDbalPostgreSqlStore
- DoctrineDbalPostgreSqlStore is a PersistingStoreInterface implementation using PostgreSql advisory locks with a Doctrine DBAL Connection.
Namespace
Symfony\Component\Lock\StoreCode
public function save(Key $key) : void {
// prevent concurrency within the same connection
$this->getInternalStore()
->save($key);
$lockAcquired = false;
try {
$sql = 'SELECT pg_try_advisory_lock(:key)';
$result = $this->conn
->executeQuery($sql, [
'key' => $this->getHashedKey($key),
]);
// Check if lock is acquired
if (true === $result->fetchOne()) {
$key->markUnserializable();
// release sharedLock in case of promotion
$this->unlockShared($key);
$lockAcquired = true;
return;
}
} finally {
if (!$lockAcquired) {
$this->getInternalStore()
->delete($key);
}
}
throw new LockConflictedException();
}