本文整理汇总了PHP中Doctrine\ORM\OptimisticLockException::lockFailedVersionMismatch方法的典型用法代码示例。如果您正苦于以下问题:PHP OptimisticLockException::lockFailedVersionMismatch方法的具体用法?PHP OptimisticLockException::lockFailedVersionMismatch怎么用?PHP OptimisticLockException::lockFailedVersionMismatch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ORM\OptimisticLockException
的用法示例。
在下文中一共展示了OptimisticLockException::lockFailedVersionMismatch方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: lock
/**
* Acquire a lock on the given entity.
*
* @param object $entity
* @param int $lockMode
* @param int $lockVersion
*
* @return void
*
* @throws ORMInvalidArgumentException
* @throws TransactionRequiredException
* @throws OptimisticLockException
*/
public function lock($entity, $lockMode, $lockVersion = null)
{
if ($entity === null) {
throw new \InvalidArgumentException("No entity passed to UnitOfWork#lock().");
}
if ($this->getEntityState($entity, self::STATE_DETACHED) != self::STATE_MANAGED) {
throw ORMInvalidArgumentException::entityNotManaged($entity);
}
$class = $this->em->getClassMetadata(get_class($entity));
switch (true) {
case LockMode::OPTIMISTIC === $lockMode:
if (!$class->isVersioned) {
throw OptimisticLockException::notVersioned($class->name);
}
if ($lockVersion === null) {
return;
}
$entityVersion = $class->reflFields[$class->versionField]->getValue($entity);
if ($entityVersion != $lockVersion) {
throw OptimisticLockException::lockFailedVersionMismatch($entity, $lockVersion, $entityVersion);
}
break;
case LockMode::NONE === $lockMode:
case LockMode::PESSIMISTIC_READ === $lockMode:
case LockMode::PESSIMISTIC_WRITE === $lockMode:
if (!$this->em->getConnection()->isTransactionActive()) {
throw TransactionRequiredException::transactionRequired();
}
$oid = spl_object_hash($entity);
$this->getEntityPersister($class->name)->lock(array_combine($class->getIdentifierFieldNames(), $this->entityIdentifiers[$oid]), $lockMode);
break;
default:
// Do nothing
}
}