Skip to content

Commit

Permalink
Remove deprecated lock-related methods
Browse files Browse the repository at this point in the history
  • Loading branch information
derrabus committed Nov 11, 2023
1 parent 304e3ec commit a25a404
Show file tree
Hide file tree
Showing 12 changed files with 18 additions and 106 deletions.
13 changes: 10 additions & 3 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ awareness about deprecated code.

# Upgrade to 4.0

## BC BREAK: Removed lock-related `AbstractPlatform` methods

The methods `AbstractPlatform::getReadLockSQL()`, `::getWriteLockSQL()` and `::getForUpdateSQL()` have been removed
Use `QueryBuilder::forUpdate()` as a replacement for the latter.

## BC BREAK: BIGINT vales are cast to int if possible

`BigIntType` casts values retrieved from the database to int if they're inside
Expand Down Expand Up @@ -215,9 +220,11 @@ The following classes have been converted to enums:
1. `Doctrine\DBAL\ColumnCase`,
2. `Doctrine\DBAL\LockMode`,
3. `Doctrine\DBAL\ParameterType`,
4. `Doctrine\DBAL\TransactionIsolationLevel`,
5. `Doctrine\DBAL\Platforms\DateIntervalUnit`,
6. `Doctrine\DBAL\Platforms\TrimMode`.
4. `Doctrine\DBAL\ArrayParameterType`,
5. `Doctrine\DBAL\TransactionIsolationLevel`,
6. `Doctrine\DBAL\Platforms\DateIntervalUnit`,
7. `Doctrine\DBAL\Platforms\TrimMode`.
8. `Doctrine\DBAL\Query\ForUpdate\ConflictResolutionMode`

The corresponding class constants are now instances of their enum type.

Expand Down
4 changes: 0 additions & 4 deletions psalm.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@

<!-- TODO for PHPUnit 11 -->
<referencedMethod name="PHPUnit\Framework\TestCase::iniSet"/>

<!-- TODO: remove in 4.0.0 -->
<referencedMethod name="Doctrine\DBAL\Platforms\AbstractPlatform::getForUpdateSQL"/>
<referencedMethod name="Doctrine\DBAL\Platforms\DB2Platform::getForUpdateSQL"/>
</errorLevel>
</DeprecatedMethod>
<DocblockTypeContradiction>
Expand Down
5 changes: 0 additions & 5 deletions src/Platforms/AbstractMySQLPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -739,11 +739,6 @@ public function getSetTransactionIsolationSQL(TransactionIsolationLevel $level):
return 'SET SESSION TRANSACTION ISOLATION LEVEL ' . $this->_getTransactionIsolationLevelSQL($level);
}

public function getReadLockSQL(): string
{
return 'LOCK IN SHARE MODE';
}

protected function initializeDoctrineTypeMappings(): void
{
$this->doctrineTypeMapping = [
Expand Down
56 changes: 0 additions & 56 deletions src/Platforms/AbstractPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -701,23 +701,6 @@ public function getBitOrComparisonExpression(string $value1, string $value2): st
*/
abstract public function getCurrentDatabaseExpression(): string;

/**
* Returns the FOR UPDATE expression.
*
* @deprecated This API is not portable. Use {@link QueryBuilder::forUpdate()}` instead.
*/
public function getForUpdateSQL(): string
{
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/6191',
'%s is deprecated as non-portable.',
__METHOD__,
);

return 'FOR UPDATE';
}

/**
* Honors that some SQL vendors such as MsSql use table hints for locking instead of the
* ANSI SQL FOR UPDATE specification.
Expand All @@ -729,45 +712,6 @@ public function appendLockHint(string $fromClause, LockMode $lockMode): string
return $fromClause;
}

/**
* Returns the SQL snippet to append to any SELECT statement which locks rows in shared read lock.
*
* This defaults to the ANSI SQL "FOR UPDATE", which is an exclusive lock (Write). Some database
* vendors allow to lighten this constraint up to be a real read lock.
*
* @deprecated This API is not portable.
*/
public function getReadLockSQL(): string
{
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/6191',
'%s is deprecated as non-portable.',
__METHOD__,
);

return $this->getForUpdateSQL();
}

/**
* Returns the SQL snippet to append to any SELECT statement which obtains an exclusive lock on the rows.
*
* The semantics of this lock mode should equal the SELECT .. FOR UPDATE of the ANSI SQL standard.
*
* @deprecated This API is not portable.
*/
public function getWriteLockSQL(): string
{
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/6191',
'%s is deprecated as non-portable.',
__METHOD__,
);

return $this->getForUpdateSQL();
}

/**
* Returns the SQL snippet to drop an existing table.
*/
Expand Down
6 changes: 0 additions & 6 deletions src/Platforms/DB2Platform.php
Original file line number Diff line number Diff line change
Expand Up @@ -564,12 +564,6 @@ public function createSelectSQLBuilder(): SelectSQLBuilder
return new DefaultSelectSQLBuilder($this, 'WITH RR USE AND KEEP UPDATE LOCKS', null);
}

/** @deprecated This API is not portable. */
public function getForUpdateSQL(): string
{
return ' WITH RR USE AND KEEP UPDATE LOCKS';
}

public function getDummySelectSQL(string $expression = '1'): string
{
return sprintf('SELECT %s FROM sysibm.sysdummy1', $expression);
Expand Down
5 changes: 0 additions & 5 deletions src/Platforms/PostgreSQLPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -685,11 +685,6 @@ public function getTruncateTableSQL(string $tableName, bool $cascade = false): s
return $sql;
}

public function getReadLockSQL(): string
{
return 'FOR SHARE';
}

protected function initializeDoctrineTypeMappings(): void
{
$this->doctrineTypeMapping = [
Expand Down
6 changes: 0 additions & 6 deletions src/Platforms/SQLServerPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -1096,12 +1096,6 @@ public function appendLockHint(string $fromClause, LockMode $lockMode): string
};
}

/** @deprecated This API is not portable. */
public function getForUpdateSQL(): string
{
return ' ';
}

protected function createReservedKeywordsList(): KeywordList
{
return new SQLServerKeywords();
Expand Down
5 changes: 0 additions & 5 deletions src/Platforms/SQLitePlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -415,11 +415,6 @@ public function getTruncateTableSQL(string $tableName, bool $cascade = false): s
return 'DELETE FROM ' . $tableIdentifier->getQuotedName($this);
}

public function getForUpdateSQL(): string
{
return '';
}

/** @internal The method should be only used from within the {@see AbstractPlatform} class hierarchy. */
public function getInlineColumnCommentSQL(string $comment): string
{
Expand Down
6 changes: 4 additions & 2 deletions src/Query/ForUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@

namespace Doctrine\DBAL\Query;

use Doctrine\DBAL\Query\ForUpdate\ConflictResolutionMode;

/** @internal */
final class ForUpdate
{
public function __construct(
private readonly int $conflictResolutionMode,
private readonly ConflictResolutionMode $conflictResolutionMode,
) {
}

public function getConflictResolutionMode(): int
public function getConflictResolutionMode(): ConflictResolutionMode
{
return $this->conflictResolutionMode;
}
Expand Down
15 changes: 3 additions & 12 deletions src/Query/ForUpdate/ConflictResolutionMode.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,15 @@

namespace Doctrine\DBAL\Query\ForUpdate;

final class ConflictResolutionMode
enum ConflictResolutionMode
{
/**
* Wait for the row to be unlocked
*/
public const ORDINARY = 0;
case ORDINARY;

/**
* Skip the row if it is locked
*/
public const SKIP_LOCKED = 1;

/**
* This class cannot be instantiated.
*
* @codeCoverageIgnore
*/
private function __construct()
{
}
case SKIP_LOCKED;
}
2 changes: 1 addition & 1 deletion src/Query/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ public function getMaxResults(): ?int
*
* @return $this
*/
public function forUpdate(int $conflictResolutionMode = ConflictResolutionMode::ORDINARY): self
public function forUpdate(ConflictResolutionMode $conflictResolutionMode = ConflictResolutionMode::ORDINARY): self
{
$this->forUpdate = new ForUpdate($conflictResolutionMode);

Expand Down
1 change: 0 additions & 1 deletion tests/Platforms/DB2PlatformTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,6 @@ public function testGeneratesSQLSnippets(): void
);

self::assertEquals("'1987/05/02' - 10 YEAR", $this->platform->getDateSubYearsExpression("'1987/05/02'", '10'));
self::assertEquals(' WITH RR USE AND KEEP UPDATE LOCKS', $this->platform->getForUpdateSQL());

self::assertEquals(
'LOCATE(substring_column, string_column)',
Expand Down

0 comments on commit a25a404

Please sign in to comment.