当前位置: 首页>>代码示例>>PHP>>正文


PHP OptimisticLockException::lockFailedVersionMismatch方法代码示例

本文整理汇总了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
     }
 }
开发者ID:josercl,项目名称:forum,代码行数:48,代码来源:UnitOfWork.php


注:本文中的Doctrine\ORM\OptimisticLockException::lockFailedVersionMismatch方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。