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


PHP OptimisticLockException::lockFailedVersionMissmatch方法代码示例

本文整理汇总了PHP中Doctrine\ORM\OptimisticLockException::lockFailedVersionMissmatch方法的典型用法代码示例。如果您正苦于以下问题:PHP OptimisticLockException::lockFailedVersionMissmatch方法的具体用法?PHP OptimisticLockException::lockFailedVersionMissmatch怎么用?PHP OptimisticLockException::lockFailedVersionMissmatch使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Doctrine\ORM\OptimisticLockException的用法示例。


在下文中一共展示了OptimisticLockException::lockFailedVersionMissmatch方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: lock

 /**
  * Acquire a lock on the given entity.
  *
  * @param object $entity
  * @param int $lockMode
  * @param int $lockVersion
  *
  * @throws ORMInvalidArgumentException
  * @throws TransactionRequiredException
  * @throws OptimisticLockException
  *
  * @return void
  */
 public function lock($entity, $lockMode, $lockVersion = null)
 {
     if ($this->getEntityState($entity, self::STATE_DETACHED) != self::STATE_MANAGED) {
         throw ORMInvalidArgumentException::entityNotManaged($entity);
     }
     $class = $this->em->getClassMetadata(get_class($entity));
     switch ($lockMode) {
         case \Doctrine\DBAL\LockMode::OPTIMISTIC:
             if (!$class->isVersioned) {
                 throw OptimisticLockException::notVersioned($class->name);
             }
             if ($lockVersion === null) {
                 return;
             }
             $entityVersion = $class->reflFields[$class->versionField]->getValue($entity);
             if ($entityVersion != $lockVersion) {
                 throw OptimisticLockException::lockFailedVersionMissmatch($entity, $lockVersion, $entityVersion);
             }
             break;
         case \Doctrine\DBAL\LockMode::PESSIMISTIC_READ:
         case \Doctrine\DBAL\LockMode::PESSIMISTIC_WRITE:
             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:richardjennings,项目名称:doctrine2,代码行数:44,代码来源:UnitOfWork.php

示例2: lock

 /**
  * Acquire a lock on the given entity.
  *
  * @param object $entity
  * @param int $lockMode
  * @param int $lockVersion
  */
 public function lock($entity, $lockMode, $lockVersion = null)
 {
     if ($this->getEntityState($entity) != self::STATE_MANAGED) {
         throw new InvalidArgumentException("Entity is not MANAGED.");
     }
     $entityName = get_class($entity);
     $class = $this->em->getClassMetadata($entityName);
     if ($lockMode == \Doctrine\DBAL\LockMode::OPTIMISTIC) {
         if (!$class->isVersioned) {
             throw OptimisticLockException::notVersioned($entityName);
         }
         if ($lockVersion != null) {
             $entityVersion = $class->reflFields[$class->versionField]->getValue($entity);
             if ($entityVersion != $lockVersion) {
                 throw OptimisticLockException::lockFailedVersionMissmatch($entity, $lockVersion, $entityVersion);
             }
         }
     } else {
         if (in_array($lockMode, array(\Doctrine\DBAL\LockMode::PESSIMISTIC_READ, \Doctrine\DBAL\LockMode::PESSIMISTIC_WRITE))) {
             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);
         }
     }
 }
开发者ID:OmondiKevin,项目名称:ADT_MTRH,代码行数:34,代码来源:UnitOfWork.php

示例3: useWithPessimisticVersionLock

 /**
  * Acquires an optimistic lock within a pessimistic lock transaction. For
  * use in fail-fast scenarios; guaranteed to throw an exception on
  * concurrent modification attempts. The one to first acquire the write lock
  * will update the version field, leading subsequent acquisitions of the
  * optimistic lock to fail.
  *
  * FIXME: Only works on entities implementing VersionLockable and does not
  * work in conjunction with the Doctrine @Version column.
  *
  * @param int $id
  * @param mixed $lockVersion
  * @param callback($entity, Doctrine\ORM\EntityManager, Repository) $callback
  * @return mixed callback return type
  * @throws OptimisticLockException
  */
 public function useWithPessimisticVersionLock($id, $lockVersion, $callback)
 {
     return $this->useWithPessimisticWriteLock($id, function (VersionLockable $entity, EntityManager $em, $self) use($lockVersion, $callback) {
         if ($entity->getVersion() !== $lockVersion) {
             // FIXME: This isn't the appropriate exception type.
             throw OptimisticLockException::lockFailedVersionMissmatch($entity, $lockVersion, $entity->getVersion());
         }
         $entity->incrementVersion();
         return $callback($entity, $em, $self);
     });
 }
开发者ID:breerly,项目名称:factory-girl-php,代码行数:27,代码来源:Repository.php


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