Finds an entity by its identifier.

@param $id The identifier.
@param int $lockMode
@param int $lockVersion
@return object The entity.
346296
public function find($id, $lockMode = LockMode::NONE, $lockVersion = null)
    {
        // Check identity map first
        if ($entity = $this->xem->getUnitOfWork()->tryGetById($id, $this->class->rootXmlEntityName)) {
            if ($lockMode != LockMode::NONE) {
                $this->xem->lock($entity, $lockMode, $lockVersion);
            }

            return $entity; // Hit!
        }

        if ($lockMode == LockMode::NONE) {
            return $this->xem->getUnitOfWork()->getXmlEntityPersister($this->entityName)->load($id);
        } else if ($lockMode == LockMode::OPTIMISTIC) {
            if (!$this->class->isVersioned) {
                throw OptimisticLockException::notVersioned($this->entityName);
            }
            $entity = $this->xem->getUnitOfWork()->getXmlEntityPersister($this->entityName)->load($id);

            $this->xem->getUnitOfWork()->lock($entity, $lockMode, $lockVersion);

            return $entity;
        } else {
            if (!$this->xem->getConnection()->isTransactionActive()) {
                throw TransactionRequiredException::transactionRequired();
            }

            return $this->xem->getUnitOfWork()->getXmlEntityPersister($this->entityName)->load($id, null, null, array(), $lockMode);
        }
    }
592523
public function find($id, array $with = array())
    {
        $entity = $this->make($with);

        return $entity->findOrFail($id);
    }
409069
protected function pathIsLocked($path, $lockMode = null, $openMode = 'r+')
    {
        $lockTestResource = fopen($path, $openMode);
        $lockMode = $lockMode ?: $this->getLockMode() | LOCK_NB;

        if (!flock($lockTestResource, $lockMode)) {
            return true;
        }

        // Remove my created lock.
        flock($lockTestResource, LOCK_UN);

        return false;

    }
1244094
public static function obtainOptimizationLock(Zend_Search_Lucene_Storage_Directory $lockDirectory)
    {
        $lock = $lockDirectory->createFile(self::OPTIMIZATION_LOCK_FILE);
        if (!$lock->lock(LOCK_EX, true)) {
            return false;
        }
        return $lock;
    }
1267612
protected function isLockableEntityLocked(LockableEntityInterface $entity)
    {
        /** @var EntityVersionLockService $entityVersionLockService */
        $entityVersionLockService = $this->container->get('kunstmaan_entity.admin_entity.entity_version_lock_service');

        return $entityVersionLockService->isEntityBelowThreshold($entity) && $entityVersionLockService->isEntityLocked(
                $this->getUser(),
                $entity
            );
    }
748940
public function unlock($id, Request $request)
    {
        $thread = $this->model()->where('locked', 1)->find($id);

        $category = !is_null($thread) ? $thread->category : [];

        return $this->updateModel($thread, ['locked' => 0], ['lockThreads', $category]);
    }
863407
public function getEntityId($entity)
    {
        $className = get_class($entity);

        if (!isset($this->idAccessorFunctions[$className]["getter"])) {
            if (!$this->hasId($entity)) {
                throw new OrmException("No Id getter registered for class $className");
            }

            $this->registerReflectionIdAccessors($className, 'id');
        }

        try {
            return call_user_func($this->idAccessorFunctions[$className]["getter"], $entity);
        } catch (ReflectionException $e) {
            throw new OrmException("Failed to get entity Id\n" . $e->getMessage(), 0, $e);
        }
    }
206648
public function getUsersWithEntityVersionLock(LockableEntityInterface $entity, User $userToExclude = null)
    {
        /** @var LockableEntity $lockable */
        $lockable = $this->getLockableEntity($entity);

        return  array_reduce(
            $this->getEntityVersionLocksByLockableEntity($lockable, $userToExclude),
            function ($return, EntityVersionLock $item) {
                $return[] = $item->getOwner();

                return $return;
            },
            []
        );
    }
252288
public function findEntityById($identifier, $id)
    {
        return $this->buildEntity($identifier, $this->findRegistriesEntityById($identifier, $id));
    }
1210609
static public function init(LockHandlerInterface $lockHandler)
    {
        if (is_null(self::$singletonObject)) {
            self::$singletonObject = new self($lockHandler);
        }
        return self::$singletonObject;
    }
720885
public function getExpiredLocks(LockableEntity $entity, $threshold)
    {
        $qb = $this->createQueryBuilder('evl')
            ->select('evl')
            ->join('evl.lockableEntity', 'le')
            ->where('le.id = :e')
            ->andWhere('evl.createdAt < :date')
            ->setParameter('e', $entity->getId())
            ->setParameter('date', new \DateTime(sprintf('-%s seconds', $threshold)));

        return $qb->getQuery()->getResult();
    }
646223
public function get($id, ?int $lockMode = null, ?int $lockVersion = null)
    {
        $entity = $this->find($id, $lockMode, $lockVersion);

        if (null === $entity) {
            if (!\is_array($id)) {
                $id = [$this->_class->identifier[0] => $id];
            }

            throw EntityNotFoundException::fromClassNameAndIdentifier(
                $this->getClassName(),
                $this->identifierFlattener->flattenIdentifier($this->_class, $id)
            );
        }

        return $entity;
    }
35753
public function findEntityById($id)
    {
        $item = $this->itemRepository->find($id);
        if (!$item) {
            return null;
        }

        return $item;
    }
449836
public function lock($document, $lockMode)
    {
        $id = $this->uow->getDocumentIdentifier($document);
        $criteria = array('_id' => $this->class->getDatabaseIdentifierValue($id));
        $lockMapping = $this->class->fieldMappings[$this->class->lockField];
        $this->collection->update($criteria, array('$set' => array($lockMapping['name'] => $lockMode)));
        $this->class->reflFields[$this->class->lockField]->setValue($document, $lockMode);
    }
318668
public static ILockableEntityGroup findLockableGroup(String key, String lockOwner)
            throws GroupsException {
        LOGGER.trace("Invoking findLockableGroup for key='{}', lockOwner='{}'", key, lockOwner);
        return instance().ifindLockableGroup(key, lockOwner);
    }
117730
public function checkAction(Request $request, $id, $repository)
    {
        $entityIsLocked = false;
        $message = '';

        /** @var LockableEntityInterface $entity */
        $entity = $this->getEntityManager()->getRepository($repository)->find($id);

        try {
            /** @var EntityVersionLockService $entityVersionLockservice */
            $entityVersionLockService = $this->get('kunstmaan_entity.admin_entity.entity_version_lock_service');

            $entityIsLocked = $entityVersionLockService->isEntityLocked($this->getUser(), $entity);

            if ($entityIsLocked) {
                $user = $entityVersionLockService->getUsersWithEntityVersionLock($entity, $this->getUser());
                $message = $this->get('translator')->trans('kuma_admin_list.edit.flash.locked', array('%user%' => implode(', ', $user)));
            }
        } catch (AccessDeniedException $ade) {
        }

        return new JsonResponse(['lock' => $entityIsLocked, 'message' => $message]);
    }
134474
public function getEntity($id, $hydrationMode = AbstractQuery::HYDRATE_OBJECT)
    {
        return $this->getQueryBuilder(['id' => $id])
            ->getQuery()
            ->setMaxResults(1)
            ->getOneOrNullResult($hydrationMode);
    }