code: public Lock lock(boolean isDeep, boolean isSessionScoped) throws UnsupportedRepositoryOperationException,
        LockException, AccessDeniedException, RepositoryException
     {
        checkValid();
  
        if (!isNodeType(Constants.MIX_LOCKABLE))
        {
           throw new LockException("Node is not lockable " + getPath());
        }
  
        // session.checkPermission(getPath(), PermissionType.SET_PROPERTY) is not used because RepositoryException
        // is wrapped into AccessControlException
        if (!session.getAccessManager().hasPermission(getACL(), new String[]{PermissionType.SET_PROPERTY},
           session.getUserState().getIdentity()))
        {
           throw new AccessDeniedException("Access denied: lock operation " + getPath() + " for: " + session.getUserID()
              + " item owner " + getACL().getOwner());
        }
  
        if (dataManager.hasPendingChanges(getInternalPath()))
        {
           throw new InvalidItemStateException("Node has pending unsaved changes " + getPath());
        }
  
        Lock newLock = session.getLockManager().addLock(this, isDeep, isSessionScoped, -1);
  
        PlainChangesLog changesLog = new PlainChangesLogImpl(new ArrayList<ItemState>(), session, ExtendedEvent.LOCK);
  
        PropertyData propData =
           TransientPropertyData.createPropertyData(nodeData(), Constants.JCR_LOCKOWNER, PropertyType.STRING, false,
              new TransientValueData(session.getUserID()));
        changesLog.add(ItemState.createAddedState(propData));
  
        propData =
           TransientPropertyData.createPropertyData(nodeData(), Constants.JCR_LOCKISDEEP, PropertyType.BOOLEAN, false,
              new TransientValueData(isDeep));
        changesLog.add(ItemState.createAddedState(propData));
  
        dataManager.getTransactManager().save(changesLog);
  
        session.getActionHandler().postLock(this);
        return newLock;
  
     }
docs: {@inheritDoc}