Utility method to lock the current record using the lock manager.
If doEdit() doesn't have native locking, just call this method.
@return Error
@throws DBException
489348
public int lockCurrentRecord() throws DBException
    {
        int iErrorCode = DBConstants.NORMAL_RETURN;
        Record record = this.getRecord();
        Object bookmark = record.getHandle(DBConstants.BOOKMARK_HANDLE);
        if (bookmark != null)
        {   // Always
            String strUserName = null;
            BaseApplication app = null;
            org.jbundle.model.Task task = null;
            if (record.getRecordOwner() != null)
                task = record.getRecordOwner().getTask();
            if (task != null)
                app = (BaseApplication)record.getRecordOwner().getTask().getApplication();
            if (app != null)
                strUserName = app.getProperty(DBParams.USER_NAME);
            Environment env = null;
            if (app != null)
                env = app.getEnvironment();
            else
                env = Environment.getEnvironment(null);
            iErrorCode = env.getLockManager().lockThisRecord(task, record.getDatabaseName(), record.getTableNames(false), bookmark, strUserName, record.getOpenMode());
        }
        return iErrorCode;
    }
617604
public void add(Rec fieldList) throws DBException
    {
        Record record = (Record)fieldList;
        int iErrorCode = DBConstants.NORMAL_RETURN;
        if ((record.getOpenMode() & DBConstants.OPEN_READ_ONLY) != 0)
            throw new DatabaseException(DBConstants.ERROR_READ_ONLY);
        boolean[] rgbSaveEnabled = null;
        try   {
            if (record.getEditMode() != Constants.EDIT_ADD)
            {
                if (record.getEditMode() == Constants.EDIT_IN_PROGRESS)
                    if ((record.getOpenMode() & DBConstants.OPEN_REFRESH_AND_LOCK_ON_CHANGE_STRATEGY) == DBConstants.OPEN_REFRESH_AND_LOCK_ON_CHANGE_STRATEGY)
                { // Special case - Add with refresh/update on add
                    iErrorCode = record.handleRecordChange(DBConstants.ADD_TYPE);
                    if (iErrorCode != DBConstants.NORMAL_RETURN)
                        throw new DatabaseException(iErrorCode);
                    rgbSaveEnabled = record.setEnableListeners(false);      // Don't trigger any UPDATE listeners
                    if (record.isModified())
                        this.set(record);
                    record.setEnableListeners(rgbSaveEnabled);
                    rgbSaveEnabled = null;
                    iErrorCode = record.handleRecordChange(DBConstants.AFTER_ADD_TYPE);
                    if (iErrorCode != DBConstants.NORMAL_RETURN)
                        throw new DatabaseException(iErrorCode);
                    return;
                }
                throw new DatabaseException(DBConstants.INVALID_RECORD);
            }
            CounterField fldCounter = (CounterField)record.getCounterField();
            if (fldCounter != null)
                if (!DBConstants.FALSE.equalsIgnoreCase(this.getProperty(SQLParams.AUTO_SEQUENCE_ENABLED))) // Auto seq is enabled:
            {       // Just in case you had some data in the counter (it will be cleared).
                boolean[] rgbEnabled = fldCounter.setEnableListeners(false);
                fldCounter.setData(null);
                fldCounter.setEnableListeners(rgbEnabled);
            }
            iErrorCode = record.handleRecordChange(DBConstants.ADD_TYPE);
            if (iErrorCode != DBConstants.NORMAL_RETURN)
                throw new DatabaseException(iErrorCode);
            if (record.getEditMode() != Constants.EDIT_ADD)
            {   // It is possible that the add behavior wrote and refreshed the record, in that case, I need to update.
                if ((record.getEditMode() == Constants.EDIT_IN_PROGRESS) || (record.getEditMode() == Constants.EDIT_CURRENT))
                { // Special case - Add with refresh/update on add
                    rgbSaveEnabled = record.setEnableListeners(false);      // Don't trigger any UPDATE listeners
                    if (record.isModified())
                        this.set(record);
                    record.setEnableListeners(rgbSaveEnabled);
                    rgbSaveEnabled = null;
                    iErrorCode = record.handleRecordChange(DBConstants.AFTER_ADD_TYPE);
                    if (iErrorCode != DBConstants.NORMAL_RETURN)
                        throw new DatabaseException(iErrorCode);
                    return;
                }
                throw new DatabaseException(DBConstants.INVALID_RECORD);
            }
            this.fieldsToData(record);
            this.setLastModHint(record);
            this.doAdd(record);
            m_iRecordStatus |= DBConstants.RECORD_INVALID;
        } catch (DBException ex)    {
            if (rgbSaveEnabled != null)
                record.setEnableListeners(rgbSaveEnabled);
            if (ex.getErrorCode() == DBConstants.DUPLICATE_KEY)
            {   // If duplicate key, don't invalidate the record.
                iErrorCode = this.getRecord().handleErrorReturn(DBConstants.AFTER_ADD_TYPE, ex.getErrorCode()); // Give the listeners a chance to fix the error.
                if (iErrorCode == DBConstants.NORMAL_RETURN)
                    return;
            }
//x            else
//x                record.setEditMode(Constants.EDIT_NONE);
            throw ex;
        }
        iErrorCode = record.handleRecordChange(DBConstants.AFTER_ADD_TYPE);
        if (iErrorCode != DBConstants.NORMAL_RETURN)
            throw new DatabaseException(iErrorCode);
        record.setEditMode(Constants.EDIT_NONE);    // Unknown status after an add
        if ((record.getOpenMode() & DBConstants.OPEN_REFRESH_AND_LOCK_ON_CHANGE_STRATEGY) == DBConstants.OPEN_REFRESH_AND_LOCK_ON_CHANGE_STRATEGY)
            return;   // Will need these to refresh record
        m_objectID = null;
        m_dataSource = null;
    }
8169
private function AssertSuccess()
    {
        if ($this->db)
        {
            if ($this->IsConnected())
            {
                $errorCode = $this->db->errno;
                if ($errorCode != 0)
                {
                    if ($this->inTransaction)
                        $this->RollBack();

                    throw new DBExceptions\DatabaseException($this->db->error, $errorCode, $this->lastQuery);
                }
            }
            else
            {
                $errorCode = $this->db->connect_errno;
                if ($errorCode != 0)
                {
                    throw new DBExceptions\DatabaseException($this->db->connect_error, $errorCode);
                }
            }
        }
    }
581607
public void open() throws DBException
    {
        if (this.isOpen())
            return;         // Ignore if already open
        this.getRecord().handleInitialKey();        // Set up the smaller key
        this.getRecord().handleEndKey();            // Set up the larger key
                // You can't process a QueryRecord using tables, use special table logic.
        ((QueryRecord)m_record).openTableQuery();
    }
106753
public function lock()
    {
        if ($this->handle) {
            return true;
        }

        // start the silence for both userland and native PHP error handlers
        $errorLevel = error_reporting(0);
        set_error_handler('var_dump', 0);

        if (!$this->handle = fopen($this->file, 'r')) {
            if ($this->handle = fopen($this->file, 'x')) {
                chmod($this->file, 0444);
            } elseif (!$this->handle = fopen($this->file, 'r')) {
                usleep(100);
                $this->handle = fopen($this->file, 'r');
            }
        }

        restore_error_handler();
        error_reporting($errorLevel);

        if (!$this->handle) {
            $error = error_get_last();
            throw new \RuntimeException($error['message'], 0, null, $this->file);
        }

        if (!flock($this->handle, LOCK_EX | LOCK_NB)) {
            fclose($this->handle);
            $this->handle = null;

            return false;
        }

        return true;
    }
764669
public void set(Rec record) throws DBException
    {
        if ((this.getRecord().getEditMode() != Constants.EDIT_CURRENT)
            && ((this.getRecord().getEditMode() != Constants.EDIT_IN_PROGRESS)))
                throw new DBException(Constants.INVALID_RECORD);
        m_record = (FieldList)record;
        this.fieldsToData(record);
        this.doSet(record);
        this.setDataSource(null);
        this.getRecord().setEditMode(Constants.EDIT_NONE);
    }
563580
private void lock(Object obtainer) throws PSQLException {
    if (lockedFor == obtainer) {
      throw new PSQLException(GT.tr("Tried to obtain lock while already holding it"),
          PSQLState.OBJECT_NOT_IN_STATE);

    }
    waitOnLock();
    lockedFor = obtainer;
  }
1227415
public int update() throws SQLException {
		checkForDao();
		@SuppressWarnings("unchecked")
		T t = (T) this;
		return dao.update(t);
	}
253848
public void addNew() throws DBException
    {
        if (((this.getRecord().getOpenMode() & DBConstants.OPEN_REFRESH_AND_LOCK_ON_CHANGE_STRATEGY) == 0)
            && ((this.getRecord().getOpenMode() & DBConstants.OPEN_READ_ONLY) != DBConstants.OPEN_READ_ONLY)
            && (this.getRecord().getCounterField() != null))
                this.getRecord().setOpenMode(this.getRecord().getOpenMode() | DBConstants.OPEN_REFRESH_AND_LOCK_ON_CHANGE_STRATEGY); // Must have for MirrorTable to sync new records
        super.addNew();
        Iterator<BaseTable> iterator = this.getTables();
        while (iterator.hasNext())
        {
            BaseTable table = iterator.next();
            if ((table != null) && (table != this.getNextTable()))
            {
                table.addNew();
            }
        }
    }
371165
protected synchronized void lock(ManagedObject managedObject)
                    throws ObjectManagerException
    {
        throw new InvalidStateException(this, InternalTransaction.stateTerminated, InternalTransaction.stateNames[InternalTransaction.stateTerminated]);
    }
562916
def start(self):
        
        # Delete any expired locks first
        self.delete_expired_locks()
        try:
            with transaction.atomic():
                self.lock = DBMutex.objects.create(lock_id=self.lock_id)
        except IntegrityError:
            raise DBMutexError('Could not acquire lock: {0}'.format(self.lock_id))
245934
public void rollback() throws DBException
    {
        super.rollback(); // Will throw an error if something is not set up right.
        try   {
            if (m_JDBCConnection != null)
                m_JDBCConnection.rollback();
        } catch (SQLException ex) {
            throw this.convertError(ex);
        }
    }
1180066
public void set(Rec fieldList) throws DBException
    {
        super.set(fieldList);
        Record record = (Record)fieldList;
        Iterator<BaseTable> iterator = this.getTables();
        while (iterator.hasNext())
        {
            BaseTable table = iterator.next();
            if ((table != null) && (table != this.getNextTable()))
            {
                if ((table.getRecord().getEditMode() == Constants.EDIT_IN_PROGRESS) || (table.getRecord().getEditMode() == Constants.EDIT_CURRENT))
                {
                    Record record2 = table.getRecord();
                    this.copyRecord(record2, record);
                    table.set(record2);
                }
                else if (table.getRecord().getEditMode() == Constants.EDIT_ADD)
                {   // Should have been in sync, but it is now!
                    Record record2 = table.getRecord();
                    boolean bIsAutoSequence = record2.setAutoSequence(false);
                    this.copyRecord(record2, record);
                    try {
                        table.add(record2);
                    } catch (DBException ex) {
                        throw ex;
                    } finally {
                        record2.setAutoSequence(bIsAutoSequence);
                    }
                }
            }
        }
    }
181161
public function lock()
    {
        $result = null;

        $context = $this->getContext();
        $context->table = $this->getBase();

        if ($this->invokeCommand('before.lock', $context) !== false)
        {
            if ($this->isConnected()) {
                $context->result = $this->getDriver()->lock($this->getBase());
            }

            $this->invokeCommand('after.lock', $context);
        }

        return $context->result;
    }
194748
public void doRemove() throws DBException
    {
        try   {
            synchronized (this.getSyncObject())
            {   // In case this is called from another task
                m_tableRemote.remove(null, this.getRecord().getOpenMode());
            }
        } catch (Exception ex) {
            throw DatabaseException.toDatabaseException(ex);
        }
    }
400332
public void doAddNew() throws DBException
    {
        if (this.lockOnDBTrxType(null, DBConstants.ADD_TYPE, false))  // ADD_TYPE = Add new; Should I do the unlock in my code?
            this.unlockIfLocked(this.getRecord(), null);    // Release any locks
    }
724292
public function isLockedOut()
    {
        /** @var DBDatetime $lockedOutUntilObj */
        $lockedOutUntilObj = $this->dbObject('LockedOutUntil');
        if ($lockedOutUntilObj->InFuture()) {
            return true;
        }

        $maxAttempts = $this->config()->get('lock_out_after_incorrect_logins');
        if ($maxAttempts <= 0) {
            return false;
        }

        $idField = static::config()->get('unique_identifier_field');
        $attempts = LoginAttempt::getByEmail($this->{$idField})
            ->sort('Created', 'DESC')
            ->limit($maxAttempts);

        if ($attempts->count() < $maxAttempts) {
            return false;
        }

        foreach ($attempts as $attempt) {
            if ($attempt->Status === 'Success') {
                return false;
            }
        }

        // Calculate effective LockedOutUntil
        /** @var DBDatetime $firstFailureDate */
        $firstFailureDate = $attempts->first()->dbObject('Created');
        $maxAgeSeconds = $this->config()->get('lock_out_delay_mins') * 60;
        $lockedOutUntil = $firstFailureDate->getTimestamp() + $maxAgeSeconds;
        $now = DBDatetime::now()->getTimestamp();
        if ($now < $lockedOutUntil) {
            return true;
        }

        return false;
    }