Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use LockMode::NONE as default lock mode #8341

Open
wants to merge 1 commit into
base: old-prototype-3.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Doctrine\ORM\Cache\Persister\Entity;

use Doctrine\Common\Collections\Criteria;
use Doctrine\DBAL\LockMode;
use Doctrine\ORM\Cache;
use Doctrine\ORM\Cache\CollectionCacheKey;
use Doctrine\ORM\Cache\EntityCacheKey;
Expand Down Expand Up @@ -105,7 +106,7 @@ public function __construct(EntityPersister $persister, Region $region, EntityMa
public function getSelectSQL(
$criteria,
?AssociationMetadata $association = null,
$lockMode = null,
$lockMode = LockMode::NONE,
$limit = null,
$offset = null,
array $orderBy = []
Expand Down Expand Up @@ -360,11 +361,11 @@ public function load(
$entity = null,
?AssociationMetadata $association = null,
array $hints = [],
$lockMode = null,
$lockMode = LockMode::NONE,
$limit = null,
?array $orderBy = null
) {
if ($entity !== null || $association !== null || ! empty($hints) || $lockMode !== null) {
if ($entity !== null || $association !== null || ! empty($hints)) {
return $this->persister->load($criteria, $entity, $association, $hints, $lockMode, $limit, $orderBy);
}

Expand Down Expand Up @@ -642,7 +643,7 @@ public function lock(array $criteria, $lockMode)
/**
* {@inheritdoc}
*/
public function refresh(array $id, $entity, $lockMode = null)
public function refresh(array $id, $entity, $lockMode = LockMode::NONE)
{
$this->persister->refresh($id, $entity, $lockMode);
}
Expand Down
3 changes: 2 additions & 1 deletion lib/Doctrine/ORM/Decorator/EntityManagerDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Doctrine\ORM\Decorator;

use Doctrine\Common\Persistence\ObjectManagerDecorator;
use Doctrine\DBAL\LockMode;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Query\ResultSetMapping;

Expand Down Expand Up @@ -136,7 +137,7 @@ public function lock($entity, $lockMode, $lockVersion = null)
/**
* {@inheritdoc}
*/
public function find($entityName, $id, $lockMode = null, $lockVersion = null)
public function find($entityName, $id, $lockMode = LockMode::NONE, $lockVersion = null)
{
return $this->wrapped->find($entityName, $id, $lockMode, $lockVersion);
}
Expand Down
9 changes: 3 additions & 6 deletions lib/Doctrine/ORM/EntityManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -362,9 +362,7 @@ public function flush()
*
* @param string $entityName The class name of the entity to find.
* @param mixed $id The identity of the entity to find.
* @param int|null $lockMode One of the \Doctrine\DBAL\LockMode::* constants
* or NULL if no specific lock mode should be used
* during the search.
* @param int $lockMode One of the \Doctrine\DBAL\LockMode::* constants.
* @param int|null $lockVersion The version of the entity to find when using
* optimistic locking.
*
Expand All @@ -375,12 +373,12 @@ public function flush()
* @throws TransactionRequiredException
* @throws ORMException
*/
public function find($entityName, $id, $lockMode = null, $lockVersion = null)
public function find($entityName, $id, $lockMode = LockMode::NONE, $lockVersion = null)
{
$class = $this->metadataFactory->getMetadataFor(ltrim($entityName, '\\'));
$className = $class->getClassName();

if ($lockMode !== null) {
if ($lockMode !== LockMode::NONE) {
$this->checkLockRequirements($lockMode, $class);
}

Expand Down Expand Up @@ -431,7 +429,6 @@ public function find($entityName, $id, $lockMode = null, $lockVersion = null)
$this->lock($entity, $lockMode, $lockVersion);
break;

case $lockMode === LockMode::NONE:
case $lockMode === LockMode::PESSIMISTIC_READ:
case $lockMode === LockMode::PESSIMISTIC_WRITE:
$persister = $unitOfWork->getEntityPersister($className);
Expand Down
7 changes: 3 additions & 4 deletions lib/Doctrine/ORM/EntityRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Doctrine\Common\Collections\Selectable;
use Doctrine\Common\Inflector\Inflector;
use Doctrine\Common\Persistence\ObjectRepository;
use Doctrine\DBAL\LockMode;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Query\ResultSetMappingBuilder;
use Doctrine\ORM\Repository\Exception\InvalidMagicMethodCall;
Expand Down Expand Up @@ -91,14 +92,12 @@ public function clear()
* Finds an entity by its primary key / identifier.
*
* @param mixed $id The identifier.
* @param int|null $lockMode One of the \Doctrine\DBAL\LockMode::* constants
* or NULL if no specific lock mode should be used
* during the search.
* @param int $lockMode One of the \Doctrine\DBAL\LockMode::* constants.
* @param int|null $lockVersion The lock version.
*
* @return object|null The entity instance or NULL if the entity can not be found.
*/
public function find($id, $lockMode = null, $lockVersion = null)
public function find($id, $lockMode = LockMode::NONE, $lockVersion = null)
{
return $this->em->find($this->entityName, $id, $lockMode, $lockVersion);
}
Expand Down
8 changes: 4 additions & 4 deletions lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,7 @@ public function load(
$entity = null,
?AssociationMetadata $association = null,
array $hints = [],
$lockMode = null,
$lockMode = LockMode::NONE,
$limit = null,
array $orderBy = []
) {
Expand Down Expand Up @@ -905,7 +905,7 @@ public function loadToOneEntity(ToOneAssociationMetadata $association, $sourceEn
/**
* {@inheritdoc}
*/
public function refresh(array $id, $entity, $lockMode = null)
public function refresh(array $id, $entity, $lockMode = LockMode::NONE)
{
$sql = $this->getSelectSQL($id, null, $lockMode);
[$params, $types] = $this->expandParameters($id);
Expand Down Expand Up @@ -1151,7 +1151,7 @@ private function getManyToManyStatement(
public function getSelectSQL(
$criteria,
?AssociationMetadata $association = null,
$lockMode = null,
$lockMode = LockMode::NONE,
$limit = null,
$offset = null,
array $orderBy = []
Expand Down Expand Up @@ -2179,7 +2179,7 @@ public function exists($entity, ?Criteria $extraConditions = null)
$alias = $this->getSQLTableAlias($this->class->getTableName());

$sql = 'SELECT 1 '
. $this->getLockTablesSql(null)
. $this->getLockTablesSql(LockMode::NONE)
. ' WHERE ' . $this->getSelectConditionSQL($criteria);

[$params, $types] = $this->expandParameters($criteria);
Expand Down
20 changes: 9 additions & 11 deletions lib/Doctrine/ORM/Persisters/Entity/EntityPersister.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Doctrine\ORM\Persisters\Entity;

use Doctrine\Common\Collections\Criteria;
use Doctrine\DBAL\LockMode;
use Doctrine\ORM\Mapping\AssociationMetadata;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Mapping\ManyToManyAssociationMetadata;
Expand Down Expand Up @@ -63,7 +64,7 @@ public function getColumnValue($entity, string $columnName);
* Gets the SELECT SQL to select one or more entities by a set of field criteria.
*
* @param Criteria|Criteria[] $criteria
* @param int|null $lockMode
* @param int $lockMode
* @param int|null $limit
* @param int|null $offset
* @param mixed[] $orderBy
Expand All @@ -73,7 +74,7 @@ public function getColumnValue($entity, string $columnName);
public function getSelectSQL(
$criteria,
?AssociationMetadata $association = null,
$lockMode = null,
$lockMode = LockMode::NONE,
$limit = null,
$offset = null,
array $orderBy = []
Expand Down Expand Up @@ -186,16 +187,14 @@ public function exists($entity, ?Criteria $extraConditions = null);
/**
* Refreshes a managed entity.
*
* @param mixed[] $id The identifier of the entity as an associative array from
* @param mixed[] $id The identifier of the entity as an associative array from
* column or field names to values.
* @param object $entity The entity to refresh.
* @param int|null $lockMode One of the \Doctrine\DBAL\LockMode::* constants
* or NULL if no specific lock mode should be used
* for refreshing the managed entity.
* @param object $entity The entity to refresh.
* @param int $lockMode One of the \Doctrine\DBAL\LockMode::* constants.
*
* @return void
*/
public function refresh(array $id, $entity, $lockMode = null);
public function refresh(array $id, $entity, $lockMode = LockMode::NONE);

/**
* Loads an entity by a list of field criteria.
Expand All @@ -204,8 +203,7 @@ public function refresh(array $id, $entity, $lockMode = null);
* @param object|null $entity The entity to load the data into. If not specified, a new entity is created.
* @param AssociationMetadata|null $association The association that connects the entity to load to another entity, if any.
* @param mixed[] $hints Hints for entity creation.
* @param int|null $lockMode One of the \Doctrine\DBAL\LockMode::* constants or NULL if no specific lock mode
* should be used for loading the entity.
* @param int $lockMode One of the \Doctrine\DBAL\LockMode::* constants.
* @param int|null $limit Limit number of results.
* @param mixed[] $orderBy Criteria to order by.
*
Expand All @@ -218,7 +216,7 @@ public function load(
$entity = null,
?AssociationMetadata $association = null,
array $hints = [],
$lockMode = null,
$lockMode = LockMode::NONE,
$limit = null,
array $orderBy = []
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public function delete($entity)
public function getSelectSQL(
$criteria,
?AssociationMetadata $association = null,
$lockMode = null,
$lockMode = LockMode::NONE,
$limit = null,
$offset = null,
array $orderBy = []
Expand Down
6 changes: 3 additions & 3 deletions lib/Doctrine/ORM/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ public function setHydrationMode($hydrationMode)
*/
public function setLockMode($lockMode)
{
if (in_array($lockMode, [LockMode::NONE, LockMode::PESSIMISTIC_READ, LockMode::PESSIMISTIC_WRITE], true)) {
if (in_array($lockMode, [LockMode::PESSIMISTIC_READ, LockMode::PESSIMISTIC_WRITE], true)) {
if (! $this->em->getConnection()->isTransactionActive()) {
throw TransactionRequiredException::transactionRequired();
}
Expand All @@ -709,14 +709,14 @@ public function setLockMode($lockMode)
/**
* Get the current lock mode for this query.
*
* @return int|null The current lock mode of this query or NULL if no specific lock mode is set.
* @return int The current lock mode of this query.
*/
public function getLockMode()
{
$lockMode = $this->getHint(self::HINT_LOCK_MODE);

if ($lockMode === false) {
return null;
return LockMode::NONE;
}

return $lockMode;
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/ORM/Query/SqlWalker.php
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ public function walkSelectStatement(AST\SelectStatement $AST)
$sql = $this->platform->modifyLimitQuery($sql, $limit, $offset ?? 0);
}

if ($lockMode === null || $lockMode === false || $lockMode === LockMode::NONE) {
if ($lockMode === false || $lockMode === LockMode::NONE) {
return $sql;
}

Expand Down
1 change: 0 additions & 1 deletion lib/Doctrine/ORM/UnitOfWork.php
Original file line number Diff line number Diff line change
Expand Up @@ -1976,7 +1976,6 @@ public function lock($entity, $lockMode, $lockVersion = null)

break;

case $lockMode === LockMode::NONE:
case $lockMode === LockMode::PESSIMISTIC_READ:
case $lockMode === LockMode::PESSIMISTIC_WRITE:
if (! $this->em->getConnection()->isTransactionActive()) {
Expand Down