Acquire a lock on the given document.

@throws InvalidArgumentException
@throws LockException
199017
public function lock(object $document, int $lockMode, ?int $lockVersion = null) : void
    {
        $this->unitOfWork->lock($document, $lockMode, $lockVersion);
    }
130105
@Override
    public synchronized Lock obtainReadLock() {
        File writeLock = getWriteLock();

        if (writeLock != null && writeLock.exists()) {
            return null;
        }

        return createLock(false);
    }
513170
private void lockReachableObjects(Identity oid, Object userObject,
            Object cacheObject, int lock, Stack stack, boolean buildingObject)
            throws LockingException
    {
        ContextEntry entry;
        boolean onlyDependants = !_tx.getKit().isImplicitLockingUsed();
        ClassDescriptor mif = _pb.getClassDescriptor(userObject.getClass());

        // N:1 relations
        Iterator iter = mif.getObjectReferenceDescriptors().iterator();
        ObjectReferenceDescriptor rds = null;
        PersistentField f;
        Object relUserObj;
        Identity relOid;
        boolean isDependent;

        while (iter.hasNext())
        {
            rds = (ObjectReferenceDescriptor) iter.next();
            isDependent = rds.getOtmDependent();
            if (onlyDependants && !isDependent)
            {
                continue;
            }
            f = rds.getPersistentField();
            relUserObj = f.get(userObject);
            if (relUserObj != null)
            {
                relOid = new Identity(relUserObj, _pb);
                entry = (ContextEntry) _objects.get(relOid);
                if ((entry == null) || (entry.userObject != relUserObj))
                {
                    entry = insertInternal(relOid, relUserObj, lock, isDependent,
                                           oid, stack);
                    if (buildingObject && (entry != null))
                    {
                        f.set(userObject, entry.userObject);
                        f.set(cacheObject, entry.cacheObject);
                    }
                }
            }
        }

        // 1:N relations
        Iterator collections = mif.getCollectionDescriptors().iterator();
        CollectionDescriptor cds;
        Object userCol;
        Iterator userColIterator;
        Class type;
        ArrayList newUserCol = null;
        ArrayList newCacheCol = null;

        while (collections.hasNext())
        {
            cds = (CollectionDescriptor) collections.next();
            f = cds.getPersistentField();
            type = f.getType();
            isDependent = cds.getOtmDependent();
            if (onlyDependants && !isDependent)
            {
                continue;
            }
            userCol = f.get(userObject);
            if (userCol != null)
            {
                if ((userCol instanceof CollectionProxyDefaultImpl)
                        && !((CollectionProxyDefaultImpl) userCol).isLoaded())
                {
                    continue;
                }

                if (buildingObject)
                {
                    newUserCol = new ArrayList();
                    newCacheCol = new ArrayList();
                }

                if (Collection.class.isAssignableFrom(type))
                {
                    userColIterator = ((Collection) userCol).iterator();
                }
                else if (type.isArray())
                {
                    userColIterator = new ArrayIterator(userCol);
                }
                else
                {
                    throw new OJBRuntimeException(
                        userCol.getClass()
                            + " can not be managed by OJB OTM, use Array or Collection instead !");
                }

                while (userColIterator.hasNext())
                {
                    relUserObj = userColIterator.next();
                    relOid = new Identity(relUserObj, _pb);
                    entry = (ContextEntry) _objects.get(relOid);
                    if ((entry == null) || (entry.userObject != relUserObj))
                    {
                        entry = insertInternal(relOid, relUserObj, lock,
                                               isDependent, null, stack);
                    }
                    if (buildingObject && (entry != null))
                    {
                        newUserCol.add(entry.userObject);
                        newCacheCol.add(entry.cacheObject);
                    }
                }
                if (buildingObject)
                {
                    setCollectionField(userObject, f, newUserCol);
                    setCollectionField(cacheObject, f, newCacheCol);
                }
            }
        }
    }
327633
@Override
  public void lock() throws JobLockException {
    try {
      this.lock.acquire();
    } catch (Exception e) {
      throw new JobLockException("Failed to acquire lock " + this.lockPath, e);
    }
  }
310742
public static Lock toLock(Entity entity) {
		return new Lock(entity.getKey().getName(), 
				(String) entity.getProperty(TRANSACTION_PROPERTY), 
				(Date) entity.getProperty(TIMESTAMP_PROPERTY));
	}
473134
public function find($id, int $lockMode = LockMode::NONE, ?int $lockVersion = null) : ?object
    {
        if ($id === null) {
            return null;
        }

        /* TODO: What if the ID object has a field with the same name as the
         * class' mapped identifier field name?
         */
        if (is_array($id)) {
            [$identifierFieldName] = $this->class->getIdentifierFieldNames();

            if (isset($id[$identifierFieldName])) {
                $id = $id[$identifierFieldName];
            }
        }

        // Check identity map first
        $document = $this->uow->tryGetById($id, $this->class);
        if ($document) {
            if ($lockMode !== LockMode::NONE) {
                $this->dm->lock($document, $lockMode, $lockVersion);
            }

            return $document; // Hit!
        }

        $criteria = ['_id' => $id];

        if ($lockMode === LockMode::NONE) {
            return $this->getDocumentPersister()->load($criteria);
        }

        if ($lockMode === LockMode::OPTIMISTIC) {
            if (! $this->class->isVersioned) {
                throw LockException::notVersioned($this->documentName);
            }

            $document = $this->getDocumentPersister()->load($criteria);
            if ($document) {
                $this->uow->lock($document, $lockMode, $lockVersion);
            }

            return $document;
        }

        return $this->getDocumentPersister()->load($criteria, null, [], $lockMode);
    }
861073
public function unlock($document)
    {
        $qb          = $this->dm->createQueryBuilder($this->class->name);
        $identifier  = $this->uow->getDocumentIdentifier($document);
        $lockMapping = $this->class->lockMetadata;

        $qb->update();
        $qb->setIdentifier($identifier);
        $qb->attr($lockMapping->name)->remove();

        $qb->getQuery()->execute();

        $lockMapping->setValue($document, null);
    }
751563
private boolean getLockInformation( final ITransaction transaction, final WebdavRequest req, final WebdavResponse resp )
        throws WebdavException, IOException
    {

        Node lockInfoNode = null;
        DocumentBuilder documentBuilder = null;

        documentBuilder = getDocumentBuilder();
        try
        {
            final Document document = documentBuilder.parse( new InputSource( req.getInputStream() ) );

            // Get the root element of the document
            final Element rootElement = document.getDocumentElement();

            lockInfoNode = rootElement;

            if ( lockInfoNode != null )
            {
                NodeList childList = lockInfoNode.getChildNodes();
                Node lockScopeNode = null;
                Node lockTypeNode = null;
                Node lockOwnerNode = null;

                Node currentNode = null;
                String nodeName = null;

                for ( int i = 0; i < childList.getLength(); i++ )
                {
                    currentNode = childList.item( i );

                    if ( currentNode.getNodeType() == Node.ELEMENT_NODE || currentNode.getNodeType() == Node.TEXT_NODE )
                    {

                        nodeName = currentNode.getNodeName();

                        if ( nodeName.endsWith( "locktype" ) )
                        {
                            lockTypeNode = currentNode;
                        }
                        if ( nodeName.endsWith( "lockscope" ) )
                        {
                            lockScopeNode = currentNode;
                        }
                        if ( nodeName.endsWith( "owner" ) )
                        {
                            lockOwnerNode = currentNode;
                        }
                    }
                    else
                    {
                        return false;
                    }
                }

                if ( lockScopeNode != null )
                {
                    String scope = null;
                    childList = lockScopeNode.getChildNodes();
                    for ( int i = 0; i < childList.getLength(); i++ )
                    {
                        currentNode = childList.item( i );

                        if ( currentNode.getNodeType() == Node.ELEMENT_NODE )
                        {
                            scope = currentNode.getNodeName();

                            if ( scope.endsWith( "exclusive" ) )
                            {
                                _exclusive = true;
                            }
                            else if ( scope.equals( "shared" ) )
                            {
                                _exclusive = false;
                            }
                        }
                    }
                    if ( scope == null )
                    {
                        return false;
                    }

                }
                else
                {
                    return false;
                }

                if ( lockTypeNode != null )
                {
                    childList = lockTypeNode.getChildNodes();
                    for ( int i = 0; i < childList.getLength(); i++ )
                    {
                        currentNode = childList.item( i );

                        if ( currentNode.getNodeType() == Node.ELEMENT_NODE )
                        {
                            _type = currentNode.getNodeName();

                            if ( _type.endsWith( "write" ) )
                            {
                                _type = "write";
                            }
                            else if ( _type.equals( "read" ) )
                            {
                                _type = "read";
                            }
                        }
                    }
                    if ( _type == null )
                    {
                        return false;
                    }
                }
                else
                {
                    return false;
                }

                if ( lockOwnerNode != null )
                {
                    childList = lockOwnerNode.getChildNodes();
                    for ( int i = 0; i < childList.getLength(); i++ )
                    {
                        currentNode = childList.item( i );

                        if ( currentNode.getNodeType() == Node.ELEMENT_NODE || currentNode.getNodeType() == Node.TEXT_NODE )
                        {
                            _lockOwner = currentNode.getTextContent();
                        }
                    }
                }
                if ( _lockOwner == null )
                {
                    return false;
                }
            }
            else
            {
                return false;
            }

        }
        catch ( final DOMException e )
        {
            resp.sendError( SC_INTERNAL_SERVER_ERROR );
            e.printStackTrace();
            return false;
        }
        catch ( final SAXException e )
        {
            resp.sendError( SC_INTERNAL_SERVER_ERROR );
            e.printStackTrace();
            return false;
        }

        return true;
    }
1256521
public function acquireLock()
    {
        if ($this->adapter->hasItem(self::WURFL_LOCKED)) {
            return false;
        }

        return $this->save(self::WURFL_LOCKED, true);
    }
392469
public IEntityLock newReadLock(EntityIdentifier entityID, String owner)
            throws LockingException {
        return lockService.newLock(
                entityID.getType(), entityID.getKey(), IEntityLockService.READ_LOCK, owner);
    }
42737
public void performWithLock (final NodeObject.Lock lock, final LockedOperation operation)
    {
        acquireLock(lock, new ResultListener<String>() {
            public void requestCompleted (String nodeName) {
                if (getNodeObject().nodeName.equals(nodeName)) {
                    // lock acquired successfully - perform the operation, and release the lock.
                    try {
                        operation.run();
                    } finally {
                        releaseLock(lock, new ResultListener.NOOP<String>());
                    }
                } else {
                    // some other peer beat us to it
                    operation.fail(nodeName);
                    if (nodeName == null) {
                        log.warning("Lock acquired by null?", "lock", lock);
                    }
                }
            }
            public void requestFailed (Exception cause) {
                log.warning("Lock acquisition failed", "lock", lock, cause);
                operation.fail(null);
            }
        });
    }
1286721
public function acquire()
    {
        $isAcquired = $this->lock->acquireLock($this->timeout->getValue());

        if (!$isAcquired) {
            throw new LockingException('Lock cannot be acquired.', 1438871269);
        }
    }
19162
public void writeLock(EntityKey key, int timeout) {
		ReadWriteLock lock = getLock( key );
		Lock writeLock = lock.writeLock();
		acquireLock( key, timeout, writeLock );
	}
891157
public function setLockMapping(array &$mapping) : void
    {
        if ($mapping['type'] !== 'int') {
            throw LockException::invalidLockFieldType($mapping['type']);
        }

        $this->isLockable = true;
        $this->lockField  = $mapping['fieldName'];
    }
245010
public synchronized boolean lock() throws KeeperException, InterruptedException {
        if (isClosed()) {
            return false;
        }
        ensurePathExists(dir);

        return (Boolean) retryOperation(zop);
    }
239969
def acquire_lock(path: str, blocking: bool) -> Generator[Optional[int], None, None]:
    """"""
    try:
        with open(path, "w+") as lockfile:
            if not blocking:
                lock_command = fcntl.LOCK_EX | fcntl.LOCK_NB
            else:
                lock_command = fcntl.LOCK_EX

            fcntl.lockf(lockfile.fileno(), lock_command)
            yield lockfile.fileno()
            fcntl.lockf(lockfile.fileno(), fcntl.LOCK_UN)

    except FileNotFoundError:
        yield
997889
@Override
    public void lock(Object entity, LockModeType lockMode)
    {
        ivEm.lock(entity, lockMode);
    }