summaryrefslogtreecommitdiff
path: root/vendor/doctrine/orm/src/Utility/LockSqlHelper.php
blob: 7d135eb8cb52fe4443b6e66421b04cf5ffd49ba4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php

declare(strict_types=1);

namespace Doctrine\ORM\Utility;

use Doctrine\DBAL\Platforms\AbstractMySQLPlatform;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\DB2Platform;
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
use Doctrine\DBAL\Platforms\SQLitePlatform;
use Doctrine\DBAL\Platforms\SQLServerPlatform;

/** @internal */
trait LockSqlHelper
{
    private function getReadLockSQL(AbstractPlatform $platform): string
    {
        return match (true) {
            $platform instanceof AbstractMySQLPlatform => 'LOCK IN SHARE MODE',
            $platform instanceof PostgreSQLPlatform => 'FOR SHARE',
            default => $this->getWriteLockSQL($platform),
        };
    }

    private function getWriteLockSQL(AbstractPlatform $platform): string
    {
        return match (true) {
            $platform instanceof DB2Platform => 'WITH RR USE AND KEEP UPDATE LOCKS',
            $platform instanceof SQLitePlatform,
            $platform instanceof SQLServerPlatform => '',
            default => 'FOR UPDATE',
        };
    }
}