當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。